import React, { useState } from 'react'; import { Tab, TabList, TabPanel, TabPanels, Tabs } from '@carbon/react'; import { useTranslation } from 'react-i18next'; import { useConfig, userHasAccess, useSession } from '@openmrs/esm-framework'; import PatientQueueHeader from './patient-queue-header/patient-queue-header.component'; import QueueLocationHeaderTitle from './patient-queue-header/queue-location-header-title.component'; import ClinicMetrics from './metrics/metrics-container.component'; import ClinicOverview from './clinic-administrator/clinic-overview.component'; import AttendingPatients from './attending-patients/attending-patients.component'; import DefaultQueueTable from './queue-table/default-queue-table.component'; import { type ConfigObject } from './config-schema'; import styles from './home.scss'; const clinicOverviewTabIndex = 0; const Home: React.FC = () => { const { t } = useTranslation(); const { clinicAdministratorScreen: { privilege }, } = useConfig(); const session = useSession(); const [selectedTabIndex, setSelectedTabIndex] = useState(clinicOverviewTabIndex); // Until the session resolves, fall back to the standard dashboard rather than to nothing: the tab // strip appearing a moment late is a far smaller cost than a blank Service Queues page. An empty // privilege must hide the tabs rather than open them to everyone, since userHasAccess grants access // to every user when the privilege is falsy. const showClinicOverview = Boolean(privilege) && Boolean(session?.user) && userHasAccess(privilege, session.user); if (!showClinicOverview) { return ( <> } actions={} /> ); } // The overview tab carries its own clinic totals, so the header's metrics would duplicate them. return ( <> } actions={selectedTabIndex === clinicOverviewTabIndex ? undefined : } /> setSelectedTabIndex(selectedIndex)}> {t('clinicOverview', 'Clinic overview')} {t('waitingList', 'Waiting list')} {/* Carbon keeps hidden panels mounted, so each panel is gated on being the selected one: otherwise the tab nobody is looking at keeps polling for queue entries. */} {selectedTabIndex === clinicOverviewTabIndex && } {selectedTabIndex !== clinicOverviewTabIndex && } ); }; function WaitingListView() { return ( <> ); } export default Home;