style: workspace settings pages

This commit is contained in:
Aaryan Khandelwal 2023-03-03 14:30:21 +05:30
parent 433276c833
commit 1d8b4296fb
7 changed files with 182 additions and 239 deletions

View File

@ -3,6 +3,8 @@ import React, { useRef, useState } from "react";
import Image from "next/image";
import { useRouter } from "next/router";
import useSWR, { mutate } from "swr";
// services
import workspaceService from "services/workspace.service";
// hooks
@ -10,10 +12,11 @@ import useToast from "hooks/use-toast";
// ui
import { Button, Loader } from "components/ui";
// icons
import GithubLogo from "public/logos/github-black.png";
import useSWR, { mutate } from "swr";
import { APP_INTEGRATIONS, WORKSPACE_INTEGRATIONS } from "constants/fetch-keys";
import GithubLogo from "public/logos/github-square.png";
// types
import { IWorkspaceIntegrations } from "types";
// fetch-keys
import { WORKSPACE_INTEGRATIONS } from "constants/fetch-keys";
const OAuthPopUp = ({ integration }: any) => {
const [deletingIntegration, setDeletingIntegration] = useState(false);
@ -97,28 +100,28 @@ const OAuthPopUp = ({ integration }: any) => {
);
return (
<div className="flex items-center justify-between gap-2 border p-4 rounded-lg">
<div className="flex items-center justify-between gap-2 rounded-[10px] border bg-white p-5">
<div className="flex items-start gap-4">
<div className="h-12 w-12">
<div className="h-12 w-12 flex-shrink-0">
<Image src={GithubLogo} alt="GithubLogo" />
</div>
<div>
<h3 className="flex items-center gap-4 font-semibold text-xl">
<h3 className="flex items-center gap-4 text-xl font-semibold">
{integration.title}
{workspaceIntegrations ? (
isInstalled ? (
<span className="flex items-center text-green-500 font-normal text-sm gap-1">
<span className="h-1.5 w-1.5 bg-green-500 flex-shrink-0 rounded-full" /> Installed
<span className="flex items-center gap-1 text-sm font-normal text-green-500">
<span className="h-1.5 w-1.5 flex-shrink-0 rounded-full bg-green-500" /> Installed
</span>
) : (
<span className="flex items-center text-gray-400 font-normal text-sm gap-1">
<span className="h-1.5 w-1.5 bg-gray-400 flex-shrink-0 rounded-full" /> Not
<span className="flex items-center gap-1 text-sm font-normal text-gray-400">
<span className="h-1.5 w-1.5 flex-shrink-0 rounded-full bg-gray-400" /> Not
Installed
</span>
)
) : null}
</h3>
<p className="text-gray-400 text-sm">
<p className="text-sm text-gray-400">
{workspaceIntegrations
? isInstalled
? "Activate GitHub integrations on individual projects to sync with specific repositories."

View File

@ -87,7 +87,7 @@ export const SingleIntegration: React.FC<Props> = ({ integration }) => {
{integration && (
<div className="flex items-center justify-between gap-2 rounded-[10px] border bg-white p-5">
<div className="flex items-start gap-4">
<div className="h-12 w-12">
<div className="h-12 w-12 flex-shrink-0">
<Image src={GithubLogo} alt="GithubLogo" />
</div>
<div>

View File

@ -64,7 +64,7 @@ const SettingsNavbar: React.FC = () => {
return (
<div className="flex flex-wrap gap-4">
{(projectId ? projectLinks : workspaceLinks).map((link) => (
<Link href={link.href}>
<Link key={link.href} href={link.href}>
<a>
<div
className={`rounded-3xl border px-5 py-1.5 text-sm sm:px-7 sm:py-2 sm:text-base ${

View File

@ -18,12 +18,13 @@ import AppLayout from "layouts/app-layout";
import ConfirmProjectMemberRemove from "components/project/confirm-project-member-remove";
import SendProjectInvitationModal from "components/project/send-project-invitation-modal";
// ui
import { Button, CustomMenu, CustomSelect, Loader } from "components/ui";
import { CustomMenu, CustomSelect, Loader } from "components/ui";
import { BreadcrumbItem, Breadcrumbs } from "components/breadcrumbs";
// icons
import { PlusIcon } from "@heroicons/react/24/outline";
// types
import type { NextPage, GetServerSidePropsContext } from "next";
import { UserAuth } from "types";
// fetch-keys
import {
PROJECT_DETAILS,
@ -34,18 +35,8 @@ import {
// constants
import { ROLE } from "constants/workspace";
type TMemberSettingsProps = {
isMember: boolean;
isOwner: boolean;
isViewer: boolean;
isGuest: boolean;
};
const MembersSettings: NextPage<TMemberSettingsProps> = (props) => {
const { isMember, isOwner, isViewer, isGuest } = props;
const MembersSettings: NextPage<UserAuth> = ({ isMember, isOwner, isViewer, isGuest }) => {
const [inviteModal, setInviteModal] = useState(false);
const [selectedMember, setSelectedMember] = useState<string | null>(null);
const [selectedRemoveMember, setSelectedRemoveMember] = useState<string | null>(null);
const [selectedInviteRemoveMember, setSelectedInviteRemoveMember] = useState<string | null>(null);
@ -251,7 +242,6 @@ const MembersSettings: NextPage<TMemberSettingsProps> = (props) => {
),
false
);
setSelectedMember(null);
})
.catch((err) => {
console.log(err);
@ -259,7 +249,7 @@ const MembersSettings: NextPage<TMemberSettingsProps> = (props) => {
}}
>
{Object.keys(ROLE).map((key) => (
<CustomSelect.Option value={key}>
<CustomSelect.Option key={key} value={key}>
<>{ROLE[parseInt(key) as keyof typeof ROLE]}</>
</CustomSelect.Option>
))}

View File

@ -27,7 +27,7 @@ import { BreadcrumbItem, Breadcrumbs } from "components/breadcrumbs";
// helpers
import { copyTextToClipboard } from "helpers/string.helper";
// types
import type { IWorkspace } from "types";
import type { IWorkspace, UserAuth } from "types";
import type { GetServerSideProps, NextPage } from "next";
// fetch-keys
import { WORKSPACE_DETAILS, USER_WORKSPACES } from "constants/fetch-keys";
@ -41,14 +41,7 @@ const defaultValues: Partial<IWorkspace> = {
logo: null,
};
type TWorkspaceSettingsProps = {
isOwner: boolean;
isMember: boolean;
isViewer: boolean;
isGuest: boolean;
};
const WorkspaceSettings: NextPage<TWorkspaceSettingsProps> = (props) => {
const WorkspaceSettings: NextPage<UserAuth> = (props) => {
const [isOpen, setIsOpen] = useState(false);
const [isImageUploading, setIsImageUploading] = useState(false);
const [isImageUploadModalOpen, setIsImageUploadModalOpen] = useState(false);
@ -135,17 +128,16 @@ const WorkspaceSettings: NextPage<TWorkspaceSettingsProps> = (props) => {
data={activeWorkspace ?? null}
/>
{activeWorkspace ? (
<div className="space-y-8">
<div>
<h3 className="text-3xl font-bold leading-6 text-gray-900">General</h3>
<p className="mt-4 text-sm text-gray-500">
This information will be displayed to every member of the workspace.
<div className="space-y-8 sm:space-y-12">
<div className="grid grid-cols-12 gap-4 sm:gap-16">
<div className="col-span-12 sm:col-span-6">
<h4 className="text-xl font-semibold">Logo</h4>
<p className="text-gray-500">
Max file size is 5MB. Supported file types are .jpg and .png.
</p>
</div>
<div className="grid grid-cols-1 gap-x-16 gap-y-8 lg:grid-cols-12">
<div className="col-span lg:col-span-5">
<h4 className="text-md mb-1 leading-6 text-gray-900">Logo</h4>
<div className="flex w-full gap-2">
<div className="col-span-12 sm:col-span-6">
<div className="flex items-center gap-4">
<button type="button" onClick={() => setIsImageUploadModalOpen(true)}>
{watch("logo") && watch("logo") !== null && watch("logo") !== "" ? (
<div className="relative mx-auto flex h-12 w-12">
@ -165,9 +157,6 @@ const WorkspaceSettings: NextPage<TWorkspaceSettingsProps> = (props) => {
)}
</button>
<div>
<p className="mb-2 text-sm text-gray-500">
Max file size is 5MB. Supported file types are .jpg and .png.
</p>
<Button
onClick={() => {
setIsImageUploadModalOpen(true);
@ -178,35 +167,13 @@ const WorkspaceSettings: NextPage<TWorkspaceSettingsProps> = (props) => {
</div>
</div>
</div>
<div className="lg:col-span-5">
<div className="mb-3 flex items-end justify-between gap-2">
<div>
<h4 className="text-md mb-1 leading-6 text-gray-900">URL</h4>
<p className="text-sm text-gray-500">Give a name to your workspace.</p>
</div>
<Button
type="button"
theme="secondary"
className="h-min"
onClick={() =>
copyTextToClipboard(`https://app.plane.so/${activeWorkspace.slug}`)
.then(() => {
setToastAlert({
type: "success",
title: "Workspace link copied to clipboard",
});
})
.catch(() => {
setToastAlert({
type: "error",
title: "Some error occurred",
});
})
}
>
<LinkIcon className="h-3.5 w-3.5" />
</Button>
<div className="grid grid-cols-12 gap-4 sm:gap-16">
<div className="col-span-12 sm:col-span-6">
<h4 className="text-xl font-semibold">URL</h4>
<p className="text-gray-500">Your workspace URL.</p>
</div>
<div className="col-span-12 flex items-center gap-2 sm:col-span-6">
<Input
id="url"
name="url"
@ -217,10 +184,30 @@ const WorkspaceSettings: NextPage<TWorkspaceSettingsProps> = (props) => {
value={`app.plane.so/${activeWorkspace.slug}`}
disabled
/>
<Button
type="button"
theme="secondary"
className="h-min"
onClick={() =>
copyTextToClipboard(`https://app.plane.so/${activeWorkspace.slug}`).then(() => {
setToastAlert({
type: "success",
title: "Link Copied!",
message: "Workspace link copied to clipboard.",
});
})
}
>
<LinkIcon className="h-[18px] w-[18px]" />
</Button>
</div>
<div className="lg:col-span-5">
<h4 className="text-md mb-1 leading-6 text-gray-900">Name</h4>
<p className="mb-3 text-sm text-gray-500">Give a name to your workspace.</p>
</div>
<div className="grid grid-cols-12 gap-4 sm:gap-16">
<div className="col-span-12 sm:col-span-6">
<h4 className="text-xl font-semibold">Name</h4>
<p className="text-gray-500">Give a name to your workspace.</p>
</div>
<div className="col-span-12 sm:col-span-6">
<Input
id="name"
name="name"
@ -231,12 +218,15 @@ const WorkspaceSettings: NextPage<TWorkspaceSettingsProps> = (props) => {
validations={{
required: "Name is required",
}}
className="w-full"
/>
</div>
<div className="lg:col-span-5">
<h4 className="text-md mb-1 leading-6 text-gray-900">Company Size</h4>
<p className="mb-3 text-sm text-gray-500">How big is your company?</p>
</div>
<div className="grid grid-cols-12 gap-4 sm:gap-16">
<div className="col-span-12 sm:col-span-6">
<h4 className="text-xl font-semibold">Company Size</h4>
<p className="text-gray-500">How big is your company?</p>
</div>
<div className="col-span-12 sm:col-span-6">
<Controller
name="company_size"
control={control}
@ -256,29 +246,28 @@ const WorkspaceSettings: NextPage<TWorkspaceSettingsProps> = (props) => {
)}
/>
</div>
<div className="col-span-full">
</div>
<div className="sm:text-right">
<Button onClick={handleSubmit(onSubmit)} disabled={isSubmitting}>
{isSubmitting ? "Updating..." : "Update Workspace"}
</Button>
</div>
<div className="space-y-8 lg:col-span-10">
<div>
<h4 className="text-md mb-1 leading-6 text-gray-900">Danger Zone</h4>
<p className="mb-3 text-sm text-gray-500">
<div className="grid grid-cols-12 gap-4 sm:gap-16">
<div className="col-span-12 sm:col-span-6">
<h4 className="text-xl font-semibold">Danger Zone</h4>
<p className="text-gray-500">
The danger zone of the workspace delete page is a critical area that requires
careful consideration and attention. When deleting a workspace, all of the data
and resources within that workspace will be permanently removed and cannot be
recovered.
careful consideration and attention. When deleting a workspace, all of the data and
resources within that workspace will be permanently removed and cannot be recovered.
</p>
</div>
<div>
<div className="col-span-12 sm:col-span-6">
<OutlineButton theme="danger" onClick={() => setIsOpen(true)}>
Delete the workspace
</OutlineButton>
</div>
</div>
</div>
</div>
) : (
<div className="grid h-full w-full place-items-center px-4 sm:px-0">
<Spinner />

View File

@ -50,11 +50,8 @@ const WorkspaceIntegrations: NextPage<UserAuth> = (props) => {
settingsLayout
>
<section className="space-y-8">
<div>
<h3 className="text-3xl font-bold leading-6 text-gray-900">Integrations</h3>
<p className="mt-4 text-sm text-gray-500">Manage the workspace integrations.</p>
</div>
<div className="space-y-4">
<h3 className="text-2xl font-semibold">Integrations</h3>
<div className="space-y-5">
{integrations ? (
integrations.map((integration) => (
<OAuthPopUp

View File

@ -17,33 +17,25 @@ import AppLayout from "layouts/app-layout";
import ConfirmWorkspaceMemberRemove from "components/workspace/confirm-workspace-member-remove";
import SendWorkspaceInvitationModal from "components/workspace/send-workspace-invitation-modal";
// ui
import { Button, CustomListbox, CustomMenu, Loader } from "components/ui";
import { CustomMenu, CustomSelect, Loader } from "components/ui";
import { BreadcrumbItem, Breadcrumbs } from "components/breadcrumbs";
// icons
import { PlusIcon } from "@heroicons/react/24/outline";
// types
import type { GetServerSideProps, NextPage } from "next";
import { UserAuth } from "types";
// fetch-keys
import { WORKSPACE_DETAILS, WORKSPACE_INVITATIONS, WORKSPACE_MEMBERS } from "constants/fetch-keys";
// constants
import { ROLE } from "constants/workspace";
type TMembersSettingsProps = {
isOwner: boolean;
isMember: boolean;
isViewer: boolean;
isGuest: boolean;
};
const MembersSettings: NextPage<TMembersSettingsProps> = (props) => {
const [selectedMember, setSelectedMember] = useState<string | null>(null);
const MembersSettings: NextPage<UserAuth> = (props) => {
const [selectedRemoveMember, setSelectedRemoveMember] = useState<string | null>(null);
const [selectedInviteRemoveMember, setSelectedInviteRemoveMember] = useState<string | null>(null);
const [inviteModal, setInviteModal] = useState(false);
const {
query: { workspaceSlug },
} = useRouter();
const router = useRouter();
const { workspaceSlug } = router.query;
const { setToastAlert } = useToast();
@ -151,43 +143,38 @@ const MembersSettings: NextPage<TMembersSettingsProps> = (props) => {
settingsLayout
>
<section className="space-y-8">
<div>
<h3 className="text-3xl font-bold leading-6 text-gray-900">Members</h3>
<p className="mt-4 text-sm text-gray-500">Manage all the members of the workspace.</p>
<div className="flex items-end justify-between gap-4">
<h3 className="text-2xl font-semibold">Members</h3>
<button
type="button"
className="flex items-center gap-2 text-theme outline-none"
onClick={() => setInviteModal(true)}
>
<PlusIcon className="h-4 w-4" />
Add Member
</button>
</div>
{!workspaceMembers || !workspaceInvitations ? (
<Loader className="space-y-5 md:w-2/3">
<Loader className="space-y-5">
<Loader.Item height="40px" />
<Loader.Item height="40px" />
<Loader.Item height="40px" />
<Loader.Item height="40px" />
</Loader>
) : (
<div className="md:w-2/3">
<div className="flex items-center justify-between gap-2">
<h4 className="text-md mb-1 leading-6 text-gray-900">Manage members</h4>
<Button
theme="secondary"
className="flex items-center gap-x-1"
onClick={() => setInviteModal(true)}
>
<PlusIcon className="h-4 w-4" />
Add Member
</Button>
</div>
<div className="mt-6 space-y-6">
<div className="divide-y rounded-[10px] border border-gray-200 bg-white px-6">
{members.length > 0
? members.map((member) => (
<div key={member.id} className="flex items-center justify-between">
<div key={member.id} className="flex items-center justify-between py-6">
<div className="flex items-center gap-x-8 gap-y-2">
<div className="relative flex h-10 w-10 items-center justify-center rounded bg-gray-700 p-4 capitalize text-white">
<div className="relative flex h-10 w-10 items-center justify-center rounded-lg bg-gray-700 p-4 capitalize text-white">
{member.avatar && member.avatar !== "" ? (
<Image
src={member.avatar}
alt={member.first_name}
layout="fill"
objectFit="cover"
className="rounded"
className="rounded-lg"
/>
) : member.first_name !== "" ? (
member.first_name.charAt(0)
@ -203,28 +190,19 @@ const MembersSettings: NextPage<TMembersSettingsProps> = (props) => {
</div>
</div>
<div className="flex items-center gap-2 text-xs">
{selectedMember === member.id ? (
<CustomListbox
options={Object.keys(ROLE).map((key) => ({
display: ROLE[parseInt(key) as keyof typeof ROLE],
value: key,
}))}
title={ROLE[member.role as keyof typeof ROLE] ?? "None"}
<CustomSelect
label={ROLE[member.role as keyof typeof ROLE]}
value={member.role}
onChange={(value) => {
onChange={(value: any) => {
workspaceService
.updateWorkspaceMember(
activeWorkspace?.slug as string,
member.id,
{
.updateWorkspaceMember(activeWorkspace?.slug as string, member.id, {
role: value,
}
)
})
.then(() => {
mutateMembers(
(prevData) =>
prevData?.map((m) =>
m.id === selectedMember ? { ...m, role: value } : m
m.id === member.id ? { ...m, role: value } : m
),
false
);
@ -233,7 +211,6 @@ const MembersSettings: NextPage<TMembersSettingsProps> = (props) => {
type: "success",
message: "Member role updated successfully.",
});
setSelectedMember(null);
})
.catch(() => {
setToastAlert({
@ -243,26 +220,14 @@ const MembersSettings: NextPage<TMembersSettingsProps> = (props) => {
});
});
}}
/>
) : (
ROLE[member.role as keyof typeof ROLE] ?? "None"
)}
<CustomMenu ellipsis>
<CustomMenu.MenuItem
onClick={() => {
if (!member.member) {
setToastAlert({
type: "error",
message: "You can't edit a pending invitation.",
title: "Error",
});
} else {
setSelectedMember(member.id);
}
}}
>
Edit
</CustomMenu.MenuItem>
{Object.keys(ROLE).map((key) => (
<CustomSelect.Option key={key} value={key}>
<>{ROLE[parseInt(key) as keyof typeof ROLE]}</>
</CustomSelect.Option>
))}
</CustomSelect>
<CustomMenu ellipsis>
<CustomMenu.MenuItem
onClick={() => {
if (member.member) {
@ -272,7 +237,7 @@ const MembersSettings: NextPage<TMembersSettingsProps> = (props) => {
}
}}
>
Remove
Remove member
</CustomMenu.MenuItem>
</CustomMenu>
</div>
@ -280,7 +245,6 @@ const MembersSettings: NextPage<TMembersSettingsProps> = (props) => {
))
: null}
</div>
</div>
)}
</section>
</AppLayout>