"use client"; import { observer } from "mobx-react"; import { usePathname } from "next/navigation"; // components import { ProfileSidebar } from "@/components/profile"; // constants import { EUserWorkspaceRoles } from "@/constants/workspace"; // hooks import { useUser } from "@/hooks/store"; // local components import { ProfileNavbar } from "./navbar"; type Props = { children: React.ReactNode; }; const AUTHORIZED_ROLES = [EUserWorkspaceRoles.ADMIN, EUserWorkspaceRoles.MEMBER, EUserWorkspaceRoles.VIEWER]; const ProfileAuthWrapper: React.FC = observer((props) => { const { children } = props; // router const pathname = usePathname(); // store hooks const { membership: { currentWorkspaceRole }, } = useUser(); // derived values const isAuthorized = currentWorkspaceRole && AUTHORIZED_ROLES.includes(currentWorkspaceRole); const isAuthorizedPath = pathname.includes("assigned") || pathname.includes("created") || pathname.includes("subscribed"); const isIssuesTab = pathname.includes("assigned") || pathname.includes("created") || pathname.includes("subscribed"); return (
{isAuthorized || !isAuthorizedPath ? (
{children}
) : (
You do not have the permission to access this page.
)}
); }); export default ProfileAuthWrapper;