Skip to content

Commit

Permalink
CM-737: merge with develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan committed Mar 6, 2024
2 parents 6dfa0e7 + a41cd8c commit 63879de
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 7 deletions.
23 changes: 20 additions & 3 deletions src/components/IndividualSearcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -69,6 +70,9 @@ function IndividualSearcher({
fieldsFromBfSchema,
fetchingFieldsFromBfSchema,
fetchedFieldsFromBfSchema,
isModalEnrollment,
advancedCriteria,
benefitPlanToEnroll,
}) {
const dispatch = useDispatch();
const [individualToDelete, setIndividualToDelete] = useState(null);
Expand Down Expand Up @@ -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) => (
<Tooltip title={formatMessage(intl, 'individual', 'editButtonTooltip')}>
<IconButton
Expand All @@ -185,7 +189,7 @@ function IndividualSearcher({
</Tooltip>
));
}
if (rights.includes(RIGHT_INDIVIDUAL_DELETE)) {
if (rights.includes(RIGHT_INDIVIDUAL_DELETE) && isModalEnrollment === false) {
formatters.push((individual) => (
<Tooltip title={formatMessage(intl, 'individual', 'deleteButtonTooltip')}>
<IconButton
Expand Down Expand Up @@ -236,6 +240,16 @@ function IndividualSearcher({
filter: `groupId: "${groupId}"`,
};
}
if (isModalEnrollment && advancedCriteria !== null && advancedCriteria !== undefined) {
filters.customFilters = {
value: advancedCriteria,
filter: `customFilters: [${advancedCriteria}]`,
};
filters.benefitPlanToEnroll = {
value: benefitPlanToEnroll,
filter: `benefitPlanToEnroll: "${decodeId(benefitPlanToEnroll)}"`,
};
}
return filters;
};

Expand Down Expand Up @@ -285,7 +299,10 @@ function IndividualSearcher({
chooseExportableColumns
cacheFiltersKey="individualsFilterCache"
resetFiltersOnUnmount
actionsContributionKey={INDIVIDUALS_UPLOAD_FORM_CONTRIBUTION_KEY}
// eslint-disable-next-line react/jsx-props-no-spreading, max-len
{...(isModalEnrollment === false ? {
actionsContributionKey: INDIVIDUALS_UPLOAD_FORM_CONTRIBUTION_KEY, isCustomFiltering: true,
} : { isCustomFiltering: false })}
/>
{failedExport && (
<Dialog fullWidth maxWidth="sm">
Expand Down
17 changes: 15 additions & 2 deletions src/components/dialogs/AdvancedCriteriaForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -48,13 +49,15 @@ function AdvancedCriteriaForm({
confirmed,
clearConfirm,
coreConfirm,
rights,
edited,
}) {
// 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 getBenefitPlanDefaultCriteria = () => {
const { jsonExt } = edited?.benefitPlan ?? {};
Expand Down Expand Up @@ -136,6 +139,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)}"`,
Expand Down Expand Up @@ -189,6 +193,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)}"`,
Expand Down Expand Up @@ -344,18 +349,26 @@ function AdvancedCriteriaForm({
</Paper>
</Grid>
</Grid>
<Grid container spacing={4}>
<Grid container spacing={3}>
<Grid item xs={5} />
<Grid item xs={5}>
<Button
onClick={() => openConfirmEnrollmentDialog()}
variant="contained"
color="primary"
autoFocus
disabled={!object || confirmed}
disabled={!object || confirmed || enrollmentSummary.numberOfIndividualsToUpload === '0'}
>
{formatMessage(intl, 'individual', 'individual.enrollment.confirmEnrollment')}
</Button>
<IndividualPreviewEnrollmentDialog
rights={rights}
classes={classes}
advancedCriteria={filtersToApply}
benefitPlanToEnroll={object.id}
enrollmentSummary={enrollmentSummary}
confirmed={confirmed}
/>
</Grid>
<Grid item xs={5} />
</Grid>
Expand Down
123 changes: 123 additions & 0 deletions src/components/dialogs/IndividualPreviewEnrollmentDialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/* 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,
enrollmentSummary,
confirmed,
}) {
const [isOpen, setIsOpen] = useState(false);

const handleOpen = () => {
setIsOpen(true);
};

const handleClose = () => {
setIsOpen(false);
};

const modulesManager = useModulesManager();
const { formatMessage } = useTranslations(INDIVIDUAL_MODULE_NAME, modulesManager);

return (
<>
<Button
onClick={handleOpen}
variant="contained"
color="primary"
className={classes.button}
style={{ marginLeft: '16px' }}
disabled={enrollmentSummary?.numberOfIndividualsToUpload === '0' || confirmed}
>
{formatMessage('individual.enrollment.previewIndividuals')}
</Button>
<Dialog
open={isOpen}
onClose={handleClose}
PaperProps={{
style: {
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%,-50%)',
width: '75%',
maxWidth: '75%',
},
}}
>
<DialogTitle
style={{
marginTop: '10px',
}}
>
{formatMessage('individual.enrollment.previewIndividuals')}
</DialogTitle>
<DialogContent>
<div
style={{ backgroundColor: '#DFEDEF' }}
>
<IndividualSearcher
rights={rights}
isModalEnrollment
advancedCriteria={advancedCriteria}
benefitPlanToEnroll={benefitPlanToEnroll}
/>
</div>
</DialogContent>
<DialogActions
style={{
display: 'inline',
paddingLeft: '10px',
marginTop: '25px',
marginBottom: '15px',
width: '100%',
}}
>
<div style={{ maxWidth: '3000px' }}>
<div style={{ float: 'left' }} />
<div style={{
float: 'right',
paddingRight: '16px',
}}
>
<Button
onClick={handleClose}
variant="outlined"
autoFocus
style={{ margin: '0 16px' }}
>
{formatMessage('individual.enrollment.close')}
</Button>
</div>
</div>
</DialogActions>
</Dialog>
</>
);
}

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);
2 changes: 1 addition & 1 deletion src/pages/IndividualsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function IndividualsPage(props) {
rights.includes(RIGHT_INDIVIDUAL_SEARCH) && (
<div className={classes.page}>
<Helmet title={formatMessage(intl, 'individual', 'individuals.pageTitle')} />
<IndividualSearcher rights={rights} />
<IndividualSearcher rights={rights} isModalEnrollment={false} />
</div>
)
);
Expand Down
4 changes: 3 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 63879de

Please sign in to comment.