2023-10-18 13:47:02 +00:00
|
|
|
import React from "react";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import Link from "next/link";
|
2023-11-15 10:26:57 +00:00
|
|
|
import { RootStore } from "store/root";
|
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
|
|
|
|
|
|
|
export enum EUserWorkspaceRoles {
|
|
|
|
GUEST = 5,
|
|
|
|
MEMBER = 15,
|
|
|
|
ADMIN = 20,
|
|
|
|
}
|
2023-10-18 13:47:02 +00:00
|
|
|
|
|
|
|
export const WorkspaceSettingsSidebar = () => {
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug } = router.query;
|
2023-11-15 10:26:57 +00:00
|
|
|
const { user: userStore }: RootStore = useMobxStore();
|
|
|
|
|
|
|
|
const workspaceMemberInfo = userStore.currentWorkspaceRole || EUserWorkspaceRoles.GUEST;
|
2023-10-18 13:47:02 +00:00
|
|
|
|
|
|
|
const workspaceLinks: Array<{
|
|
|
|
label: string;
|
|
|
|
href: string;
|
2023-11-15 10:26:57 +00:00
|
|
|
access: EUserWorkspaceRoles;
|
2023-10-18 13:47:02 +00:00
|
|
|
}> = [
|
|
|
|
{
|
|
|
|
label: "General",
|
|
|
|
href: `/${workspaceSlug}/settings`,
|
2023-11-15 10:26:57 +00:00
|
|
|
access: EUserWorkspaceRoles.GUEST,
|
2023-10-18 13:47:02 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Members",
|
|
|
|
href: `/${workspaceSlug}/settings/members`,
|
2023-11-15 10:26:57 +00:00
|
|
|
access: EUserWorkspaceRoles.GUEST,
|
2023-10-18 13:47:02 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Billing & Plans",
|
|
|
|
href: `/${workspaceSlug}/settings/billing`,
|
2023-11-15 10:26:57 +00:00
|
|
|
access: EUserWorkspaceRoles.ADMIN,
|
2023-10-18 13:47:02 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Integrations",
|
|
|
|
href: `/${workspaceSlug}/settings/integrations`,
|
2023-11-15 10:26:57 +00:00
|
|
|
access: EUserWorkspaceRoles.ADMIN,
|
2023-10-18 13:47:02 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Imports",
|
|
|
|
href: `/${workspaceSlug}/settings/imports`,
|
2023-11-15 10:26:57 +00:00
|
|
|
access: EUserWorkspaceRoles.GUEST,
|
2023-10-18 13:47:02 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Exports",
|
|
|
|
href: `/${workspaceSlug}/settings/exports`,
|
2023-11-15 10:26:57 +00:00
|
|
|
access: EUserWorkspaceRoles.GUEST,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Webhooks",
|
|
|
|
href: `/${workspaceSlug}/settings/webhooks`,
|
|
|
|
access: EUserWorkspaceRoles.ADMIN,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "API Tokens",
|
|
|
|
href: `/${workspaceSlug}/settings/api-tokens`,
|
|
|
|
access: EUserWorkspaceRoles.GUEST,
|
2023-10-18 13:47:02 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const profileLinks: Array<{
|
|
|
|
label: string;
|
|
|
|
href: string;
|
|
|
|
}> = [
|
|
|
|
{
|
|
|
|
label: "Profile",
|
|
|
|
href: `/${workspaceSlug}/me/profile`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Activity",
|
|
|
|
href: `/${workspaceSlug}/me/profile/activity`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Preferences",
|
|
|
|
href: `/${workspaceSlug}/me/profile/preferences`,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2023-11-15 10:26:57 +00:00
|
|
|
function highlightSetting(label: string, link: string): boolean {
|
|
|
|
if (router.asPath.startsWith(link) && (label === "Imports" || label === "Api tokens")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return link === router.asPath;
|
|
|
|
}
|
|
|
|
|
2023-10-18 13:47:02 +00:00
|
|
|
return (
|
|
|
|
<div className="flex flex-col gap-6 w-80 px-5">
|
|
|
|
<div className="flex flex-col gap-2">
|
|
|
|
<span className="text-xs text-custom-sidebar-text-400 font-semibold">SETTINGS</span>
|
|
|
|
<div className="flex flex-col gap-1 w-full">
|
2023-11-15 10:26:57 +00:00
|
|
|
{workspaceLinks.map(
|
|
|
|
(link) =>
|
|
|
|
workspaceMemberInfo >= link.access && (
|
|
|
|
<Link key={link.href} href={link.href}>
|
|
|
|
<a>
|
|
|
|
<div
|
|
|
|
className={`px-4 py-2 text-sm font-medium rounded-md ${
|
|
|
|
router.pathname.split("/")?.[3] === link.href.split("/")?.[3]
|
|
|
|
? "bg-custom-primary-100/10 text-custom-primary-100"
|
|
|
|
: "text-custom-sidebar-text-200 hover:bg-custom-sidebar-background-80 focus:bg-custom-sidebar-background-80"
|
|
|
|
}`}
|
|
|
|
>
|
|
|
|
{link.label}
|
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
)
|
|
|
|
)}
|
2023-10-18 13:47:02 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="flex flex-col gap-2">
|
|
|
|
<span className="text-xs text-custom-sidebar-text-400 font-semibold">My Account</span>
|
|
|
|
<div className="flex flex-col gap-1 w-full">
|
|
|
|
{profileLinks.map((link) => (
|
|
|
|
<Link key={link.href} href={link.href}>
|
|
|
|
<a>
|
|
|
|
<div
|
|
|
|
className={`px-4 py-2 text-sm font-medium rounded-md ${
|
|
|
|
(link.label === "Import" ? router.asPath.includes(link.href) : router.asPath === link.href)
|
|
|
|
? "bg-custom-primary-100/10 text-custom-primary-100"
|
|
|
|
: "text-custom-sidebar-text-200 hover:bg-custom-sidebar-background-80 focus:bg-custom-sidebar-background-80"
|
|
|
|
}`}
|
|
|
|
>
|
|
|
|
{link.label}
|
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|