import React, { useState } from 'react'; import { Button, ComboBox, InlineNotification, DropdownSkeleton, InlineLoading, Layer, ModalBody, ModalFooter, ModalHeader, } from '@carbon/react'; import { useTranslation } from 'react-i18next'; import { useLocationsByTag } from '../hooks/useAdmissionLocation'; import { type Location, navigate, setUserProperties, showSnackbar, useSession } from '@openmrs/esm-framework'; import styles from './materal-ward/ward-switch.scss'; interface WardSwitchModalProps { closeModal: () => void; } const WardSwitchModal: React.FC = ({ closeModal }) => { const { t } = useTranslation(); const { locations, isLoading, error } = useLocationsByTag('Admission Location'); const { user } = useSession(); const [selectedWard, setSelectedWard] = useState(null); const [isSaving, setIsSaving] = useState(false); const handleSave = async () => { if (!selectedWard?.uuid) { return; } if (user?.uuid) { setIsSaving(true); try { await setUserProperties(user.uuid, { defaultWardLocationUuid: selectedWard.uuid, }); } catch { showSnackbar({ title: t('errorSettingDefaultWard', 'Error setting default ward view'), subtitle: t( 'errorMessageForSettingDefaultWard', 'Proceed to selected ward view, your preference has not been set, you can try again', ), isLowContrast: true, kind: 'info', }); } finally { setIsSaving(false); } } navigate({ to: `${globalThis.spaBase}/home/ward/${selectedWard.uuid}` }); closeModal(); }; const handleCancel = () => { closeModal(); }; return (
{t('switchWard', 'Switch ward')} {error && ( )}

{t('switchWardPrompt', 'Do you want to switch the ward you are currently viewing?')}

{isLoading ? ( ) : (
item?.display ?? ''} onChange={({ selectedItem }) => setSelectedWard(selectedItem)} disabled={isLoading || isSaving} size="md" light={true} downshiftProps={{ id: 'ward-switch-selector-downshift' }} />
)} {isSaving && ( )}
); }; export default WardSwitchModal;