Skip to content

Commit

Permalink
CM-949: added logic to resolve deduplication payment (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
sniedzielski authored Jul 4, 2024
1 parent 292feb4 commit 9972e10
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
35 changes: 27 additions & 8 deletions src/components/tables/BenefitPaymentDuplicatesTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,37 @@ const useStyles = makeStyles((theme) => ({
}));

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

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

const handleCheckboxChange = (rowIndex) => {
const newSelectedRows = [...selectedRows];
const index = newSelectedRows.indexOf(rowIndex);
if (index !== -1) {
newSelectedRows.splice(index, 1);
} else {
newSelectedRows.push(rowIndex);
}
if (newSelectedRows.length < rows.length) {
setSelectedRows(newSelectedRows);
const benefitIds = newSelectedRows.map((idx) => rows[idx].benefitId);
const additionalDataString = `{\\"benefitIds\\": ${JSON.stringify(benefitIds).replace(/"/g, '\\"')}}`;
// eslint-disable-next-line object-shorthand
setAdditionalData(additionalDataString);
}
};

const shouldDisableCell = (rowIndex) => selectedRows.includes(rowIndex);

return (
<div className={classes.tableContainer}>
Expand All @@ -61,7 +79,7 @@ function BenefitPaymentDuplicatesTable({
<TableHead className={classes.header}>
<TableRow className={classes.header}>
<TableCell key="checkbox-header-merge" className={classes.checkboxCell}>
<FormattedMessage module="deduplication" id="BeneficiaryDuplicatesTable.merge.header" />
<FormattedMessage module="paymentCycle" id="PaymentDuplicatesTable.merge.header" />
</TableCell>
{headers.map((header, index) => (
<TableCell key={index}>{header}</TableCell>
Expand All @@ -77,8 +95,9 @@ function BenefitPaymentDuplicatesTable({
<TableCell key={`checkbox-cell-${rowIndex}`} className={classes.checkboxCell}>
<Checkbox
color="primary"
onChange={() => {}}
disabled={shouldDisableCell(rowIndex)}
checked={selectedRows.includes(rowIndex)}
onChange={() => handleCheckboxChange(rowIndex)}
disabled={selectedRows.length === rows.length - 1 && !selectedRows.includes(rowIndex)}
/>
</TableCell>
{headers.map((header, headerIndex) => (
Expand Down
3 changes: 2 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@
"paymentCycle.deduplicate.fields": "Duplicate Detection Field Selection",
"paymentCycle.deduplicate.fields.placeholder": "Duplicate Detection Field Selection",
"paymentCycle.button.showDuplicateSummary": "Show Duplicate Summary",
"paymentCycle.tasks.deduplication.title": "Payment Deduplication Task"
"paymentCycle.tasks.deduplication.title": "Payment Deduplication Task",
"paymentCycle.PaymentDuplicatesTable.merge.header": "Remove payment"
}

0 comments on commit 9972e10

Please sign in to comment.