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
|
|
|
},
|
|
|
|
{
|
2023-11-27 06:44:06 +00:00
|
|
|
label: "Billing and plans",
|
2023-10-18 13:47:02 +00:00
|
|
|
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-27 06:44:06 +00:00
|
|
|
access: EUserWorkspaceRoles.ADMIN,
|
2023-10-18 13:47:02 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Exports",
|
|
|
|
href: `/${workspaceSlug}/settings/exports`,
|
2023-11-27 11:45:48 +00:00
|
|
|
access: EUserWorkspaceRoles.MEMBER,
|
2023-11-15 10:26:57 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Webhooks",
|
|
|
|
href: `/${workspaceSlug}/settings/webhooks`,
|
|
|
|
access: EUserWorkspaceRoles.ADMIN,
|
|
|
|
},
|
|
|
|
{
|
2023-11-27 06:44:06 +00:00
|
|
|
label: "API tokens",
|
2023-11-15 10:26:57 +00:00
|
|
|
href: `/${workspaceSlug}/settings/api-tokens`,
|
2023-11-27 06:44:06 +00:00
|
|
|
access: EUserWorkspaceRoles.ADMIN,
|
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>
|
|
|
|
);
|
|
|
|
};
|