"use client"; import { observer } from "mobx-react"; import { useParams, usePathname } from "next/navigation"; import useSWR from "swr"; // components import { AppHeader, ContentWrapper } from "@/components/core"; import { ProfileSidebar } from "@/components/profile"; // constants import { USER_PROFILE_PROJECT_SEGREGATION } from "@/constants/fetch-keys"; import { PROFILE_ADMINS_TAB, PROFILE_VIEWER_TAB } from "@/constants/profile"; // hooks import { useUserPermissions } from "@/hooks/store"; import useSize from "@/hooks/use-window-size"; import { EUserPermissions, EUserPermissionsLevel } from "@/plane-web/constants/user-permissions"; // local components import { UserService } from "@/services/user.service"; import { UserProfileHeader } from "./header"; import { ProfileIssuesMobileHeader } from "./mobile-header"; import { ProfileNavbar } from "./navbar"; const userService = new UserService(); type Props = { children: React.ReactNode; }; const UseProfileLayout: React.FC = observer((props) => { const { children } = props; // router const { workspaceSlug, userId } = useParams(); const pathname = usePathname(); // store hooks const { allowPermissions } = useUserPermissions(); // derived values const isAuthorized = allowPermissions( [EUserPermissions.ADMIN, EUserPermissions.MEMBER], EUserPermissionsLevel.WORKSPACE ); const windowSize = useSize(); const isSmallerScreen = windowSize[0] >= 768; const { data: userProjectsData } = useSWR( workspaceSlug && userId ? USER_PROFILE_PROJECT_SEGREGATION(workspaceSlug.toString(), userId.toString()) : null, workspaceSlug && userId ? () => userService.getUserProfileProjectsSegregation(workspaceSlug.toString(), userId.toString()) : null ); // derived values const isAuthorizedPath = pathname.includes("assigned") || pathname.includes("created") || pathname.includes("subscribed"); const isIssuesTab = pathname.includes("assigned") || pathname.includes("created") || pathname.includes("subscribed"); const tabsList = isAuthorized ? [...PROFILE_VIEWER_TAB, ...PROFILE_ADMINS_TAB] : PROFILE_VIEWER_TAB; const currentTab = tabsList.find((tab) => pathname === `/${workspaceSlug}/profile/${userId}${tab.selected}`); return ( <> {/* Passing the type prop from the current route value as we need the header as top most component. TODO: We are depending on the route path to handle the mobile header type. If the path changes, this logic will break. */}
} mobileHeader={isIssuesTab && } />
{isAuthorized || !isAuthorizedPath ? (
{children}
) : (
You do not have the permission to access this page.
)}
{!isSmallerScreen && }
{isSmallerScreen && }
); }); export default UseProfileLayout;