feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration - Fixes to Caching of allocations summary
This commit is contained in:
@@ -26,10 +26,11 @@ import dayjs from "../../utils/day";
|
||||
* @param socket
|
||||
* @param job
|
||||
* @param logsRef
|
||||
* @param allocationsSummary
|
||||
* @returns {JSX.Element}
|
||||
* @constructor
|
||||
*/
|
||||
export default function RRPostForm({ bodyshop, socket, job, logsRef }) {
|
||||
export default function RRPostForm({ bodyshop, socket, job, logsRef, allocationsSummary }) {
|
||||
const [form] = Form.useForm();
|
||||
const { t } = useTranslation();
|
||||
|
||||
@@ -113,16 +114,21 @@ export default function RRPostForm({ bodyshop, socket, job, logsRef }) {
|
||||
logsRef?.current?.scrollIntoView({ behavior: "smooth" });
|
||||
};
|
||||
|
||||
// Discrepancy is ignored for RR; we still show totals for operator context
|
||||
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() };
|
||||
// Discrepancy is ignored for RR; we still show totals for operator context.
|
||||
// Use the lifted allocationsSummary from the container instead of reading from the socket.
|
||||
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")}>
|
||||
|
||||
Reference in New Issue
Block a user