From 8c0ba304a502f94ad9f9c2da5311bcafcb46cb98 Mon Sep 17 00:00:00 2001 From: sniedzielski Date: Mon, 4 Mar 2024 13:48:26 +0100 Subject: [PATCH] CM-738: added possibility to preview individual --- src/components/IndividualSearcher.js | 23 +++- .../dialogs/AdvancedCriteriaForm.js | 13 +- .../IndividualPreviewEnrollmentDialog.js | 120 ++++++++++++++++++ src/pages/IndividualsPage.js | 2 +- src/translations/en.json | 4 +- 5 files changed, 156 insertions(+), 6 deletions(-) create mode 100644 src/components/dialogs/IndividualPreviewEnrollmentDialog.js diff --git a/src/components/IndividualSearcher.js b/src/components/IndividualSearcher.js index d3ec6b7..76f15df 100644 --- a/src/components/IndividualSearcher.js +++ b/src/components/IndividualSearcher.js @@ -13,6 +13,7 @@ import { historyPush, downloadExport, CLEARED_STATE_FILTER, + decodeId, } from '@openimis/fe-core'; import { bindActionCreators } from 'redux'; import { connect, useDispatch } from 'react-redux'; @@ -69,6 +70,9 @@ function IndividualSearcher({ fieldsFromBfSchema, fetchingFieldsFromBfSchema, fetchedFieldsFromBfSchema, + isModalEnrollment, + advancedCriteria, + benefitPlanToEnroll, }) { const dispatch = useDispatch(); const [individualToDelete, setIndividualToDelete] = useState(null); @@ -172,7 +176,7 @@ function IndividualSearcher({ (individual) => individual.lastName, (individual) => (individual.dob ? formatDateFromISO(modulesManager, intl, individual.dob) : EMPTY_STRING), ]; - if (rights.includes(RIGHT_INDIVIDUAL_UPDATE)) { + if (rights.includes(RIGHT_INDIVIDUAL_UPDATE) && isModalEnrollment === false) { formatters.push((individual) => ( )); } - if (rights.includes(RIGHT_INDIVIDUAL_DELETE)) { + if (rights.includes(RIGHT_INDIVIDUAL_DELETE) && isModalEnrollment === false) { formatters.push((individual) => ( {failedExport && ( diff --git a/src/components/dialogs/AdvancedCriteriaForm.js b/src/components/dialogs/AdvancedCriteriaForm.js index 55a0722..9daba60 100644 --- a/src/components/dialogs/AdvancedCriteriaForm.js +++ b/src/components/dialogs/AdvancedCriteriaForm.js @@ -20,6 +20,7 @@ import AdvancedCriteriaRowValue from './AdvancedCriteriaRowValue'; import { CLEARED_STATE_FILTER, INDIVIDUAL } from '../../constants'; import { isBase64Encoded, isEmptyObject } from '../../utils'; import { confirmEnrollment, fetchIndividualEnrollmentSummary } from '../../actions'; +import IndividualPreviewEnrollmentDialog from './IndividualPreviewEnrollmentDialog'; const styles = (theme) => ({ item: theme.paper.item, @@ -48,12 +49,14 @@ function AdvancedCriteriaForm({ confirmed, clearConfirm, coreConfirm, + rights, }) { // eslint-disable-next-line no-unused-vars const [currentFilter, setCurrentFilter] = useState({ field: '', filter: '', type: '', value: '', amount: '', }); const [filters, setFilters] = useState(getDefaultAppliedCustomFilters()); + const [filtersToApply, setFiltersToApply] = useState(null); const createParams = (moduleName, objectTypeName, uuidOfObject = null, additionalParams = null) => { const params = [ @@ -119,6 +122,7 @@ function AdvancedCriteriaForm({ // Extract custom_filter_condition values and construct customFilters array const customFilters = advancedCriteria.map((criterion) => `"${criterion.custom_filter_condition}"`); + setFiltersToApply(customFilters); const params = [ `customFilters: [${customFilters}]`, `benefitPlanId: "${decodeId(object.id)}"`, @@ -172,6 +176,7 @@ function AdvancedCriteriaForm({ // Extract custom_filter_condition values and construct customFilters array const customFilters = advancedCriteria.map((criterion) => `"${criterion.custom_filter_condition}"`); + setFiltersToApply(customFilters); const params = { customFilters: `[${customFilters}]`, benefitPlanId: `"${decodeId(object.id)}"`, @@ -327,7 +332,7 @@ function AdvancedCriteriaForm({ - + + diff --git a/src/components/dialogs/IndividualPreviewEnrollmentDialog.js b/src/components/dialogs/IndividualPreviewEnrollmentDialog.js new file mode 100644 index 0000000..7b1d483 --- /dev/null +++ b/src/components/dialogs/IndividualPreviewEnrollmentDialog.js @@ -0,0 +1,120 @@ +/* eslint-disable max-len */ +import React, { useState } from 'react'; +import Button from '@material-ui/core/Button'; +import Dialog from '@material-ui/core/Dialog'; +import DialogActions from '@material-ui/core/DialogActions'; +import DialogContent from '@material-ui/core/DialogContent'; +import DialogTitle from '@material-ui/core/DialogTitle'; +import { + useModulesManager, + useTranslations, +} from '@openimis/fe-core'; +import { connect } from 'react-redux'; +import { bindActionCreators } from 'redux'; +import { INDIVIDUAL_MODULE_NAME } from '../../constants'; +import IndividualSearcher from '../IndividualSearcher'; + +function IndividualPreviewEnrollmentDialog({ + classes, + rights, + advancedCriteria, + benefitPlanToEnroll, +}) { + const [isOpen, setIsOpen] = useState(false); + + const handleOpen = () => { + setIsOpen(true); + }; + + const handleClose = () => { + setIsOpen(false); + }; + + const modulesManager = useModulesManager(); + const { formatMessage } = useTranslations(INDIVIDUAL_MODULE_NAME, modulesManager); + + return ( + <> + + + + {formatMessage('individual.enrollment.previewIndividuals')} + + +
+ +
+
+ +
+
+
+ +
+
+ +
+ + ); +} + +const mapStateToProps = (state) => ({ + rights: !!state.core && !!state.core.user && !!state.core.user.i_user ? state.core.user.i_user.rights : [], + confirmed: state.core.confirmed, +}); + +const mapDispatchToProps = (dispatch) => bindActionCreators({ +}, dispatch); + +export default connect(mapStateToProps, mapDispatchToProps)(IndividualPreviewEnrollmentDialog); diff --git a/src/pages/IndividualsPage.js b/src/pages/IndividualsPage.js index 44d93c1..aa6fd8f 100644 --- a/src/pages/IndividualsPage.js +++ b/src/pages/IndividualsPage.js @@ -18,7 +18,7 @@ function IndividualsPage(props) { rights.includes(RIGHT_INDIVIDUAL_SEARCH) && (
- +
) ); diff --git a/src/translations/en.json b/src/translations/en.json index 6cc59c3..96d2106 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -70,7 +70,9 @@ "numberOfIndividualsNotAssignedToProgramme": "Number of Individuals Without Assignment to Program", "numberOfIndividualsAssignedToSelectedProgramme": "Number Of Individuals Already Assigned to Selected Programme", "numberOfIndividualsToBeUploaded": "Number Of Individuals to be Uploaded", - "confirmMessageDialog": "Are you sure you want to confirm the enrollment of the selected individuals into the {benefitPlanName} Programme?" + "confirmMessageDialog": "Are you sure you want to confirm the enrollment of the selected individuals into the {benefitPlanName} Programme?", + "previewIndividuals": "Preview Individuals", + "close": "Close" }, "saveButton.tooltip.enabled": "Save changes", "saveButton.tooltip.disabled": "Please fill General Information fields first",