feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration - Checkpoint

This commit is contained in:
Dave
2025-10-14 14:26:15 -04:00
parent 5a9381ebdb
commit 6671db1724
4 changed files with 242 additions and 115 deletions

View File

@@ -9,6 +9,7 @@ import { SyncOutlined } from "@ant-design/icons";
import { pageLimit } from "../../utils/config";
import { useSplitTreatments } from "@splitsoftware/splitio-react";
import { useSocket } from "../../contexts/SocketIO/useSocket";
import { determineDmsType } from "../../utils/determineDMSType";
const mapStateToProps = createStructuredSelector({
//currentUser: selectCurrentUser
@@ -33,13 +34,23 @@ export function DmsAllocationsSummary({ socket, bodyshop, jobId, title }) {
});
const { socket: wsssocket } = useSocket();
useEffect(() => {
if (Fortellis.treatment === "on") {
const dms = determineDmsType(bodyshop);
const fetchAllocations = () => {
// ✅ RR takes precedence over Fortellis
if (dms === "rr") {
wsssocket.emit("rr-calculate-allocations", jobId, (ack) => {
setAllocationsSummary(ack);
socket.allocationsSummary = ack;
});
} else if (Fortellis.treatment === "on") {
// Fortellis path (unchanged)
wsssocket.emit("fortellis-calculate-allocations", jobId, (ack) => {
setAllocationsSummary(ack);
socket.allocationsSummary = ack;
});
} else {
// Default to CDK path
if (socket.connected) {
socket.emit("cdk-calculate-allocations", jobId, (ack) => {
setAllocationsSummary(ack);
@@ -47,7 +58,11 @@ export function DmsAllocationsSummary({ socket, bodyshop, jobId, title }) {
});
}
}
}, [socket, socket.connected, jobId]);
};
useEffect(() => {
fetchAllocations();
}, [socket, socket.connected, jobId, dms, Fortellis?.treatment]);
const columns = [
{
@@ -91,15 +106,7 @@ export function DmsAllocationsSummary({ socket, bodyshop, jobId, title }) {
<Card
title={title}
extra={
<Button
onClick={() => {
if (Fortellis.treatment === "on") {
socket.emit("fortellis-calculate-allocations", jobId, (ack) => setAllocationsSummary(ack));
} else {
socket.emit("cdk-calculate-allocations", jobId, (ack) => setAllocationsSummary(ack));
}
}}
>
<Button onClick={fetchAllocations}>
<SyncOutlined />
</Button>
}

View File

@@ -8,13 +8,12 @@ import { useSocket } from "../../contexts/SocketIO/useSocket";
import { socket } from "../../pages/dms/dms.container";
import { selectBodyshop } from "../../redux/user/user.selectors";
import { alphaSort } from "../../utils/sorters";
import { determineDmsType } from "../../utils/determineDMSType";
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop
});
const mapDispatchToProps = () => ({
//setUserLanguage: language => dispatch(setUserLanguage(language))
});
const mapDispatchToProps = () => ({});
export default connect(mapStateToProps, mapDispatchToProps)(DmsCustomerSelector);
export function DmsCustomerSelector({ bodyshop, jobid }) {
@@ -34,27 +33,43 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
const { socket: wsssocket } = useSocket();
const dms = determineDmsType(bodyshop);
const bodyshopId = bodyshop?.id || bodyshop?.bodyshopid || bodyshop?.uuid;
useEffect(() => {
// ✅ RR takes precedence over Fortellis
if (dms === "rr") {
const handleRrSelectCustomer = (list) => {
setOpen(true);
setDmsType("rr");
setcustomerList(Array.isArray(list) ? list : []);
};
wsssocket.on("rr-select-customer", handleRrSelectCustomer);
return () => {
wsssocket.off("rr-select-customer", handleRrSelectCustomer);
};
}
if (Fortellis.treatment === "on") {
const handleFortellisSelectCustomer = (customerList) => {
const handleFortellisSelectCustomer = (list) => {
setOpen(true);
setDmsType("cdk");
setcustomerList(customerList);
setcustomerList(Array.isArray(list) ? list : []);
};
wsssocket.on("fortellis-select-customer", handleFortellisSelectCustomer);
return () => {
wsssocket.off("fortellis-select-customer", handleFortellisSelectCustomer);
};
} else {
const handleCdkSelectCustomer = (customerList) => {
const handleCdkSelectCustomer = (list) => {
setOpen(true);
setDmsType("cdk");
setcustomerList(customerList);
setcustomerList(Array.isArray(list) ? list : []);
};
const handlePbsSelectCustomer = (customerList) => {
const handlePbsSelectCustomer = (list) => {
setOpen(true);
setDmsType("pbs");
setcustomerList(customerList);
setcustomerList(Array.isArray(list) ? list : []);
};
socket.on("cdk-select-customer", handleCdkSelectCustomer);
socket.on("pbs-select-customer", handlePbsSelectCustomer);
@@ -63,12 +78,14 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
socket.off("pbs-select-customer", handlePbsSelectCustomer);
};
}
}, []);
}, [dms, Fortellis?.treatment, wsssocket]);
const onUseSelected = () => {
setOpen(false);
if (Fortellis.treatment === "on") {
wsssocket.emit(`fortellis-selected-customer`, { selectedCustomerId: selectedCustomer, jobid });
if (dmsType === "rr") {
wsssocket.emit("rr-selected-customer", { bodyshopId, selectedCustomerId: selectedCustomer, jobid });
} else if (Fortellis.treatment === "on") {
wsssocket.emit("fortellis-selected-customer", { selectedCustomerId: selectedCustomer, jobid });
} else {
socket.emit(`${dmsType}-selected-customer`, selectedCustomer);
}
@@ -77,23 +94,24 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
const onUseGeneric = () => {
setOpen(false);
const generic = bodyshop.cdk_configuration?.generic_customer_number || null;
if (Fortellis.treatment === "on") {
wsssocket.emit(`fortellis-selected-customer`, {
selectedCustomerId: bodyshop.cdk_configuration.generic_customer_number,
jobid
});
if (dmsType === "rr") {
wsssocket.emit("rr-selected-customer", { bodyshopId, selectedCustomerId: generic, jobid });
} else if (Fortellis.treatment === "on") {
wsssocket.emit("fortellis-selected-customer", { selectedCustomerId: generic, jobid });
} else {
socket.emit(`${dmsType}-selected-customer`, bodyshop.cdk_configuration.generic_customer_number);
socket.emit(`${dmsType}-selected-customer`, generic);
}
setSelectedCustomer(null);
};
const onCreateNew = () => {
setOpen(false);
if (Fortellis.treatment === "on") {
wsssocket.emit(`fortellis-selected-customer`, { selectedCustomerId: null, jobid });
if (dmsType === "rr") {
wsssocket.emit("rr-selected-customer", { bodyshopId, selectedCustomerId: null, jobid });
} else if (Fortellis.treatment === "on") {
wsssocket.emit("fortellis-selected-customer", { selectedCustomerId: null, jobid });
} else {
socket.emit(`${dmsType}-selected-customer`, null);
}
@@ -126,13 +144,13 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
},
{
title: t("jobs.fields.dms.address"),
key: "address",
render: (record) =>
`${record.postalAddress?.addressLine1} ${record.postalAddress?.addressLine2 ? `, ${record.postalAddress?.addressLine2}` : ""},
${record.postalAddress?.city} ${record.postalAddress?.state} ${record.postalAddress?.postalCode} ${
record.postalAddress?.country
}`
`${record.postalAddress?.addressLine1 || ""}${
record.postalAddress?.addressLine2 ? `, ${record.postalAddress.addressLine2}` : ""
}, ${record.postalAddress?.city || ""} ${record.postalAddress?.state || ""} ${
record.postalAddress?.postalCode || ""
} ${record.postalAddress?.country || ""}`
}
];
@@ -154,10 +172,8 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
key: "name1",
sorter: (a, b) => alphaSort(a.name1?.fullName, b.name1?.fullName)
},
{
title: t("jobs.fields.dms.address"),
//dataIndex: ["name2", "fullName"],
key: "address",
render: (record) =>
`${record.address?.addressLine && record.address.addressLine[0]}, ${record.address?.city} ${
@@ -178,7 +194,6 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
sorter: (a, b) => alphaSort(a.LastName, b.LastName),
render: (text, record) => `${record.FirstName || ""} ${record.LastName || ""}`
},
{
title: t("jobs.fields.dms.address"),
key: "address",
@@ -186,7 +201,57 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
}
];
// NEW: RR columns (aligned with RR CombinedSearch-style payloads; falls back gracefully)
const rrColumns = [
{
title: t("jobs.fields.dms.id"),
dataIndex: "CustomerId",
key: "CustomerId"
},
{
title: t("jobs.fields.dms.name1"),
key: "CustomerName",
sorter: (a, b) =>
alphaSort(
(a.CustomerName?.FirstName || "") + " " + (a.CustomerName?.LastName || ""),
(b.CustomerName?.FirstName || "") + " " + (b.CustomerName?.LastName || "")
),
render: (record) => `${record.CustomerName?.FirstName || ""} ${record.CustomerName?.LastName || ""}`.trim()
},
{
title: t("jobs.fields.dms.address"),
key: "Address",
render: (record) => {
const a = record.PostalAddress || record.Address || {};
const l1 = a.AddressLine1 || a.Line1 || "";
const l2 = a.AddressLine2 || a.Line2 || "";
const city = a.City || "";
const st = a.State || a.StateProvince || "";
const pc = a.PostalCode || "";
const ctry = a.Country || "";
return `${l1}${l2 ? `, ${l2}` : ""}, ${city} ${st} ${pc} ${ctry}`.trim();
}
}
];
if (!open) return null;
const columns =
dmsType === "rr"
? rrColumns
: dmsType === "cdk"
? Fortellis.treatment === "on"
? fortellisColumns
: cdkColumns
: pbsColumns;
const rowKeyFn =
dmsType === "rr"
? (record) => record.CustomerId || record.customerId
: dmsType === "cdk"
? (record) => record.id?.value || record.customerId
: (record) => record.ContactId;
return (
<Col span={24}>
<Table
@@ -202,13 +267,18 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
</div>
)}
pagination={{ position: "top" }}
columns={dmsType === "cdk" ? (Fortellis.treatment === "on" ? fortellisColumns : cdkColumns) : pbsColumns}
rowKey={(record) => (dmsType === "cdk" ? record.id?.value || record.customerId : record.ContactId)}
columns={columns}
rowKey={rowKeyFn}
dataSource={customerList}
//onChange={handleTableChange}
rowSelection={{
onSelect: (record) => {
setSelectedCustomer(dmsType === "cdk" ? record.id?.value || record.customerId : record.ContactId);
const key =
dmsType === "rr"
? record.CustomerId || record.customerId
: dmsType === "cdk"
? record.id?.value || record.customerId
: record.ContactId;
setSelectedCustomer(key);
},
type: "radio",
selectedRowKeys: [selectedCustomer]

View File

@@ -62,35 +62,45 @@ export function DmsPostForm({ bodyshop, socket, job, logsRef }) {
return {
...cdkPayer,
dms_acctnumber: cdkPayer.dms_acctnumber,
controlnumber: job && job[cdkPayer.control_type]
controlnumber: job?.[cdkPayer.control_type]
};
})
});
};
const handleFinish = (values) => {
//TODO: Add this as a split instead.
if (Fortellis.treatment === "on") {
wsssocket.emit("fortellis-export-job", {
jobid: job.id,
txEnvelope: {
...values,
SubscriptionID: bodyshop.cdk_dealerid
}
});
} else {
socket.emit(`${determineDmsType(bodyshop)}-export-job`, {
const dms = determineDmsType(bodyshop);
// 1) RR takes precedence regardless of Fortellis split
if (dms === "rr") {
wsssocket.emit("rr-export-job", {
bodyshopId: bodyshop?.id || bodyshop?.bodyshopid || bodyshop?.uuid,
jobid: job.id,
job,
txEnvelope: values
});
}
console.log(logsRef);
if (logsRef) {
console.log("executing", logsRef);
logsRef.curent &&
logsRef.current.scrollIntoView({
behavior: "smooth"
} else {
// 2) Fallback to existing behavior
// TODO: Add this as a split instead.
if (Fortellis.treatment === "on") {
wsssocket.emit("fortellis-export-job", {
jobid: job.id,
txEnvelope: {
...values,
SubscriptionID: bodyshop.cdk_dealerid
}
});
} else {
socket.emit(`${dms}-export-job`, {
jobid: job.id,
txEnvelope: values
});
}
}
// Keep existing auto-scroll-to-logs behavior (fixing "curent" typo)
if (logsRef?.current) {
logsRef.current.scrollIntoView({ behavior: "smooth" });
}
};