import { FC, ReactNode } from "react"; import { useRouter } from "next/router"; import Link from "next/link"; import useSWR from "swr"; // services import workspaceServices from "services/workspace.service"; // icons import { Spinner, PrimaryButton, SecondaryButton } from "components/ui"; // fetch-keys import { WORKSPACE_MEMBERS_ME } from "constants/fetch-keys"; export interface IWorkspaceAuthWrapper { children: ReactNode; noHeader?: boolean; bg?: "primary" | "secondary"; breadcrumbs?: JSX.Element; left?: JSX.Element; right?: JSX.Element; } export const WorkspaceAuthWrapper: FC = (props) => { const { children } = props; // router const router = useRouter(); const { workspaceSlug } = router.query; // fetching user workspace information const { data: workspaceMemberMe, error } = useSWR( workspaceSlug ? WORKSPACE_MEMBERS_ME(workspaceSlug as string) : null, workspaceSlug ? () => workspaceServices.workspaceMemberMe(workspaceSlug.toString()) : null ); // while data is being loaded if (!workspaceMemberMe && !error) { return (
); } // while user does not have access to view that workspace if (error?.status === 401 || error?.status === 403) { return (

Not Authorized!

You{"'"}re not a member of this workspace. Please contact the workspace admin to get an invitation or check your pending invitations.

Check pending invites Create new workspace
); } return <>{children}; };