-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(fix)O3-2197:Unable to remove a patient from a list
- Loading branch information
Showing
6 changed files
with
142 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
packages/esm-patient-list-app/src/patient-table/overflow-menu.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import React, { useCallback, useState, useEffect } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { removePatientFromList } from '../api/api-remote'; | ||
import { ExtensionSlot, isDesktop, showToast, useLayoutType } from '@openmrs/esm-framework'; | ||
import { OverflowMenu, Layer, OverflowMenuItem, Modal } from '@carbon/react'; | ||
import overflowMenuStyles from './overflow-menu.scss'; | ||
|
||
interface OverflowMenuCellProps { | ||
cohortMembershipUuid: string; | ||
cohortName: string; | ||
mutatePatientListMembers: () => void; | ||
} | ||
|
||
const OverflowMenuComponent: React.FC<OverflowMenuCellProps> = ({ | ||
cohortMembershipUuid, | ||
cohortName, | ||
mutatePatientListMembers, | ||
}) => { | ||
const { t } = useTranslation(); | ||
const layoutType = useLayoutType(); | ||
const desktopLayout = isDesktop(layoutType); | ||
const [isDeleting, setIsDeleting] = useState(false); | ||
const [showConfirmationModal, setShowConfirmationModal] = useState(false); | ||
|
||
const confirmRemovePatientFromList = useCallback(async () => { | ||
setIsDeleting(true); | ||
try { | ||
await removePatientFromList(cohortMembershipUuid); | ||
mutatePatientListMembers(); | ||
showToast({ | ||
title: t('removed', 'Removed'), | ||
description: `${t('successRemovePatientFromList', 'Successfully removed patient from list')}: ${cohortName}`, | ||
}); | ||
} catch (error) { | ||
showToast({ | ||
title: t('error', 'Error'), | ||
kind: 'error', | ||
description: `${t('errorRemovePatientFromList', 'Failed to remove patient from list')}: ${cohortName}`, | ||
}); | ||
} | ||
|
||
setIsDeleting(false); | ||
setShowConfirmationModal(false); | ||
}, [cohortMembershipUuid, cohortName, mutatePatientListMembers, t]); | ||
|
||
return ( | ||
<Layer className={overflowMenuStyles.layer}> | ||
<OverflowMenu | ||
data-floating-menu-container | ||
ariaLabel={`Remove patient from the ${cohortName} list`} | ||
size={desktopLayout ? 'sm' : 'lg'} | ||
flipped> | ||
<ExtensionSlot name="cohort-member-action-items" /> | ||
<OverflowMenuItem | ||
size={desktopLayout ? 'sm' : 'lg'} | ||
className={overflowMenuStyles.menuItem} | ||
onClick={() => setShowConfirmationModal(true)} | ||
itemText={t('removePatient', 'Remove patient')} | ||
isDelete | ||
/> | ||
</OverflowMenu> | ||
|
||
{showConfirmationModal && ( | ||
<Modal | ||
open | ||
danger | ||
modalHeading={t('confirmRemovePatient', 'Are you sure you want to remove this patient from {cohortName}?', { | ||
cohortName: cohortName, | ||
})} | ||
modalLabel={t('removePatient', 'Remove patient')} | ||
primaryButtonText="Remove patient" | ||
secondaryButtonText="Cancel" | ||
onRequestClose={() => setShowConfirmationModal(false)} | ||
onRequestSubmit={confirmRemovePatientFromList} | ||
primaryButtonDisabled={isDeleting} | ||
/> | ||
)} | ||
</Layer> | ||
); | ||
}; | ||
|
||
export default OverflowMenuComponent; |
6 changes: 6 additions & 0 deletions
6
packages/esm-patient-list-app/src/patient-table/overflow-menu.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.layer { | ||
height: 100%; | ||
} | ||
.menuItem { | ||
max-width: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters