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