forked from github/plane
style: workspace settings pages
This commit is contained in:
parent
433276c833
commit
1d8b4296fb
@ -3,6 +3,8 @@ import React, { useRef, useState } from "react";
|
|||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
|
|
||||||
|
import useSWR, { mutate } from "swr";
|
||||||
|
|
||||||
// services
|
// services
|
||||||
import workspaceService from "services/workspace.service";
|
import workspaceService from "services/workspace.service";
|
||||||
// hooks
|
// hooks
|
||||||
@ -10,10 +12,11 @@ import useToast from "hooks/use-toast";
|
|||||||
// ui
|
// ui
|
||||||
import { Button, Loader } from "components/ui";
|
import { Button, Loader } from "components/ui";
|
||||||
// icons
|
// icons
|
||||||
import GithubLogo from "public/logos/github-black.png";
|
import GithubLogo from "public/logos/github-square.png";
|
||||||
import useSWR, { mutate } from "swr";
|
// types
|
||||||
import { APP_INTEGRATIONS, WORKSPACE_INTEGRATIONS } from "constants/fetch-keys";
|
|
||||||
import { IWorkspaceIntegrations } from "types";
|
import { IWorkspaceIntegrations } from "types";
|
||||||
|
// fetch-keys
|
||||||
|
import { WORKSPACE_INTEGRATIONS } from "constants/fetch-keys";
|
||||||
|
|
||||||
const OAuthPopUp = ({ integration }: any) => {
|
const OAuthPopUp = ({ integration }: any) => {
|
||||||
const [deletingIntegration, setDeletingIntegration] = useState(false);
|
const [deletingIntegration, setDeletingIntegration] = useState(false);
|
||||||
@ -97,28 +100,28 @@ const OAuthPopUp = ({ integration }: any) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
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="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" />
|
<Image src={GithubLogo} alt="GithubLogo" />
|
||||||
</div>
|
</div>
|
||||||
<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}
|
{integration.title}
|
||||||
{workspaceIntegrations ? (
|
{workspaceIntegrations ? (
|
||||||
isInstalled ? (
|
isInstalled ? (
|
||||||
<span className="flex items-center text-green-500 font-normal text-sm gap-1">
|
<span className="flex items-center gap-1 text-sm font-normal text-green-500">
|
||||||
<span className="h-1.5 w-1.5 bg-green-500 flex-shrink-0 rounded-full" /> Installed
|
<span className="h-1.5 w-1.5 flex-shrink-0 rounded-full bg-green-500" /> Installed
|
||||||
</span>
|
</span>
|
||||||
) : (
|
) : (
|
||||||
<span className="flex items-center text-gray-400 font-normal text-sm gap-1">
|
<span className="flex items-center gap-1 text-sm font-normal text-gray-400">
|
||||||
<span className="h-1.5 w-1.5 bg-gray-400 flex-shrink-0 rounded-full" /> Not
|
<span className="h-1.5 w-1.5 flex-shrink-0 rounded-full bg-gray-400" /> Not
|
||||||
Installed
|
Installed
|
||||||
</span>
|
</span>
|
||||||
)
|
)
|
||||||
) : null}
|
) : null}
|
||||||
</h3>
|
</h3>
|
||||||
<p className="text-gray-400 text-sm">
|
<p className="text-sm text-gray-400">
|
||||||
{workspaceIntegrations
|
{workspaceIntegrations
|
||||||
? isInstalled
|
? isInstalled
|
||||||
? "Activate GitHub integrations on individual projects to sync with specific repositories."
|
? "Activate GitHub integrations on individual projects to sync with specific repositories."
|
||||||
|
@ -87,7 +87,7 @@ export const SingleIntegration: React.FC<Props> = ({ integration }) => {
|
|||||||
{integration && (
|
{integration && (
|
||||||
<div className="flex items-center justify-between gap-2 rounded-[10px] border bg-white p-5">
|
<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="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" />
|
<Image src={GithubLogo} alt="GithubLogo" />
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
@ -64,7 +64,7 @@ const SettingsNavbar: React.FC = () => {
|
|||||||
return (
|
return (
|
||||||
<div className="flex flex-wrap gap-4">
|
<div className="flex flex-wrap gap-4">
|
||||||
{(projectId ? projectLinks : workspaceLinks).map((link) => (
|
{(projectId ? projectLinks : workspaceLinks).map((link) => (
|
||||||
<Link href={link.href}>
|
<Link key={link.href} href={link.href}>
|
||||||
<a>
|
<a>
|
||||||
<div
|
<div
|
||||||
className={`rounded-3xl border px-5 py-1.5 text-sm sm:px-7 sm:py-2 sm:text-base ${
|
className={`rounded-3xl border px-5 py-1.5 text-sm sm:px-7 sm:py-2 sm:text-base ${
|
||||||
|
@ -18,12 +18,13 @@ import AppLayout from "layouts/app-layout";
|
|||||||
import ConfirmProjectMemberRemove from "components/project/confirm-project-member-remove";
|
import ConfirmProjectMemberRemove from "components/project/confirm-project-member-remove";
|
||||||
import SendProjectInvitationModal from "components/project/send-project-invitation-modal";
|
import SendProjectInvitationModal from "components/project/send-project-invitation-modal";
|
||||||
// ui
|
// ui
|
||||||
import { Button, CustomMenu, CustomSelect, Loader } from "components/ui";
|
import { CustomMenu, CustomSelect, Loader } from "components/ui";
|
||||||
import { BreadcrumbItem, Breadcrumbs } from "components/breadcrumbs";
|
import { BreadcrumbItem, Breadcrumbs } from "components/breadcrumbs";
|
||||||
// icons
|
// icons
|
||||||
import { PlusIcon } from "@heroicons/react/24/outline";
|
import { PlusIcon } from "@heroicons/react/24/outline";
|
||||||
// types
|
// types
|
||||||
import type { NextPage, GetServerSidePropsContext } from "next";
|
import type { NextPage, GetServerSidePropsContext } from "next";
|
||||||
|
import { UserAuth } from "types";
|
||||||
// fetch-keys
|
// fetch-keys
|
||||||
import {
|
import {
|
||||||
PROJECT_DETAILS,
|
PROJECT_DETAILS,
|
||||||
@ -34,18 +35,8 @@ import {
|
|||||||
// constants
|
// constants
|
||||||
import { ROLE } from "constants/workspace";
|
import { ROLE } from "constants/workspace";
|
||||||
|
|
||||||
type TMemberSettingsProps = {
|
const MembersSettings: NextPage<UserAuth> = ({ isMember, isOwner, isViewer, isGuest }) => {
|
||||||
isMember: boolean;
|
|
||||||
isOwner: boolean;
|
|
||||||
isViewer: boolean;
|
|
||||||
isGuest: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
const MembersSettings: NextPage<TMemberSettingsProps> = (props) => {
|
|
||||||
const { isMember, isOwner, isViewer, isGuest } = props;
|
|
||||||
|
|
||||||
const [inviteModal, setInviteModal] = useState(false);
|
const [inviteModal, setInviteModal] = useState(false);
|
||||||
const [selectedMember, setSelectedMember] = useState<string | null>(null);
|
|
||||||
const [selectedRemoveMember, setSelectedRemoveMember] = useState<string | null>(null);
|
const [selectedRemoveMember, setSelectedRemoveMember] = useState<string | null>(null);
|
||||||
const [selectedInviteRemoveMember, setSelectedInviteRemoveMember] = useState<string | null>(null);
|
const [selectedInviteRemoveMember, setSelectedInviteRemoveMember] = useState<string | null>(null);
|
||||||
|
|
||||||
@ -251,7 +242,6 @@ const MembersSettings: NextPage<TMemberSettingsProps> = (props) => {
|
|||||||
),
|
),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
setSelectedMember(null);
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
@ -259,7 +249,7 @@ const MembersSettings: NextPage<TMemberSettingsProps> = (props) => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{Object.keys(ROLE).map((key) => (
|
{Object.keys(ROLE).map((key) => (
|
||||||
<CustomSelect.Option value={key}>
|
<CustomSelect.Option key={key} value={key}>
|
||||||
<>{ROLE[parseInt(key) as keyof typeof ROLE]}</>
|
<>{ROLE[parseInt(key) as keyof typeof ROLE]}</>
|
||||||
</CustomSelect.Option>
|
</CustomSelect.Option>
|
||||||
))}
|
))}
|
||||||
|
@ -27,7 +27,7 @@ import { BreadcrumbItem, Breadcrumbs } from "components/breadcrumbs";
|
|||||||
// helpers
|
// helpers
|
||||||
import { copyTextToClipboard } from "helpers/string.helper";
|
import { copyTextToClipboard } from "helpers/string.helper";
|
||||||
// types
|
// types
|
||||||
import type { IWorkspace } from "types";
|
import type { IWorkspace, UserAuth } from "types";
|
||||||
import type { GetServerSideProps, NextPage } from "next";
|
import type { GetServerSideProps, NextPage } from "next";
|
||||||
// fetch-keys
|
// fetch-keys
|
||||||
import { WORKSPACE_DETAILS, USER_WORKSPACES } from "constants/fetch-keys";
|
import { WORKSPACE_DETAILS, USER_WORKSPACES } from "constants/fetch-keys";
|
||||||
@ -41,14 +41,7 @@ const defaultValues: Partial<IWorkspace> = {
|
|||||||
logo: null,
|
logo: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
type TWorkspaceSettingsProps = {
|
const WorkspaceSettings: NextPage<UserAuth> = (props) => {
|
||||||
isOwner: boolean;
|
|
||||||
isMember: boolean;
|
|
||||||
isViewer: boolean;
|
|
||||||
isGuest: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
const WorkspaceSettings: NextPage<TWorkspaceSettingsProps> = (props) => {
|
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const [isImageUploading, setIsImageUploading] = useState(false);
|
const [isImageUploading, setIsImageUploading] = useState(false);
|
||||||
const [isImageUploadModalOpen, setIsImageUploadModalOpen] = useState(false);
|
const [isImageUploadModalOpen, setIsImageUploadModalOpen] = useState(false);
|
||||||
@ -135,17 +128,16 @@ const WorkspaceSettings: NextPage<TWorkspaceSettingsProps> = (props) => {
|
|||||||
data={activeWorkspace ?? null}
|
data={activeWorkspace ?? null}
|
||||||
/>
|
/>
|
||||||
{activeWorkspace ? (
|
{activeWorkspace ? (
|
||||||
<div className="space-y-8">
|
<div className="space-y-8 sm:space-y-12">
|
||||||
<div>
|
<div className="grid grid-cols-12 gap-4 sm:gap-16">
|
||||||
<h3 className="text-3xl font-bold leading-6 text-gray-900">General</h3>
|
<div className="col-span-12 sm:col-span-6">
|
||||||
<p className="mt-4 text-sm text-gray-500">
|
<h4 className="text-xl font-semibold">Logo</h4>
|
||||||
This information will be displayed to every member of the workspace.
|
<p className="text-gray-500">
|
||||||
</p>
|
Max file size is 5MB. Supported file types are .jpg and .png.
|
||||||
</div>
|
</p>
|
||||||
<div className="grid grid-cols-1 gap-x-16 gap-y-8 lg:grid-cols-12">
|
</div>
|
||||||
<div className="col-span lg:col-span-5">
|
<div className="col-span-12 sm:col-span-6">
|
||||||
<h4 className="text-md mb-1 leading-6 text-gray-900">Logo</h4>
|
<div className="flex items-center gap-4">
|
||||||
<div className="flex w-full gap-2">
|
|
||||||
<button type="button" onClick={() => setIsImageUploadModalOpen(true)}>
|
<button type="button" onClick={() => setIsImageUploadModalOpen(true)}>
|
||||||
{watch("logo") && watch("logo") !== null && watch("logo") !== "" ? (
|
{watch("logo") && watch("logo") !== null && watch("logo") !== "" ? (
|
||||||
<div className="relative mx-auto flex h-12 w-12">
|
<div className="relative mx-auto flex h-12 w-12">
|
||||||
@ -165,9 +157,6 @@ const WorkspaceSettings: NextPage<TWorkspaceSettingsProps> = (props) => {
|
|||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
<div>
|
<div>
|
||||||
<p className="mb-2 text-sm text-gray-500">
|
|
||||||
Max file size is 5MB. Supported file types are .jpg and .png.
|
|
||||||
</p>
|
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setIsImageUploadModalOpen(true);
|
setIsImageUploadModalOpen(true);
|
||||||
@ -178,35 +167,13 @@ const WorkspaceSettings: NextPage<TWorkspaceSettingsProps> = (props) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="lg:col-span-5">
|
</div>
|
||||||
<div className="mb-3 flex items-end justify-between gap-2">
|
<div className="grid grid-cols-12 gap-4 sm:gap-16">
|
||||||
<div>
|
<div className="col-span-12 sm:col-span-6">
|
||||||
<h4 className="text-md mb-1 leading-6 text-gray-900">URL</h4>
|
<h4 className="text-xl font-semibold">URL</h4>
|
||||||
<p className="text-sm text-gray-500">Give a name to your workspace.</p>
|
<p className="text-gray-500">Your workspace URL.</p>
|
||||||
</div>
|
</div>
|
||||||
<Button
|
<div className="col-span-12 flex items-center gap-2 sm:col-span-6">
|
||||||
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>
|
|
||||||
<Input
|
<Input
|
||||||
id="url"
|
id="url"
|
||||||
name="url"
|
name="url"
|
||||||
@ -217,10 +184,30 @@ const WorkspaceSettings: NextPage<TWorkspaceSettingsProps> = (props) => {
|
|||||||
value={`app.plane.so/${activeWorkspace.slug}`}
|
value={`app.plane.so/${activeWorkspace.slug}`}
|
||||||
disabled
|
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>
|
||||||
<div className="lg:col-span-5">
|
</div>
|
||||||
<h4 className="text-md mb-1 leading-6 text-gray-900">Name</h4>
|
<div className="grid grid-cols-12 gap-4 sm:gap-16">
|
||||||
<p className="mb-3 text-sm text-gray-500">Give a name to your workspace.</p>
|
<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
|
<Input
|
||||||
id="name"
|
id="name"
|
||||||
name="name"
|
name="name"
|
||||||
@ -231,12 +218,15 @@ const WorkspaceSettings: NextPage<TWorkspaceSettingsProps> = (props) => {
|
|||||||
validations={{
|
validations={{
|
||||||
required: "Name is required",
|
required: "Name is required",
|
||||||
}}
|
}}
|
||||||
className="w-full"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="lg:col-span-5">
|
</div>
|
||||||
<h4 className="text-md mb-1 leading-6 text-gray-900">Company Size</h4>
|
<div className="grid grid-cols-12 gap-4 sm:gap-16">
|
||||||
<p className="mb-3 text-sm text-gray-500">How big is your company?</p>
|
<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
|
<Controller
|
||||||
name="company_size"
|
name="company_size"
|
||||||
control={control}
|
control={control}
|
||||||
@ -256,26 +246,25 @@ const WorkspaceSettings: NextPage<TWorkspaceSettingsProps> = (props) => {
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-span-full">
|
</div>
|
||||||
<Button onClick={handleSubmit(onSubmit)} disabled={isSubmitting}>
|
<div className="sm:text-right">
|
||||||
{isSubmitting ? "Updating..." : "Update Workspace"}
|
<Button onClick={handleSubmit(onSubmit)} disabled={isSubmitting}>
|
||||||
</Button>
|
{isSubmitting ? "Updating..." : "Update Workspace"}
|
||||||
|
</Button>
|
||||||
|
</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">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.
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-8 lg:col-span-10">
|
<div className="col-span-12 sm:col-span-6">
|
||||||
<div>
|
<OutlineButton theme="danger" onClick={() => setIsOpen(true)}>
|
||||||
<h4 className="text-md mb-1 leading-6 text-gray-900">Danger Zone</h4>
|
Delete the workspace
|
||||||
<p className="mb-3 text-sm text-gray-500">
|
</OutlineButton>
|
||||||
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.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<OutlineButton theme="danger" onClick={() => setIsOpen(true)}>
|
|
||||||
Delete the workspace
|
|
||||||
</OutlineButton>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -50,11 +50,8 @@ const WorkspaceIntegrations: NextPage<UserAuth> = (props) => {
|
|||||||
settingsLayout
|
settingsLayout
|
||||||
>
|
>
|
||||||
<section className="space-y-8">
|
<section className="space-y-8">
|
||||||
<div>
|
<h3 className="text-2xl font-semibold">Integrations</h3>
|
||||||
<h3 className="text-3xl font-bold leading-6 text-gray-900">Integrations</h3>
|
<div className="space-y-5">
|
||||||
<p className="mt-4 text-sm text-gray-500">Manage the workspace integrations.</p>
|
|
||||||
</div>
|
|
||||||
<div className="space-y-4">
|
|
||||||
{integrations ? (
|
{integrations ? (
|
||||||
integrations.map((integration) => (
|
integrations.map((integration) => (
|
||||||
<OAuthPopUp
|
<OAuthPopUp
|
||||||
|
@ -17,33 +17,25 @@ import AppLayout from "layouts/app-layout";
|
|||||||
import ConfirmWorkspaceMemberRemove from "components/workspace/confirm-workspace-member-remove";
|
import ConfirmWorkspaceMemberRemove from "components/workspace/confirm-workspace-member-remove";
|
||||||
import SendWorkspaceInvitationModal from "components/workspace/send-workspace-invitation-modal";
|
import SendWorkspaceInvitationModal from "components/workspace/send-workspace-invitation-modal";
|
||||||
// ui
|
// ui
|
||||||
import { Button, CustomListbox, CustomMenu, Loader } from "components/ui";
|
import { CustomMenu, CustomSelect, Loader } from "components/ui";
|
||||||
import { BreadcrumbItem, Breadcrumbs } from "components/breadcrumbs";
|
import { BreadcrumbItem, Breadcrumbs } from "components/breadcrumbs";
|
||||||
// icons
|
// icons
|
||||||
import { PlusIcon } from "@heroicons/react/24/outline";
|
import { PlusIcon } from "@heroicons/react/24/outline";
|
||||||
// types
|
// types
|
||||||
import type { GetServerSideProps, NextPage } from "next";
|
import type { GetServerSideProps, NextPage } from "next";
|
||||||
|
import { UserAuth } from "types";
|
||||||
// fetch-keys
|
// fetch-keys
|
||||||
import { WORKSPACE_DETAILS, WORKSPACE_INVITATIONS, WORKSPACE_MEMBERS } from "constants/fetch-keys";
|
import { WORKSPACE_DETAILS, WORKSPACE_INVITATIONS, WORKSPACE_MEMBERS } from "constants/fetch-keys";
|
||||||
// constants
|
// constants
|
||||||
import { ROLE } from "constants/workspace";
|
import { ROLE } from "constants/workspace";
|
||||||
|
|
||||||
type TMembersSettingsProps = {
|
const MembersSettings: NextPage<UserAuth> = (props) => {
|
||||||
isOwner: boolean;
|
|
||||||
isMember: boolean;
|
|
||||||
isViewer: boolean;
|
|
||||||
isGuest: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
const MembersSettings: NextPage<TMembersSettingsProps> = (props) => {
|
|
||||||
const [selectedMember, setSelectedMember] = useState<string | null>(null);
|
|
||||||
const [selectedRemoveMember, setSelectedRemoveMember] = useState<string | null>(null);
|
const [selectedRemoveMember, setSelectedRemoveMember] = useState<string | null>(null);
|
||||||
const [selectedInviteRemoveMember, setSelectedInviteRemoveMember] = useState<string | null>(null);
|
const [selectedInviteRemoveMember, setSelectedInviteRemoveMember] = useState<string | null>(null);
|
||||||
const [inviteModal, setInviteModal] = useState(false);
|
const [inviteModal, setInviteModal] = useState(false);
|
||||||
|
|
||||||
const {
|
const router = useRouter();
|
||||||
query: { workspaceSlug },
|
const { workspaceSlug } = router.query;
|
||||||
} = useRouter();
|
|
||||||
|
|
||||||
const { setToastAlert } = useToast();
|
const { setToastAlert } = useToast();
|
||||||
|
|
||||||
@ -151,135 +143,107 @@ const MembersSettings: NextPage<TMembersSettingsProps> = (props) => {
|
|||||||
settingsLayout
|
settingsLayout
|
||||||
>
|
>
|
||||||
<section className="space-y-8">
|
<section className="space-y-8">
|
||||||
<div>
|
<div className="flex items-end justify-between gap-4">
|
||||||
<h3 className="text-3xl font-bold leading-6 text-gray-900">Members</h3>
|
<h3 className="text-2xl font-semibold">Members</h3>
|
||||||
<p className="mt-4 text-sm text-gray-500">Manage all the members of the workspace.</p>
|
<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>
|
</div>
|
||||||
{!workspaceMembers || !workspaceInvitations ? (
|
{!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.Item height="40px" />
|
<Loader.Item height="40px" />
|
||||||
<Loader.Item height="40px" />
|
<Loader.Item height="40px" />
|
||||||
</Loader>
|
</Loader>
|
||||||
) : (
|
) : (
|
||||||
<div className="md:w-2/3">
|
<div className="divide-y rounded-[10px] border border-gray-200 bg-white px-6">
|
||||||
<div className="flex items-center justify-between gap-2">
|
{members.length > 0
|
||||||
<h4 className="text-md mb-1 leading-6 text-gray-900">Manage members</h4>
|
? members.map((member) => (
|
||||||
<Button
|
<div key={member.id} className="flex items-center justify-between py-6">
|
||||||
theme="secondary"
|
<div className="flex items-center gap-x-8 gap-y-2">
|
||||||
className="flex items-center gap-x-1"
|
<div className="relative flex h-10 w-10 items-center justify-center rounded-lg bg-gray-700 p-4 capitalize text-white">
|
||||||
onClick={() => setInviteModal(true)}
|
{member.avatar && member.avatar !== "" ? (
|
||||||
>
|
<Image
|
||||||
<PlusIcon className="h-4 w-4" />
|
src={member.avatar}
|
||||||
Add Member
|
alt={member.first_name}
|
||||||
</Button>
|
layout="fill"
|
||||||
</div>
|
objectFit="cover"
|
||||||
<div className="mt-6 space-y-6">
|
className="rounded-lg"
|
||||||
{members.length > 0
|
|
||||||
? members.map((member) => (
|
|
||||||
<div key={member.id} className="flex items-center justify-between">
|
|
||||||
<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">
|
|
||||||
{member.avatar && member.avatar !== "" ? (
|
|
||||||
<Image
|
|
||||||
src={member.avatar}
|
|
||||||
alt={member.first_name}
|
|
||||||
layout="fill"
|
|
||||||
objectFit="cover"
|
|
||||||
className="rounded"
|
|
||||||
/>
|
|
||||||
) : member.first_name !== "" ? (
|
|
||||||
member.first_name.charAt(0)
|
|
||||||
) : (
|
|
||||||
member.email.charAt(0)
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<h4 className="text-sm">
|
|
||||||
{member.first_name} {member.last_name}
|
|
||||||
</h4>
|
|
||||||
<p className="text-xs text-gray-500">{member.email}</p>
|
|
||||||
</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"}
|
|
||||||
value={member.role}
|
|
||||||
onChange={(value) => {
|
|
||||||
workspaceService
|
|
||||||
.updateWorkspaceMember(
|
|
||||||
activeWorkspace?.slug as string,
|
|
||||||
member.id,
|
|
||||||
{
|
|
||||||
role: value,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.then(() => {
|
|
||||||
mutateMembers(
|
|
||||||
(prevData) =>
|
|
||||||
prevData?.map((m) =>
|
|
||||||
m.id === selectedMember ? { ...m, role: value } : m
|
|
||||||
),
|
|
||||||
false
|
|
||||||
);
|
|
||||||
setToastAlert({
|
|
||||||
title: "Success",
|
|
||||||
type: "success",
|
|
||||||
message: "Member role updated successfully.",
|
|
||||||
});
|
|
||||||
setSelectedMember(null);
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
setToastAlert({
|
|
||||||
title: "Error",
|
|
||||||
type: "error",
|
|
||||||
message: "An error occurred while updating member role.",
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
|
) : member.first_name !== "" ? (
|
||||||
|
member.first_name.charAt(0)
|
||||||
) : (
|
) : (
|
||||||
ROLE[member.role as keyof typeof ROLE] ?? "None"
|
member.email.charAt(0)
|
||||||
)}
|
)}
|
||||||
<CustomMenu ellipsis>
|
</div>
|
||||||
<CustomMenu.MenuItem
|
<div>
|
||||||
onClick={() => {
|
<h4 className="text-sm">
|
||||||
if (!member.member) {
|
{member.first_name} {member.last_name}
|
||||||
setToastAlert({
|
</h4>
|
||||||
type: "error",
|
<p className="text-xs text-gray-500">{member.email}</p>
|
||||||
message: "You can't edit a pending invitation.",
|
|
||||||
title: "Error",
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
setSelectedMember(member.id);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Edit
|
|
||||||
</CustomMenu.MenuItem>
|
|
||||||
<CustomMenu.MenuItem
|
|
||||||
onClick={() => {
|
|
||||||
if (member.member) {
|
|
||||||
setSelectedRemoveMember(member.id);
|
|
||||||
} else {
|
|
||||||
setSelectedInviteRemoveMember(member.id);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Remove
|
|
||||||
</CustomMenu.MenuItem>
|
|
||||||
</CustomMenu>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))
|
<div className="flex items-center gap-2 text-xs">
|
||||||
: null}
|
<CustomSelect
|
||||||
</div>
|
label={ROLE[member.role as keyof typeof ROLE]}
|
||||||
|
value={member.role}
|
||||||
|
onChange={(value: any) => {
|
||||||
|
workspaceService
|
||||||
|
.updateWorkspaceMember(activeWorkspace?.slug as string, member.id, {
|
||||||
|
role: value,
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
mutateMembers(
|
||||||
|
(prevData) =>
|
||||||
|
prevData?.map((m) =>
|
||||||
|
m.id === member.id ? { ...m, role: value } : m
|
||||||
|
),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
setToastAlert({
|
||||||
|
title: "Success",
|
||||||
|
type: "success",
|
||||||
|
message: "Member role updated successfully.",
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
setToastAlert({
|
||||||
|
title: "Error",
|
||||||
|
type: "error",
|
||||||
|
message: "An error occurred while updating member role.",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{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) {
|
||||||
|
setSelectedRemoveMember(member.id);
|
||||||
|
} else {
|
||||||
|
setSelectedInviteRemoveMember(member.id);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Remove member
|
||||||
|
</CustomMenu.MenuItem>
|
||||||
|
</CustomMenu>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
: null}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</section>
|
</section>
|
||||||
|
Loading…
Reference in New Issue
Block a user