import React from "react"; import { useRouter } from "next/router"; import Link from "next/link"; import { RootStore } from "store/root"; import { useMobxStore } from "lib/mobx/store-provider"; export enum EUserWorkspaceRoles { GUEST = 5, MEMBER = 15, ADMIN = 20, } export const WorkspaceSettingsSidebar = () => { const router = useRouter(); const { workspaceSlug } = router.query; const { user: userStore }: RootStore = useMobxStore(); const workspaceMemberInfo = userStore.currentWorkspaceRole || EUserWorkspaceRoles.GUEST; const workspaceLinks: Array<{ label: string; href: string; access: EUserWorkspaceRoles; }> = [ { label: "General", href: `/${workspaceSlug}/settings`, access: EUserWorkspaceRoles.GUEST, }, { label: "Members", href: `/${workspaceSlug}/settings/members`, access: EUserWorkspaceRoles.GUEST, }, { label: "Billing & Plans", href: `/${workspaceSlug}/settings/billing`, access: EUserWorkspaceRoles.ADMIN, }, { label: "Integrations", href: `/${workspaceSlug}/settings/integrations`, access: EUserWorkspaceRoles.ADMIN, }, { label: "Imports", href: `/${workspaceSlug}/settings/imports`, access: EUserWorkspaceRoles.GUEST, }, { label: "Exports", href: `/${workspaceSlug}/settings/exports`, access: EUserWorkspaceRoles.GUEST, }, { label: "Webhooks", href: `/${workspaceSlug}/settings/webhooks`, access: EUserWorkspaceRoles.ADMIN, }, { label: "API Tokens", href: `/${workspaceSlug}/settings/api-tokens`, access: EUserWorkspaceRoles.GUEST, }, ]; 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`, }, ]; function highlightSetting(label: string, link: string): boolean { if (router.asPath.startsWith(link) && (label === "Imports" || label === "Api tokens")) { return true; } return link === router.asPath; } return (
SETTINGS
{workspaceLinks.map( (link) => workspaceMemberInfo >= link.access && (
{link.label}
) )}
My Account
{profileLinks.map((link) => (
{link.label}
))}
); };