Skip to content

Commit

Permalink
(fix) O3-2718: inconsistent notification style upon cancelling an act…
Browse files Browse the repository at this point in the history
…ive visit (#1566)

O3-2718: Fix inconsistent notification style upon cancelling an active visit

Co-authored-by: Ps <ps.world.is.here@gmal.com>
Co-authored-by: Dennis Kigen <kigen.work@gmail.com>
  • Loading branch information
3 people committed Jan 8, 2024
1 parent 12266ec commit 1442849
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,35 @@ export function useDeleteVisit(patientUuid: string, visit: Visit, onVisitDelete

const initiateDeletingVisit = () => {
setIsDeletingVisit(true);
const isCurrentVisitDeleted = !visit?.stopDatetime;
const isCurrentVisitDeleted = !visit?.stopDatetime; // True if it's an active visit

deleteVisit(visit?.uuid)
.then(() => {
mutateVisits();
mutateCurrentVisit();
// TODO: Needs to be replaced with Actionable Snackbar when Actionable
showActionableNotification({
title: !isCurrentVisitDeleted
? t('visitDeleted', '{{visit}} deleted', {
visit: visit?.visitType?.display ?? t('visit', 'Visit'),
})
: t('visitCancelled', 'Visit cancelled'),
kind: 'success',
subtitle: !isCurrentVisitDeleted
? t('visitDeletedSuccessfully', '{{visit}} deleted successfully', {
visit: visit?.visitType?.display ?? t('visit', 'Visit'),
})
: t('visitCancelSuccessMessage', 'Active {{visit}} cancelled successfully', {
visit: visit?.visitType?.display ?? t('visit', 'Visit'),
}),
actionButtonLabel: t('undo', 'Undo'),
onActionButtonClick: restoreDeletedVisit,
});
if (!isCurrentVisitDeleted) {
showActionableNotification({
title: t('visitDeleted', '{{visit}} deleted', {
visit: visit?.visitType?.display ?? t('visit', 'Visit'),
}),
subtitle: t('visitDeletedSuccessfully', '{{visit}} deleted successfully', {
visit: visit?.visitType?.display ?? t('visit', 'Visit'),
}),
kind: 'success',
actionButtonLabel: t('undo', 'Undo'),
onActionButtonClick: restoreDeletedVisit,
});
} else {
showSnackbar({
title: t('visitCancelled', 'Visit cancelled'),
subtitle: t('visitCancelSuccessMessage', 'Active {{visit}} cancelled successfully', {
visit: visit?.visitType?.display ?? t('visit', 'Visit'),
}),
isLowContrast: true,
kind: 'success',
});
}
onVisitDelete?.();
})
.catch(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import CancelVisitDialog from './cancel-visit-dialog.component';
const mockedCloseModal = jest.fn();
const mockedOpenmrsFetch = jest.mocked(openmrsFetch);
const mockedRemoveQueuedPatient = jest.mocked(removeQueuedPatient);
const mockedActionableNotification = jest.mocked(showActionableNotification);
const mockedShowSnackbar = jest.mocked(showSnackbar);
const mockedUseVisit = jest.mocked(useVisit) as jest.Mock;
const mockedUseVisitQueueEntry = jest.mocked(useVisitQueueEntry);
Expand Down Expand Up @@ -92,12 +91,11 @@ describe('Cancel visit', () => {
method: 'DELETE',
});

expect(mockedActionableNotification).toHaveBeenCalledWith(
expect(mockedShowSnackbar).toHaveBeenCalledWith(
expect.objectContaining({
kind: 'success',
title: 'Visit cancelled',
subtitle: 'Active Facility Visit cancelled successfully',
actionButtonLabel: 'Undo',
}),
);
});
Expand Down

0 comments on commit 1442849

Please sign in to comment.