import React, { useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { StructuredListSkeleton, ContentSwitcher, Switch } from '@carbon/react'; import styles from './care-panel.scss'; import { useEnrollmentHistory } from '../hooks/useEnrollmentHistory'; import ProgramSummary from '../program-summary/program-summary.component'; import ProgramEnrollment from '../program-enrollment/program-enrollment.component'; import { CardHeader, EmptyState } from '@openmrs/esm-patient-common-lib'; import RegimenHistory from '../regimen/regimen-history.component'; import first from 'lodash/first'; import sortBy from 'lodash/sortBy'; import { ErrorState } from '@openmrs/esm-framework'; import { type SwitchEventHandlersParams } from '@carbon/react/lib/components/Switch/Switch'; type CarePanelProps = { patientUuid: string; formEntrySub: any; }; const CarePanel: React.FC = ({ patientUuid, formEntrySub }) => { const { t } = useTranslation(); const { isLoading, error, enrollments, isValidating } = useEnrollmentHistory(patientUuid); const switcherHeaders = sortBy(Object.keys(enrollments || {})); const [switchItem, setSwitcherItem] = useState({ index: 0 }); const patientEnrollments = useMemo( () => (isLoading ? [] : enrollments[switchItem?.name || first(switcherHeaders)]), [enrollments, isLoading, switchItem?.name, switcherHeaders], ); if (isLoading) { return (
); } if (error) { return ; } if (Object.keys(enrollments).length === 0) { return ( <> ); } return (
setSwitcherItem(params)}> {switcherHeaders?.map((enrollment) => ( ))}
); }; export default CarePanel;