Skip to content

Commit

Permalink
CM-947: added possibility to create review task for payment deduplica…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
sniedzielski committed Jul 3, 2024
1 parent 1158ae3 commit f26661a
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 1 deletion.
36 changes: 36 additions & 0 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,39 @@ export function codeValidationClear() {
dispatch({ type: CLEAR(ACTION_TYPE.PAYMENT_CYCLE_CODE_VALIDATION_FIELDS) });
};
}

function formatDeduplicationTasksMutation(summary) {
if (!summary || !Array.isArray(summary)) {
return '';
}

const formattedSummary = summary.map((item) => {
const keyValuePairs = Object.entries(item)
.map(([key, value]) => `${key}: ${JSON.stringify(value)}`)
.join(', ');

return `{ ${keyValuePairs} }`;
});

return `summary: [${formattedSummary.join(', ')}]`;
}

export function createDeduplicationTasks(summary, clientMutationLabel) {
const mutation = formatMutation(
'createDeduplicationPaymentTasks',
formatDeduplicationTasksMutation(summary),
clientMutationLabel,
);
const requestedDateTime = new Date();
return graphql(
mutation.payload,
// eslint-disable-next-line max-len
[REQUEST(ACTION_TYPE.MUTATION), SUCCESS(ACTION_TYPE.CREATE_PAYMENT_DEDUPLICATION_TASKS), ERROR(ACTION_TYPE.MUTATION)],
{
actionType: ACTION_TYPE.CREATE_PAYMENT_DEDUPLICATION_TASKS,
clientMutationId: mutation.clientMutationId,
clientMutationLabel,
requestedDateTime,
},
);
}
3 changes: 2 additions & 1 deletion src/components/dialogs/DeduplicationSummaryDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { withTheme, withStyles } from '@material-ui/core/styles';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import DeduplicationSummaryTable from '../tables/DeduplicationSummaryTable';
import { fetchDeduplicationSummary } from '../../actions';
import { createDeduplicationTasks, fetchDeduplicationSummary } from '../../actions';

