import type { ReactNode } from "react"; import { Link } from "react-router-dom"; import { useAuthServiceContext, useStaffPermissionServiceContext } from "../../services"; import { STAFF_WORKSPACES, getWorkspaceLabel, type StaffWorkspace } from "../../utils/staffRoleCatalog.ts"; import { getDefaultDashboardPath } from "../../utils/staffLanding.ts"; import AppSpinner from "../AppSpinner/AppSpinner"; import { useHasStalled } from "../StalledSession/StalledSession"; import AccessNotSettled from "./AccessNotSettled"; /** * Said in place of a patient or practice page that the person's workspace does not include, such as a typed chart * address from HR or Referrals. Nothing of the page mounts. A person who also holds a workspace that includes it is * told to switch; anyone else is told whom to ask. */ const NotInThisWorkspace = ({ workspace, includedIn }: { workspace: string; includedIn?: string }) => { const label = getWorkspaceLabel(workspace as StaffWorkspace); return (

This page isn’t part of your {label} workspace

{includedIn ? `Switch to your ${getWorkspaceLabel(includedIn as StaffWorkspace)} workspace to open it.` : "Patient records and the practice’s clinical and front-desk pages aren’t part of your role at this practice. If you need them, ask a practice administrator."}

Go to my {label} workspace
); }; // The workspaces the patient list and the chart already admit themselves; these only refuse before they mount. export const PATIENT_LIST_WORKSPACES: readonly string[] = [STAFF_WORKSPACES.PRACTITIONER, STAFF_WORKSPACES.RECEPTIONIST]; export const CHART_WORKSPACES: readonly string[] = [...PATIENT_LIST_WORKSPACES, "Patient", "RelatedPerson"]; /** * Renders the page only in these workspaces, and says so in place otherwise. Nothing of it mounts until a workspace * resolves: the wait is visible, and one that never ends offers a retry. */ export const OnlyInWorkspaces = ({ workspaces, children }: { workspaces: readonly string[]; children: ReactNode }) => { const { availableWorkspaces } = useAuthServiceContext(); const { activeWorkspace } = useStaffPermissionServiceContext(); const stalled = useHasStalled(!activeWorkspace); if (!activeWorkspace) { return stalled ? ( ) : ; } if (workspaces.includes(activeWorkspace)) return <>{children}; return ( workspaces.includes(workspace))} /> ); }; export default NotInThisWorkspace;