import useSWR from "swr"; import { useRouter } from "next/router"; // services import { WorkspaceService } from "services/workspace.service"; // components import { ProfileNavbar, ProfileSidebar } from "components/profile"; // constants import { WORKSPACE_MEMBERS_ME } from "constants/fetch-keys"; type Props = { children: React.ReactNode; className?: string; }; // services const workspaceService = new WorkspaceService(); export const ProfileAuthWrapper: React.FC = ({ children, className }) => { const router = useRouter(); const { workspaceSlug } = router.query; const { data: memberDetails } = useSWR( workspaceSlug ? WORKSPACE_MEMBERS_ME(workspaceSlug.toString()) : null, workspaceSlug ? () => workspaceService.workspaceMemberMe(workspaceSlug.toString()) : null ); const isAuthorized = memberDetails?.role === 20 || memberDetails?.role === 15 || memberDetails?.role === 10; return (
{isAuthorized ? (
{children}
) : (
You do not have the permission to access this page.
)}
); };