import { useState } from "react"; import Link from "next/link"; import { useRouter } from "next/router"; import useSWR from "swr"; // services import workspaceServices from "services/workspace.service"; // contexts import { WorkspaceMemberProvider } from "contexts/workspace-member.context"; // layouts import AppSidebar from "layouts/app-layout/app-sidebar"; import AppHeader from "layouts/app-layout/app-header"; import { UserAuthorizationLayout } from "./user-authorization-wrapper"; // components import { NotAuthorizedView, NotAWorkspaceMember } from "components/auth-screens"; import { CommandPalette } from "components/command-palette"; // icons import { PrimaryButton, Spinner } from "components/ui"; import { LayerDiagonalIcon } from "components/icons"; // fetch-keys import { WORKSPACE_MEMBERS_ME } from "constants/fetch-keys"; type Props = { children: React.ReactNode; noHeader?: boolean; bg?: "primary" | "secondary"; breadcrumbs?: JSX.Element; left?: JSX.Element; right?: JSX.Element; }; export const WorkspaceAuthorizationLayout: React.FC = ({ children, noHeader = false, bg = "primary", breadcrumbs, left, right, }) => { const [toggleSidebar, setToggleSidebar] = useState(false); const router = useRouter(); const { workspaceSlug } = router.query; const { data: workspaceMemberMe, error } = useSWR( workspaceSlug ? WORKSPACE_MEMBERS_ME(workspaceSlug as string) : null, workspaceSlug ? () => workspaceServices.workspaceMemberMe(workspaceSlug.toString()) : null ); if (!workspaceMemberMe && !error) return (

Loading your workspace...

); if (error?.status === 401 || error?.status === 403) return ; // FIXME: show 404 for workspace not workspace member if (error?.status === 404) { return (

No such workspace exist. Create one?

); } const settingsLayout = router.pathname.includes("/settings"); const memberType = { isOwner: workspaceMemberMe?.role === 20, isMember: workspaceMemberMe?.role === 15, isViewer: workspaceMemberMe?.role === 10, isGuest: workspaceMemberMe?.role === 5, }; return (
{settingsLayout && (memberType?.isGuest || memberType?.isViewer) ? ( Go to workspace } type="workspace" /> ) : (
{!noHeader && ( )}
{children}
)}
); };