import type { ReactNode } from "react"; import { Navigate } from "react-router-dom"; import { useStaffPermissionServiceContext } from "../../services"; import { getDefaultDashboardPath } from "../../utils/staffLanding.ts"; const CLINICIAN_OVERVIEW = "/dashboard/overview"; /** * The clinician overview belongs to the workspace that lands on it. Any other active workspace, even for * someone who also practises, goes to its own landing instead of seeing the clinician board. */ const ClinicianOverviewGate = ({ children }: { children: ReactNode }) => { const { activeWorkspace } = useStaffPermissionServiceContext(); // Until the workspace is known there is nothing to decide; guessing would send a clinician to Profile. if (!activeWorkspace) return null; const landing = getDefaultDashboardPath(activeWorkspace as string); if (landing !== CLINICIAN_OVERVIEW) { return ; } return <>{children}; }; export default ClinicianOverviewGate;