-
Notifications
You must be signed in to change notification settings - Fork 229
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
3 changed files
with
74 additions
and
4 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
54 changes: 54 additions & 0 deletions
54
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,54 @@ | ||
import { isDesktop, showToast, useLayoutType } from '@openmrs/esm-framework'; | ||
import React, { useCallback } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { removePatientFromList } from '../api/api-remote'; | ||
import { OverflowMenu, Layer, OverflowMenuItem } from '@carbon/react'; | ||
import styles from './patient-table.scss'; | ||
|
||
interface OverflowMenuCellProps { | ||
cohortMembershipUuid: string; | ||
} | ||
|
||
const OverflowMenuComponent: React.FC<OverflowMenuCellProps> = ({ cohortMembershipUuid }) => { | ||
const { t } = useTranslation(); | ||
const layoutType = useLayoutType(); | ||
const desktopLayout = isDesktop(layoutType); | ||
|
||
const handleRemovePatientFromList = useCallback(() => { | ||
removePatientFromList(cohortMembershipUuid) | ||
.then(() => | ||
showToast({ | ||
title: t('removed', 'Removed'), | ||
description: t('removePatientFromList', 'Successfully removed patient from list'), | ||
kind: 'success', | ||
}), | ||
) | ||
.catch(() => | ||
showToast({ | ||
title: t('error', 'Error'), | ||
description: t('errorRemovePatientFromList', "Couldn't remove patient from this list"), | ||
kind: 'error', | ||
}), | ||
); | ||
}, [cohortMembershipUuid, t]); | ||
|
||
return ( | ||
<Layer className={styles.layer}> | ||
<OverflowMenu | ||
data-floating-menu-container | ||
ariaLabel="Remove patient from the list" | ||
size={desktopLayout ? 'sm' : 'lg'} | ||
flipped> | ||
<OverflowMenuItem | ||
size={desktopLayout ? 'sm' : 'lg'} | ||
className={styles.menuItem} | ||
onClick={handleRemovePatientFromList} | ||
itemText={t('removePatient', 'Remove patient')} | ||
isDelete | ||
/> | ||
</OverflowMenu> | ||
</Layer> | ||
); | ||
}; | ||
|
||
export default OverflowMenuComponent; |
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