import React, { useState } from 'react'; import clsx from 'clsx'; import { useDeskInboxUnread } from '../../../hooks/useDeskInboxUnread'; import { MESSAGES_PAGE_HEIGHT } from '../../../utils/messagesLayout'; import { inboxTabLabel } from '../../../utils/messaging/inboxUnread'; import { PatientsPanel } from './panels/PatientsPanel'; import { ColleaguesPanel } from './panels/ColleaguesPanel'; import { PatientMessagingToggle } from './PatientMessagingToggle'; import './DeskMessages.css'; export type DeskTab = 'inbox' | 'patients' | 'colleagues'; export interface DeskDeepLink { tab?: 'patients' | 'colleagues' | 'teams'; openRequestId?: string; openWith?: string; } // The page takes the height left below its own top, measured again when anything above it moves. // WordPress chrome under the page is not the page's to absorb, so no overflow is chased. export const useMessagesTop = () => { const fitRef = React.useRef(null); React.useLayoutEffect(() => { const measure = () => { const node = fitRef.current; if (node) node.style.setProperty('--ak-messages-top', `${Math.max(Math.ceil(node.getBoundingClientRect().top + window.scrollY), 0)}px`); }; measure(); window.addEventListener('resize', measure); const observer = typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(measure); observer?.observe(document.body); return () => { window.removeEventListener('resize', measure); observer?.disconnect(); }; }, []); return fitRef; }; const TABS: { id: DeskTab; label: string }[] = [ { id: 'inbox', label: 'Inbox' }, { id: 'patients', label: 'Patients' }, { id: 'colleagues', label: 'Colleagues' }, ]; // The front desk's Messages: one row of tabs, an Inbox of every conversation, and the Patients and // Colleagues directories to start one from. export const DeskMessages: React.FC<{ deepLink: DeskDeepLink; workspace: string | undefined }> = ({ deepLink, workspace }) => { const opensColleagueDirectory = deepLink.tab === 'colleagues' && !!deepLink.openWith && !deepLink.openRequestId; const [tab, setTab] = useState(opensColleagueDirectory ? 'colleagues' : 'inbox'); // A deep link opens once; returning to a tab later must not reopen it. const [pending, setPending] = useState(deepLink); const unread = useDeskInboxUnread(); const fitRef = useMessagesTop(); return (

Messages

{TABS.map(({ id, label }) => ( ))}
{tab === 'colleagues' ? ( ) : ( )}
); }; export default DeskMessages;