From 5a8046bed9f8548fd3396abfd10975102e54d1da Mon Sep 17 00:00:00 2001 From: jabahum Date: Wed, 21 May 2025 13:04:56 +0300 Subject: [PATCH] make snackbars automatically disappear after 3 secs --- .../regimen-editor/regimen-form.component.tsx | 8 +++++--- .../move-to-next-service-point.workspace.tsx | 20 +++++++++++-------- .../pick-patient-dialog.component.tsx | 10 ++++++---- .../visit-form/visit-form.component.tsx | 12 +++++++---- .../system-info/system-info.component.tsx | 4 +++- 5 files changed, 34 insertions(+), 20 deletions(-) diff --git a/packages/esm-care-panel-app/src/regimen-editor/regimen-form.component.tsx b/packages/esm-care-panel-app/src/regimen-editor/regimen-form.component.tsx index 15e320f5..cae1032e 100644 --- a/packages/esm-care-panel-app/src/regimen-editor/regimen-form.component.tsx +++ b/packages/esm-care-panel-app/src/regimen-editor/regimen-form.component.tsx @@ -17,9 +17,9 @@ import { toOmrsIsoString, toDateObjectStrict, showNotification, - showToast, useConfig, restBaseUrl, + showSnackbar, } from '@openmrs/esm-framework'; import styles from './standard-regimen.scss'; import StandardRegimen from './standard-regimen.component'; @@ -192,10 +192,11 @@ const RegimenForm: React.FC = ({ saveEncounter(encounterToSave).then( (response) => { if (response.status === 201) { - showToast({ + showSnackbar({ kind: 'success', title: t('regimenUpdated', 'Regimen updated'), - description: t('regimenUpdatedSuccessfully', `Regimen updated successfully.`), + subtitle: t('regimenUpdatedSuccessfully', `Regimen updated successfully.`), + autoClose: true, }); setIsSubmitting(false); mutate(`${restBaseUrl}/currentProgramDetails?patientUuid=${patientUuid}`); @@ -212,6 +213,7 @@ const RegimenForm: React.FC = ({ kind: 'error', critical: true, description: error?.message, + millis: 3000, }); }, ); diff --git a/packages/esm-patient-queues-app/src/active-visits/move-to-next-service-point.workspace.tsx b/packages/esm-patient-queues-app/src/active-visits/move-to-next-service-point.workspace.tsx index 37885944..da0fcfa3 100644 --- a/packages/esm-patient-queues-app/src/active-visits/move-to-next-service-point.workspace.tsx +++ b/packages/esm-patient-queues-app/src/active-visits/move-to-next-service-point.workspace.tsx @@ -17,10 +17,10 @@ import { navigate, restBaseUrl, showNotification, - showToast, useLayoutType, useSession, getSessionStore, + showSnackbar, } from '@openmrs/esm-framework'; import { useTranslation } from 'react-i18next'; import { useQueueRoomLocations } from '../hooks/useQueueRooms'; @@ -98,6 +98,7 @@ const MoveToNextServicePointForm: React.FC = ({ kind: 'error', critical: true, description: errorMessages.join(','), + millis: 3000, }); }) .finally(() => setIsLoading(false)); @@ -115,6 +116,8 @@ const MoveToNextServicePointForm: React.FC = ({ title: 'Queue entry not found', kind: 'warning', description: 'The server did not return a valid queue entry.', + critical: true, + millis: 3000, }); } } catch (error) { @@ -124,6 +127,7 @@ const MoveToNextServicePointForm: React.FC = ({ kind: 'error', critical: true, description: errorMessages.join(', '), + millis: 3000, }); } }, [patientQueueUuid]); @@ -149,7 +153,6 @@ const MoveToNextServicePointForm: React.FC = ({ defaultValues: { priorityComment: priorityLabels[contentSwitcherIndex], status: statusLabels[statusSwitcherIndex].status, - }, }); @@ -176,11 +179,11 @@ const MoveToNextServicePointForm: React.FC = ({ if (status === QueueStatus.Pending) { if (queueEntry.length > 0) { await updateQueueEntry(status, provider, queueEntry[0]?.uuid, 0, priorityComment, comment).then(() => { - showToast({ - critical: true, + showSnackbar({ title: t('moveToNextServicePoint', 'Move back your service point'), kind: 'success', - description: t('backToQueue', 'Successfully moved back patient to your service point'), + subtitle: t('backToQueue', 'Successfully moved back patient to your service point'), + autoClose: true, }); closeWorkspace(); handleMutate(`${restBaseUrl}/patientqueue`); @@ -240,11 +243,11 @@ const MoveToNextServicePointForm: React.FC = ({ ); if (response.status === 200) { - showToast({ - critical: true, + showSnackbar({ title: t('moveToNextServicePoint', 'Move to next service point'), kind: 'success', - description: t('movetonextservicepoint', 'Moved to next service point successfully'), + subtitle: t('movetonextservicepoint', 'Moved to next service point successfully'), + autoClose: true, }); handleMutate(`${restBaseUrl}/patientqueue`); closeWorkspace(); @@ -277,6 +280,7 @@ const MoveToNextServicePointForm: React.FC = ({ kind: 'error', critical: true, description: errorMessages.join(','), + millis: 3000, }); handleMutate(`${restBaseUrl}/patientqueue`); closeWorkspace(); diff --git a/packages/esm-patient-queues-app/src/active-visits/pick-patient-dialog.component.tsx b/packages/esm-patient-queues-app/src/active-visits/pick-patient-dialog.component.tsx index ff041f45..e0fde2fc 100644 --- a/packages/esm-patient-queues-app/src/active-visits/pick-patient-dialog.component.tsx +++ b/packages/esm-patient-queues-app/src/active-visits/pick-patient-dialog.component.tsx @@ -6,7 +6,7 @@ import { parseDate, restBaseUrl, showNotification, - showToast, + showSnackbar, useSession, } from '@openmrs/esm-framework'; @@ -54,6 +54,7 @@ const PickQueuePatientDialog: React.FC = ({ queueEn kind: 'error', critical: true, description: errorMessages.join(','), + millis: 3000, }); }, ); @@ -70,11 +71,11 @@ const PickQueuePatientDialog: React.FC = ({ queueEn const status = 'Picked'; await updateQueueEntry(status, provider, queueEntry?.uuid, 0, priorityComment, 'comment'); - showToast({ - critical: true, + showSnackbar({ title: t('updateEntry', 'Update entry'), kind: 'success', - description: t('queueEntryUpdateSuccessfully', 'Queue Entry Updated Successfully'), + subtitle: t('queueEntryUpdateSuccessfully', 'Queue Entry Updated Successfully'), + autoClose: true, }); navigate({ to: `\${openmrsSpaBase}/patient/${queueEntry?.patient?.uuid}/chart` }); @@ -88,6 +89,7 @@ const PickQueuePatientDialog: React.FC = ({ queueEn kind: 'error', critical: true, description: error?.message, + millis: 3000, }); handleMutate(`${restBaseUrl}/patientqueue`); } diff --git a/packages/esm-patient-queues-app/src/components/visit-form/visit-form.component.tsx b/packages/esm-patient-queues-app/src/components/visit-form/visit-form.component.tsx index b9ff5884..189b6850 100644 --- a/packages/esm-patient-queues-app/src/components/visit-form/visit-form.component.tsx +++ b/packages/esm-patient-queues-app/src/components/visit-form/visit-form.component.tsx @@ -17,7 +17,7 @@ import { ExtensionSlot, restBaseUrl, showNotification, - showToast, + showSnackbar, useLayoutType, usePatient, useSession, @@ -78,7 +78,7 @@ const StartVisitForm: React.FC = ({ patientUuid, closePanel, hea resolver: zodResolver(createQueueEntrySchema), defaultValues: { status: QueueStatus.Pending, - priorityComment: priorityLabels[contentSwitcherIndex] + priorityComment: priorityLabels[contentSwitcherIndex], }, }); @@ -105,6 +105,8 @@ const StartVisitForm: React.FC = ({ patientUuid, closePanel, hea title: t('visitExists', 'Visit already exists'), kind: 'info', description: t('activeVisitExists', 'An active visit already exists for this patient.'), + millis: 3000, + critical: true, }); return; } @@ -125,10 +127,11 @@ const StartVisitForm: React.FC = ({ patientUuid, closePanel, hea const createQueueResponse = await checkInQueue(request); if (createQueueResponse.status === 201) { - showToast({ + showSnackbar({ kind: 'success', title: t('startVisit', 'Start a visit'), - description: t('startVisitQueueSuccessfully', 'Patient has been added to active visits list and queue.'), + subtitle: t('startVisitQueueSuccessfully', 'Patient has been added to active visits list and queue.'), + autoClose: true, }); handleMutate(`${restBaseUrl}/patientqueue`); @@ -141,6 +144,7 @@ const StartVisitForm: React.FC = ({ patientUuid, closePanel, hea kind: 'error', critical: true, description: error?.message || t('unexpectedError', 'An unexpected error occurred'), + millis: 3000, }); } finally { setIsSubmitting(false); diff --git a/packages/esm-ugandaemr-app/src/pages/system-info/system-info.component.tsx b/packages/esm-ugandaemr-app/src/pages/system-info/system-info.component.tsx index fb3e5ce9..1c9d0d03 100644 --- a/packages/esm-ugandaemr-app/src/pages/system-info/system-info.component.tsx +++ b/packages/esm-ugandaemr-app/src/pages/system-info/system-info.component.tsx @@ -13,7 +13,7 @@ import { TableCell, Tile, } from '@carbon/react'; -import { ErrorState, UserHasAccess, showToast, showNotification, showSnackbar } from '@openmrs/esm-framework'; +import { ErrorState, UserHasAccess, showNotification, showSnackbar } from '@openmrs/esm-framework'; import { updatePropertyValue, useGetSystemInformation, useRetrieveFacilityCode } from './system-info.resources'; import styles from './system-info.scss'; import coatOfArms from '../../images/coat_of_arms.png'; @@ -161,6 +161,7 @@ const SystemInfoPage = () => { kind: 'success', title: t('Updating Facility Code', 'Updating Facility Code'), subtitle: t('UpdatingFacilityCode', `Updated Facility Code ${response?.value}`), + autoClose: true, }); }, (error) => { @@ -169,6 +170,7 @@ const SystemInfoPage = () => { kind: 'error', critical: true, description: error?.message, + millis: 3000, }); }, );