const styles = (theme) => ({
item: theme.paper.item,
Expand Down Expand Up @@ -110,6 +110,7 @@ const mapStateToProps = (state) => ({
});

const mapDispatchToProps = (dispatch) => bindActionCreators({
createDeduplicationTasks,
}, dispatch);

export default injectIntl(
Expand Down
124 changes: 124 additions & 0 deletions src/components/tables/BenefitPaymentDuplicatesTable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/* eslint-disable react/no-array-index-key */
import React, { useState, useEffect } from 'react';
import {
makeStyles, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Checkbox,
} from '@material-ui/core';
import {
FormattedMessage,
} from '@openimis/fe-core';

const useStyles = makeStyles((theme) => ({
paper: theme.paper.paper,
table: theme.table,
tableTitle: theme.table.title,
tableHeader: theme.table.header,
tableRow: theme.table.row,
title: theme.paper.title,
tableDisabledRow: theme.table.disabledRow,
tableDisabledCell: theme.table.disabledCell,
tableContainer: {
overflow: 'auto',
},
hoverableCell: {
'&:hover': {
backgroundColor: '#f0f0f0',
},
cursor: 'pointer',
},
selectedCell: {
backgroundColor: '#a1caf1',
},
checkboxCell: {
textAlign: 'center',
},
deactivatedRow: {
opacity: 0.5,
},
strikethrough: {
textDecoration: 'line-through',
},
}));

function BenefitPaymentDuplicatesTable({
headers, rows, completedData,
}) {
const classes = useStyles();
const [dontMergeRows, setDontMergeRows] = useState([]);
const shouldDisableCell = (rowIndex) => dontMergeRows.includes(rowIndex);
const shouldCrossText = (rowIndex) => rows[rowIndex]?.is_deleted;

useEffect(() => {
if (completedData) {
const numberOfRows = Array.from(Array(rows.length).keys());
setDontMergeRows(numberOfRows);
}
}, [completedData]);

return (
<div className={classes.tableContainer}>
<TableContainer className={classes.paper}>
<Table size="small" className={classes.table} aria-label="dynamic table">
<TableHead className={classes.header}>
<TableRow className={classes.header}>
<TableCell key="checkbox-header-merge" className={classes.checkboxCell}>
<FormattedMessage module="deduplication" id="BeneficiaryDuplicatesTable.merge.header" />
</TableCell>
<TableCell key="checkbox-header" className={classes.checkboxCell}>
<FormattedMessage module="deduplication" id="BeneficiaryDuplicatesTable.checkbox.header" />
</TableCell>
{headers.map((header, index) => (
<TableCell key={index}>{header}</TableCell>
))}
</TableRow>
</TableHead>
<TableBody>
{rows.map((row, rowIndex) => (
<TableRow
key={rowIndex}
className={classes.tableRow}
>
<TableCell key={`checkbox-cell-${rowIndex}`} className={classes.checkboxCell}>
<Checkbox
color="primary"
onChange={() => {}}
disabled={shouldDisableCell(rowIndex)}
/>
</TableCell>
{headers.map((header, headerIndex) => (
<TableCell
key={headerIndex}
className={`}
${shouldDisableCell(rowIndex) ? classes.tableDisabledCell : ''}
${shouldCrossText(rowIndex) ? classes.strikethrough : ''}
`}
>
{row[header]}
</TableCell>
))}
</TableRow>
))}
<TableRow
className={classes.tableRow}
>
<TableCell className={classes.checkboxCell} />
<TableCell className={classes.checkboxCell}>
<FormattedMessage module="deduplication" id="BeneficiaryDuplicatesTable.output" />
</TableCell>
{headers.map((header, headerIndex) => (
<TableCell
key={headerIndex}
className={`${classes.tableDisabledCell}
${completedData ? classes.selectedCell : ''}`}
>
{rows[0][header]}
</TableCell>
))}
</TableRow>
</TableBody>
</Table>
</TableContainer>
</div>
);
}

export default BenefitPaymentDuplicatesTable;
79 changes: 79 additions & 0 deletions src/components/tasks/DeduplicationPaymentResolutionTask.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import React from 'react';
import { Typography, makeStyles } from '@material-ui/core';
import BenefitPaymentDuplicatesTable from '../tables/BenefitPaymentDuplicatesTable';

const useStyles = makeStyles((theme) => ({
paper: theme.paper.paper,
title: theme.paper.title,
}));

function DeduplicationPaymentResolutionTaskDisplay({
businessData, setAdditionalData, jsonExt,
}) {
if (!businessData) return null;

const classes = useStyles();
const completedData = jsonExt?.additional_resolve_data
? Object.values(jsonExt.additional_resolve_data)[0].values
: null;
const benefits = (businessData?.ids || []).map((id) => {
const {
// eslint-disable-next-line camelcase
individual, json_ext, uuid, ...rest
} = id;
return {
...rest,
...individual,
// eslint-disable-next-line camelcase
...json_ext,
individual: individual.uuid,
benefitId: uuid,
};
});

const headers = businessData?.headers || [];
const individualIndex = headers.indexOf('individual');

if (individualIndex !== -1) {
headers.splice(individualIndex, 1);
headers.unshift('individual');
}

benefits.sort((a, b) => new Date(a.date_created) - new Date(b.date_created));

return (
<div>
<Typography className={classes.title} style={{ textAlign: 'center' }}>
{JSON.stringify(businessData?.column_values)}
{' '}
,
count:
{' '}
{businessData?.count}
</Typography>
<div>
<BenefitPaymentDuplicatesTable
headers={headers}
rows={benefits}
setAdditionalData={setAdditionalData}
completedData={completedData}
/>

</div>
</div>
);
}

const DeduplicationPaymentResolutionTaskTableHeaders = () => [];

const DeduplicationPaymentResolutionItemFormatters = () => [
(businessData, jsonExt, formatterIndex, setAdditionalData) => (
<DeduplicationPaymentResolutionTaskDisplay
businessData={businessData}
setAdditionalData={setAdditionalData}
jsonExt={jsonExt}
/>
),
];

export { DeduplicationPaymentResolutionTaskTableHeaders, DeduplicationPaymentResolutionItemFormatters };
10 changes: 10 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import { PaymentCycleTaskItemFormatters, PaymentCycleTaskTableHeaders } from './
import { PaymentCycleTaskTabLabel, PaymentCycleTaskTabPanel } from './components/PaymentCycleTaskTabPanel';
import { PaymentCycleBenefitsTabLabel, PaymentCycleBenefitsTabPanel } from './components/PaymentCycleBenefitsTabPanel';
import DeduplicationFieldSelectionDialog from './components/dialogs/DeduplicationFieldSelectionDialog';
import {
DeduplicationPaymentResolutionItemFormatters,
DeduplicationPaymentResolutionTaskTableHeaders,
} from './components/tasks/DeduplicationPaymentResolutionTask';

const ROUTE_PAYMENT_CYCLES = 'paymentCycles';
const ROUTE_PAYMENT_CYCLE = 'paymentCycles/paymentCycle';
Expand Down Expand Up @@ -50,6 +54,12 @@ const DEFAULT_CONFIG = {
tableHeaders: PaymentCycleTaskTableHeaders,
itemFormatters: PaymentCycleTaskItemFormatters,
taskSource: ['PaymentCycleService'],
},
{
text: <FormattedMessage module="deduplication" id="tasks.deduplication.title" />,
tableHeaders: DeduplicationPaymentResolutionTaskTableHeaders,
itemFormatters: DeduplicationPaymentResolutionItemFormatters,
taskSource: ['CreateDeduplicationPaymentReviewTasksService'],
}],
};

Expand Down
3 changes: 3 additions & 0 deletions src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const ACTION_TYPE = {
PAYMENT_CYCLE_CODE_VALIDATION_FIELDS: 'PAYMENT_CYCLE_CODE_VALIDATION_FIELDS',
GET_DEDUPLICATION_BENEFIT_SUMMARY: 'PAYMENT_CYCLE_DEDUPLICATION_BENEFIT_SUMMARY',
FETCH_GLOBAL_SCHEMA: 'PAYMENT_CYCLE_GLOBAL_SCHEMA',
CREATE_PAYMENT_DEDUPLICATION_TASKS: 'PAYMENT_CYCLE_PAYMENT_DEDUPLICATION_TASKS',
};

export const MUTATION_SERVICE = {
Expand Down Expand Up @@ -293,6 +294,8 @@ function reducer(
return dispatchMutationResp(state, MUTATION_SERVICE.PAYMENT_CYCLE.CREATE, action);
case SUCCESS(ACTION_TYPE.UPDATE_PAYMENT_CYCLE):
return dispatchMutationResp(state, MUTATION_SERVICE.PAYMENT_CYCLE.UPDATE, action);
case SUCCESS(ACTION_TYPE.CREATE_PAYMENT_DEDUPLICATION_TASKS):
return dispatchMutationResp(state, 'createPaymentDeduplicationTasks', action);
case ERROR(ACTION_TYPE.MUTATION):
return dispatchMutationErr(state, action);
default:
Expand Down

0 comments on commit f26661a

Please sign in to comment.