feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration - Fixes to Caching of allocations summary

This commit is contained in:
Dave
2025-11-28 11:29:48 -05:00
parent d885bac7d0
commit c1e3c08652
6 changed files with 93 additions and 31 deletions

View File

@@ -39,10 +39,11 @@ import { useSplitTreatments } from "@splitsoftware/splitio-react";
* @param job
* @param logsRef
* @param mode
* @param allocationsSummary
* @returns {JSX.Element}
* @constructor
*/
export default function CdkLikePostForm({ bodyshop, socket, job, logsRef, mode }) {
export default function CdkLikePostForm({ bodyshop, socket, job, logsRef, mode, allocationsSummary }) {
const [form] = Form.useForm();
const { t } = useTranslation();
const [, /*unused*/ setTick] = useState(0); // handy if you need a forceUpdate later
@@ -120,15 +121,19 @@ export default function CdkLikePostForm({ bodyshop, socket, job, logsRef, mode }
};
// Totals & discrepancy
const totals = socket?.allocationsSummary
? socket.allocationsSummary.reduce(
(acc, val) => ({
totalSale: acc.totalSale.add(Dinero(val.sale)),
totalCost: acc.totalCost.add(Dinero(val.cost))
}),
{ totalSale: Dinero(), totalCost: Dinero() }
)
: { totalSale: Dinero(), totalCost: Dinero() };
const totals = useMemo(() => {
if (!allocationsSummary || allocationsSummary.length === 0) {
return { totalSale: Dinero(), totalCost: Dinero() };
}
return allocationsSummary.reduce(
(acc, val) => ({
totalSale: acc.totalSale.add(Dinero(val.sale)),
totalCost: acc.totalCost.add(Dinero(val.cost))
}),
{ totalSale: Dinero(), totalCost: Dinero() }
);
}, [allocationsSummary]);
return (
<Card title={t("jobs.labels.dms.postingform")}>
@@ -214,7 +219,7 @@ export default function CdkLikePostForm({ bodyshop, socket, job, logsRef, mode }
<Row gutter={[16, 12]}>
<Col span={24}>
<Form.Item name="story" label={t("jobs.fields.dms.story")} rules={[{ required: true }]}>
<Input.TextArea maxLength={Fortellis.treatment === "on" ? 40 : 240} showCount/>
<Input.TextArea maxLength={Fortellis.treatment === "on" ? 40 : 240} showCount />
</Form.Item>
</Col>
</Row>
@@ -382,7 +387,10 @@ export default function CdkLikePostForm({ bodyshop, socket, job, logsRef, mode }
const payersOk =
payers.length > 0 &&
payers.every((p) => p?.name && p.dms_acctnumber && (p.amount ?? "") !== "" && p.controlnumber);
const nonRrDiscrepancyGate = socket?.allocationsSummary ? discrep.getAmount() !== 0 : true;
const hasAllocations = allocationsSummary && allocationsSummary.length > 0;
const nonRrDiscrepancyGate = hasAllocations ? discrep.getAmount() !== 0 : true;
const disablePost = !payersOk || nonRrDiscrepancyGate;
return (