-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
183 additions
and
123 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
61 changes: 48 additions & 13 deletions
61
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 |
---|---|---|
@@ -1,24 +1,59 @@ | ||
import React from 'react'; | ||
import { OverflowMenu, OverflowMenuItem } from '@carbon/react'; | ||
import { isDesktop, showToast, useLayoutType } from '@openmrs/esm-framework'; | ||
import React, { useCallback } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { deletePatientFromList } from '../api/api-remote'; | ||
import { removePatientFromList } from '../api/api-remote'; | ||
import { OverflowMenu, TableCell, Layer, OverflowMenuItem } from '@carbon/react'; | ||
import styles from './patient-table.scss'; | ||
|
||
interface PatientListOverflowMenuComponentProps { | ||
patientUuid: string; | ||
interface OverflowMenuComponentProps { | ||
cohortMembershipUuid: string; | ||
} | ||
|
||
const PatientListOverflowMenuComponent: React.FC<PatientListOverflowMenuComponentProps> = ({ patientUuid }) => { | ||
const OverflowMenuComponent: React.FC<OverflowMenuComponentProps> = ({ cohortMembershipUuid }) => { | ||
const { t } = useTranslation(); | ||
const layoutType = useLayoutType(); | ||
const desktopLayout = isDesktop(layoutType); | ||
|
||
const handleDeletePatient = async () => { | ||
alert('deleteCalled'); | ||
}; | ||
// eslint-disable-next-line no-console | ||
console.log(cohortMembershipUuid); | ||
|
||
const handleRemovePatientFromList = useCallback(() => { | ||
removePatientFromList(cohortMembershipUuid) | ||
.then(() => | ||
showToast({ | ||
title: t('removed', 'Removed'), | ||
description: t('deletedPatientFromList', '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 ( | ||
<OverflowMenu ariaLabel="Actions" size="sm" flipped> | ||
<OverflowMenuItem itemText={t('deletePatient', 'Delete Patient')} onClick={handleDeletePatient} isDelete /> | ||
</OverflowMenu> | ||
<TableCell className="cds--table-column-menu"> | ||
<Layer className={styles.layer}> | ||
<OverflowMenu | ||
data-floating-menu-container | ||
ariaLabel="Remove patient form list" | ||
size={desktopLayout ? 'sm' : 'lg'} | ||
flipped> | ||
<OverflowMenuItem | ||
size={desktopLayout ? 'sm' : 'lg'} | ||
className={styles.menuItem} | ||
onClick={handleRemovePatientFromList} | ||
itemText={t('removePatientFromList', 'Remove patient from list')} | ||
delete | ||
/> | ||
</OverflowMenu> | ||
</Layer> | ||
</TableCell> | ||
); | ||
}; | ||
|
||
export default PatientListOverflowMenuComponent; | ||
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
Oops, something went wrong.