import { FC, ReactNode } from "react"; import { observer } from "mobx-react-lite"; import Link from "next/link"; import { useRouter } from "next/router"; import useSWR from "swr"; // hooks import { Button, Spinner } from "@plane/ui"; import { useLabel, useMember, useProject, useUser } from "hooks/store"; // icons export interface IWorkspaceAuthWrapper { children: ReactNode; } export const WorkspaceAuthWrapper: FC = observer((props) => { const { children } = props; // store hooks const { membership } = useUser(); const { fetchProjects } = useProject(); const { workspace: { fetchWorkspaceMembers }, } = useMember(); // router const router = useRouter(); const { workspaceSlug } = router.query; // fetching user workspace information useSWR( workspaceSlug ? `WORKSPACE_MEMBERS_ME_${workspaceSlug}` : null, workspaceSlug ? () => membership.fetchUserWorkspaceInfo(workspaceSlug.toString()) : null, { revalidateIfStale: false, revalidateOnFocus: false } ); // fetching workspace projects useSWR( workspaceSlug ? `WORKSPACE_PROJECTS_${workspaceSlug}` : null, workspaceSlug ? () => fetchProjects(workspaceSlug.toString()) : null, { revalidateIfStale: false, revalidateOnFocus: false } ); // fetch workspace members useSWR( workspaceSlug ? `WORKSPACE_MEMBERS_${workspaceSlug}` : null, workspaceSlug ? () => fetchWorkspaceMembers(workspaceSlug.toString()) : null, { revalidateIfStale: false, revalidateOnFocus: false } ); // fetch workspace user projects role useSWR( workspaceSlug ? `WORKSPACE_PROJECTS_ROLE_${workspaceSlug}` : null, workspaceSlug ? () => membership.fetchUserWorkspaceProjectsRole(workspaceSlug.toString()) : null, { revalidateIfStale: false, revalidateOnFocus: false } ); // while data is being loaded if (!membership.currentWorkspaceMemberInfo && membership.hasPermissionToCurrentWorkspace === undefined) { return (
); } // while user does not have access to view that workspace if ( membership.hasPermissionToCurrentWorkspace !== undefined && membership.hasPermissionToCurrentWorkspace === false ) { 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.

); } return <>{children}; });