feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration - Checkpoint
This commit is contained in:
@@ -9,6 +9,7 @@ import { SyncOutlined } from "@ant-design/icons";
|
|||||||
import { pageLimit } from "../../utils/config";
|
import { pageLimit } from "../../utils/config";
|
||||||
import { useSplitTreatments } from "@splitsoftware/splitio-react";
|
import { useSplitTreatments } from "@splitsoftware/splitio-react";
|
||||||
import { useSocket } from "../../contexts/SocketIO/useSocket";
|
import { useSocket } from "../../contexts/SocketIO/useSocket";
|
||||||
|
import { determineDmsType } from "../../utils/determineDMSType";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
//currentUser: selectCurrentUser
|
//currentUser: selectCurrentUser
|
||||||
@@ -33,13 +34,23 @@ export function DmsAllocationsSummary({ socket, bodyshop, jobId, title }) {
|
|||||||
});
|
});
|
||||||
const { socket: wsssocket } = useSocket();
|
const { socket: wsssocket } = useSocket();
|
||||||
|
|
||||||
useEffect(() => {
|
const dms = determineDmsType(bodyshop);
|
||||||
if (Fortellis.treatment === "on") {
|
|
||||||
|
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) => {
|
wsssocket.emit("fortellis-calculate-allocations", jobId, (ack) => {
|
||||||
setAllocationsSummary(ack);
|
setAllocationsSummary(ack);
|
||||||
socket.allocationsSummary = ack;
|
socket.allocationsSummary = ack;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
// Default to CDK path
|
||||||
if (socket.connected) {
|
if (socket.connected) {
|
||||||
socket.emit("cdk-calculate-allocations", jobId, (ack) => {
|
socket.emit("cdk-calculate-allocations", jobId, (ack) => {
|
||||||
setAllocationsSummary(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 = [
|
const columns = [
|
||||||
{
|
{
|
||||||
@@ -91,15 +106,7 @@ export function DmsAllocationsSummary({ socket, bodyshop, jobId, title }) {
|
|||||||
<Card
|
<Card
|
||||||
title={title}
|
title={title}
|
||||||
extra={
|
extra={
|
||||||
<Button
|
<Button onClick={fetchAllocations}>
|
||||||
onClick={() => {
|
|
||||||
if (Fortellis.treatment === "on") {
|
|
||||||
socket.emit("fortellis-calculate-allocations", jobId, (ack) => setAllocationsSummary(ack));
|
|
||||||
} else {
|
|
||||||
socket.emit("cdk-calculate-allocations", jobId, (ack) => setAllocationsSummary(ack));
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<SyncOutlined />
|
<SyncOutlined />
|
||||||
</Button>
|
</Button>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,13 +8,12 @@ import { useSocket } from "../../contexts/SocketIO/useSocket";
|
|||||||
import { socket } from "../../pages/dms/dms.container";
|
import { socket } from "../../pages/dms/dms.container";
|
||||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||||
import { alphaSort } from "../../utils/sorters";
|
import { alphaSort } from "../../utils/sorters";
|
||||||
|
import { determineDmsType } from "../../utils/determineDMSType";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop
|
bodyshop: selectBodyshop
|
||||||
});
|
});
|
||||||
const mapDispatchToProps = () => ({
|
const mapDispatchToProps = () => ({});
|
||||||
//setUserLanguage: language => dispatch(setUserLanguage(language))
|
|
||||||
});
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(DmsCustomerSelector);
|
export default connect(mapStateToProps, mapDispatchToProps)(DmsCustomerSelector);
|
||||||
|
|
||||||
export function DmsCustomerSelector({ bodyshop, jobid }) {
|
export function DmsCustomerSelector({ bodyshop, jobid }) {
|
||||||
@@ -34,27 +33,43 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
|
|||||||
|
|
||||||
const { socket: wsssocket } = useSocket();
|
const { socket: wsssocket } = useSocket();
|
||||||
|
|
||||||
|
const dms = determineDmsType(bodyshop);
|
||||||
|
const bodyshopId = bodyshop?.id || bodyshop?.bodyshopid || bodyshop?.uuid;
|
||||||
|
|
||||||
useEffect(() => {
|
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") {
|
if (Fortellis.treatment === "on") {
|
||||||
const handleFortellisSelectCustomer = (customerList) => {
|
const handleFortellisSelectCustomer = (list) => {
|
||||||
setOpen(true);
|
setOpen(true);
|
||||||
setDmsType("cdk");
|
setDmsType("cdk");
|
||||||
setcustomerList(customerList);
|
setcustomerList(Array.isArray(list) ? list : []);
|
||||||
};
|
};
|
||||||
wsssocket.on("fortellis-select-customer", handleFortellisSelectCustomer);
|
wsssocket.on("fortellis-select-customer", handleFortellisSelectCustomer);
|
||||||
return () => {
|
return () => {
|
||||||
wsssocket.off("fortellis-select-customer", handleFortellisSelectCustomer);
|
wsssocket.off("fortellis-select-customer", handleFortellisSelectCustomer);
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
const handleCdkSelectCustomer = (customerList) => {
|
const handleCdkSelectCustomer = (list) => {
|
||||||
setOpen(true);
|
setOpen(true);
|
||||||
setDmsType("cdk");
|
setDmsType("cdk");
|
||||||
setcustomerList(customerList);
|
setcustomerList(Array.isArray(list) ? list : []);
|
||||||
};
|
};
|
||||||
const handlePbsSelectCustomer = (customerList) => {
|
const handlePbsSelectCustomer = (list) => {
|
||||||
setOpen(true);
|
setOpen(true);
|
||||||
setDmsType("pbs");
|
setDmsType("pbs");
|
||||||
setcustomerList(customerList);
|
setcustomerList(Array.isArray(list) ? list : []);
|
||||||
};
|
};
|
||||||
socket.on("cdk-select-customer", handleCdkSelectCustomer);
|
socket.on("cdk-select-customer", handleCdkSelectCustomer);
|
||||||
socket.on("pbs-select-customer", handlePbsSelectCustomer);
|
socket.on("pbs-select-customer", handlePbsSelectCustomer);
|
||||||
@@ -63,12 +78,14 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
|
|||||||
socket.off("pbs-select-customer", handlePbsSelectCustomer);
|
socket.off("pbs-select-customer", handlePbsSelectCustomer);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}, []);
|
}, [dms, Fortellis?.treatment, wsssocket]);
|
||||||
|
|
||||||
const onUseSelected = () => {
|
const onUseSelected = () => {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
if (Fortellis.treatment === "on") {
|
if (dmsType === "rr") {
|
||||||
wsssocket.emit(`fortellis-selected-customer`, { selectedCustomerId: selectedCustomer, jobid });
|
wsssocket.emit("rr-selected-customer", { bodyshopId, selectedCustomerId: selectedCustomer, jobid });
|
||||||
|
} else if (Fortellis.treatment === "on") {
|
||||||
|
wsssocket.emit("fortellis-selected-customer", { selectedCustomerId: selectedCustomer, jobid });
|
||||||
} else {
|
} else {
|
||||||
socket.emit(`${dmsType}-selected-customer`, selectedCustomer);
|
socket.emit(`${dmsType}-selected-customer`, selectedCustomer);
|
||||||
}
|
}
|
||||||
@@ -77,23 +94,24 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
|
|||||||
|
|
||||||
const onUseGeneric = () => {
|
const onUseGeneric = () => {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
|
const generic = bodyshop.cdk_configuration?.generic_customer_number || null;
|
||||||
|
|
||||||
if (Fortellis.treatment === "on") {
|
if (dmsType === "rr") {
|
||||||
wsssocket.emit(`fortellis-selected-customer`, {
|
wsssocket.emit("rr-selected-customer", { bodyshopId, selectedCustomerId: generic, jobid });
|
||||||
selectedCustomerId: bodyshop.cdk_configuration.generic_customer_number,
|
} else if (Fortellis.treatment === "on") {
|
||||||
jobid
|
wsssocket.emit("fortellis-selected-customer", { selectedCustomerId: generic, jobid });
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
socket.emit(`${dmsType}-selected-customer`, bodyshop.cdk_configuration.generic_customer_number);
|
socket.emit(`${dmsType}-selected-customer`, generic);
|
||||||
}
|
}
|
||||||
setSelectedCustomer(null);
|
setSelectedCustomer(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onCreateNew = () => {
|
const onCreateNew = () => {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
|
if (dmsType === "rr") {
|
||||||
if (Fortellis.treatment === "on") {
|
wsssocket.emit("rr-selected-customer", { bodyshopId, selectedCustomerId: null, jobid });
|
||||||
wsssocket.emit(`fortellis-selected-customer`, { selectedCustomerId: null, jobid });
|
} else if (Fortellis.treatment === "on") {
|
||||||
|
wsssocket.emit("fortellis-selected-customer", { selectedCustomerId: null, jobid });
|
||||||
} else {
|
} else {
|
||||||
socket.emit(`${dmsType}-selected-customer`, null);
|
socket.emit(`${dmsType}-selected-customer`, null);
|
||||||
}
|
}
|
||||||
@@ -126,13 +144,13 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: t("jobs.fields.dms.address"),
|
title: t("jobs.fields.dms.address"),
|
||||||
|
|
||||||
key: "address",
|
key: "address",
|
||||||
render: (record) =>
|
render: (record) =>
|
||||||
`${record.postalAddress?.addressLine1} ${record.postalAddress?.addressLine2 ? `, ${record.postalAddress?.addressLine2}` : ""},
|
`${record.postalAddress?.addressLine1 || ""}${
|
||||||
${record.postalAddress?.city} ${record.postalAddress?.state} ${record.postalAddress?.postalCode} ${
|
record.postalAddress?.addressLine2 ? `, ${record.postalAddress.addressLine2}` : ""
|
||||||
record.postalAddress?.country
|
}, ${record.postalAddress?.city || ""} ${record.postalAddress?.state || ""} ${
|
||||||
}`
|
record.postalAddress?.postalCode || ""
|
||||||
|
} ${record.postalAddress?.country || ""}`
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -154,10 +172,8 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
|
|||||||
key: "name1",
|
key: "name1",
|
||||||
sorter: (a, b) => alphaSort(a.name1?.fullName, b.name1?.fullName)
|
sorter: (a, b) => alphaSort(a.name1?.fullName, b.name1?.fullName)
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
title: t("jobs.fields.dms.address"),
|
title: t("jobs.fields.dms.address"),
|
||||||
//dataIndex: ["name2", "fullName"],
|
|
||||||
key: "address",
|
key: "address",
|
||||||
render: (record) =>
|
render: (record) =>
|
||||||
`${record.address?.addressLine && record.address.addressLine[0]}, ${record.address?.city} ${
|
`${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),
|
sorter: (a, b) => alphaSort(a.LastName, b.LastName),
|
||||||
render: (text, record) => `${record.FirstName || ""} ${record.LastName || ""}`
|
render: (text, record) => `${record.FirstName || ""} ${record.LastName || ""}`
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
title: t("jobs.fields.dms.address"),
|
title: t("jobs.fields.dms.address"),
|
||||||
key: "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;
|
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 (
|
return (
|
||||||
<Col span={24}>
|
<Col span={24}>
|
||||||
<Table
|
<Table
|
||||||
@@ -202,13 +267,18 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
pagination={{ position: "top" }}
|
pagination={{ position: "top" }}
|
||||||
columns={dmsType === "cdk" ? (Fortellis.treatment === "on" ? fortellisColumns : cdkColumns) : pbsColumns}
|
columns={columns}
|
||||||
rowKey={(record) => (dmsType === "cdk" ? record.id?.value || record.customerId : record.ContactId)}
|
rowKey={rowKeyFn}
|
||||||
dataSource={customerList}
|
dataSource={customerList}
|
||||||
//onChange={handleTableChange}
|
|
||||||
rowSelection={{
|
rowSelection={{
|
||||||
onSelect: (record) => {
|
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",
|
type: "radio",
|
||||||
selectedRowKeys: [selectedCustomer]
|
selectedRowKeys: [selectedCustomer]
|
||||||
|
|||||||
@@ -62,35 +62,45 @@ export function DmsPostForm({ bodyshop, socket, job, logsRef }) {
|
|||||||
return {
|
return {
|
||||||
...cdkPayer,
|
...cdkPayer,
|
||||||
dms_acctnumber: cdkPayer.dms_acctnumber,
|
dms_acctnumber: cdkPayer.dms_acctnumber,
|
||||||
controlnumber: job && job[cdkPayer.control_type]
|
controlnumber: job?.[cdkPayer.control_type]
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleFinish = (values) => {
|
const handleFinish = (values) => {
|
||||||
//TODO: Add this as a split instead.
|
const dms = determineDmsType(bodyshop);
|
||||||
if (Fortellis.treatment === "on") {
|
|
||||||
wsssocket.emit("fortellis-export-job", {
|
// 1) RR takes precedence regardless of Fortellis split
|
||||||
jobid: job.id,
|
if (dms === "rr") {
|
||||||
txEnvelope: {
|
wsssocket.emit("rr-export-job", {
|
||||||
...values,
|
bodyshopId: bodyshop?.id || bodyshop?.bodyshopid || bodyshop?.uuid,
|
||||||
SubscriptionID: bodyshop.cdk_dealerid
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
socket.emit(`${determineDmsType(bodyshop)}-export-job`, {
|
|
||||||
jobid: job.id,
|
jobid: job.id,
|
||||||
|
job,
|
||||||
txEnvelope: values
|
txEnvelope: values
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
console.log(logsRef);
|
// 2) Fallback to existing behavior
|
||||||
if (logsRef) {
|
// TODO: Add this as a split instead.
|
||||||
console.log("executing", logsRef);
|
if (Fortellis.treatment === "on") {
|
||||||
logsRef.curent &&
|
wsssocket.emit("fortellis-export-job", {
|
||||||
logsRef.current.scrollIntoView({
|
jobid: job.id,
|
||||||
behavior: "smooth"
|
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" });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -37,21 +37,20 @@ const mapDispatchToProps = (dispatch) => ({
|
|||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(DmsContainer);
|
export default connect(mapStateToProps, mapDispatchToProps)(DmsContainer);
|
||||||
|
|
||||||
export const socket = SocketIO(
|
// Legacy /ws socket (CDK/PBS)
|
||||||
import.meta.env.PROD ? import.meta.env.VITE_APP_AXIOS_BASE_API_URL : "", // for dev testing,
|
export const socket = SocketIO(import.meta.env.PROD ? import.meta.env.VITE_APP_AXIOS_BASE_API_URL : "", {
|
||||||
{
|
path: "/ws",
|
||||||
path: "/ws",
|
withCredentials: true,
|
||||||
withCredentials: true,
|
auth: async (callback) => {
|
||||||
auth: async (callback) => {
|
const token = auth.currentUser && (await auth.currentUser.getIdToken());
|
||||||
const token = auth.currentUser && (await auth.currentUser.getIdToken());
|
callback({ token });
|
||||||
callback({ token });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
|
|
||||||
export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, insertAuditTrail }) {
|
export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, insertAuditTrail }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [logLevel, setLogLevel] = useState(determineDmsType(bodyshop) === "pbs" ? "INFO" : "DEBUG");
|
const dms = determineDmsType(bodyshop);
|
||||||
|
const [logLevel, setLogLevel] = useState(dms === "pbs" ? "INFO" : "DEBUG");
|
||||||
const history = useNavigate();
|
const history = useNavigate();
|
||||||
const [logs, setLogs] = useState([]);
|
const [logs, setLogs] = useState([]);
|
||||||
const search = queryString.parse(useLocation().search);
|
const search = queryString.parse(useLocation().search);
|
||||||
@@ -64,6 +63,7 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
names: ["Fortellis"],
|
names: ["Fortellis"],
|
||||||
splitKey: bodyshop.imexshopid
|
splitKey: bodyshop.imexshopid
|
||||||
});
|
});
|
||||||
|
// New unified wss socket (Fortellis, RR)
|
||||||
const { socket: wsssocket } = useSocket();
|
const { socket: wsssocket } = useSocket();
|
||||||
|
|
||||||
const { loading, error, data } = useQuery(QUERY_JOB_EXPORT_DMS, {
|
const { loading, error, data } = useQuery(QUERY_JOB_EXPORT_DMS, {
|
||||||
@@ -95,19 +95,59 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
}, [t, setBreadcrumbs, setSelectedHeader]);
|
}, [t, setBreadcrumbs, setSelectedHeader]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// ✅ RR uses the new wss socket and takes precedence over Fortellis flag
|
||||||
|
if (dms === "rr") {
|
||||||
|
// set log level on connect and immediately
|
||||||
|
wsssocket.emit("set-log-level", logLevel);
|
||||||
|
const handleConnect = () => wsssocket.emit("set-log-level", logLevel);
|
||||||
|
const handleReconnect = () =>
|
||||||
|
setLogs((prev) => [
|
||||||
|
...prev,
|
||||||
|
{ timestamp: new Date(), level: "warn", message: "Reconnected to RR Export Service" }
|
||||||
|
]);
|
||||||
|
const handleConnectError = (err) => {
|
||||||
|
console.log(`connect_error due to ${err}`, err);
|
||||||
|
notification.error({ message: err.message });
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleLogEvent = (payload) => setLogs((prev) => [...prev, payload]);
|
||||||
|
const handleExportSuccess = (payload) => {
|
||||||
|
notification.success({ message: t("jobs.successes.exported") });
|
||||||
|
insertAuditTrail({
|
||||||
|
jobid: payload,
|
||||||
|
operation: AuditTrailMapping.jobexported(),
|
||||||
|
type: "jobexported"
|
||||||
|
});
|
||||||
|
history("/manage/accounting/receivables");
|
||||||
|
};
|
||||||
|
const handleRrExportResult = (payload) => handleExportSuccess(payload);
|
||||||
|
|
||||||
|
wsssocket.on("connect", handleConnect);
|
||||||
|
wsssocket.on("reconnect", handleReconnect);
|
||||||
|
wsssocket.on("connect_error", handleConnectError);
|
||||||
|
|
||||||
|
// RR channels (over wss)
|
||||||
|
wsssocket.on("rr-log-event", handleLogEvent);
|
||||||
|
wsssocket.on("export-success", handleExportSuccess);
|
||||||
|
wsssocket.on("rr-export-job:result", handleRrExportResult);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
wsssocket.off("connect", handleConnect);
|
||||||
|
wsssocket.off("reconnect", handleReconnect);
|
||||||
|
wsssocket.off("connect_error", handleConnectError);
|
||||||
|
wsssocket.off("rr-log-event", handleLogEvent);
|
||||||
|
wsssocket.off("export-success", handleExportSuccess);
|
||||||
|
wsssocket.off("rr-export-job:result", handleRrExportResult);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fortellis / CDK behavior (when not RR)
|
||||||
if (Fortellis.treatment === "on") {
|
if (Fortellis.treatment === "on") {
|
||||||
wsssocket.emit("set-log-level", logLevel);
|
wsssocket.emit("set-log-level", logLevel);
|
||||||
|
|
||||||
const handleLogEvent = (payload) => {
|
const handleLogEvent = (payload) => setLogs((prev) => [...prev, payload]);
|
||||||
setLogs((logs) => {
|
|
||||||
return [...logs, payload];
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleExportSuccess = (payload) => {
|
const handleExportSuccess = (payload) => {
|
||||||
notification.success({
|
notification.success({ message: t("jobs.successes.exported") });
|
||||||
message: t("jobs.successes.exported")
|
|
||||||
});
|
|
||||||
insertAuditTrail({
|
insertAuditTrail({
|
||||||
jobid: payload,
|
jobid: payload,
|
||||||
operation: AuditTrailMapping.jobexported(),
|
operation: AuditTrailMapping.jobexported(),
|
||||||
@@ -116,6 +156,7 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
history("/manage/accounting/receivables");
|
history("/manage/accounting/receivables");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Fortellis logs (wss)
|
||||||
wsssocket.on("fortellis-log-event", handleLogEvent);
|
wsssocket.on("fortellis-log-event", handleLogEvent);
|
||||||
wsssocket.on("export-success", handleExportSuccess);
|
wsssocket.on("export-success", handleExportSuccess);
|
||||||
|
|
||||||
@@ -124,32 +165,21 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
wsssocket.off("export-success", handleExportSuccess);
|
wsssocket.off("export-success", handleExportSuccess);
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
// CDK/PBS via legacy /ws socket
|
||||||
socket.on("connect", () => socket.emit("set-log-level", logLevel));
|
socket.on("connect", () => socket.emit("set-log-level", logLevel));
|
||||||
socket.on("reconnect", () => {
|
socket.on("reconnect", () => {
|
||||||
setLogs((logs) => {
|
setLogs((prev) => [
|
||||||
return [
|
...prev,
|
||||||
...logs,
|
{ timestamp: new Date(), level: "warn", message: "Reconnected to CDK Export Service" }
|
||||||
{
|
]);
|
||||||
timestamp: new Date(),
|
|
||||||
level: "warn",
|
|
||||||
message: "Reconnected to CDK Export Service"
|
|
||||||
}
|
|
||||||
];
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
socket.on("connect_error", (err) => {
|
socket.on("connect_error", (err) => {
|
||||||
console.log(`connect_error due to ${err}`, err);
|
console.log(`connect_error due to ${err}`, err);
|
||||||
notification.error({ message: err.message });
|
notification.error({ message: err.message });
|
||||||
});
|
});
|
||||||
socket.on("log-event", (payload) => {
|
socket.on("log-event", (payload) => setLogs((prev) => [...prev, payload]));
|
||||||
setLogs((logs) => {
|
|
||||||
return [...logs, payload];
|
|
||||||
});
|
|
||||||
});
|
|
||||||
socket.on("export-success", (payload) => {
|
socket.on("export-success", (payload) => {
|
||||||
notification.success({
|
notification.success({ message: t("jobs.successes.exported") });
|
||||||
message: t("jobs.successes.exported")
|
|
||||||
});
|
|
||||||
insertAuditTrail({
|
insertAuditTrail({
|
||||||
jobid: payload,
|
jobid: payload,
|
||||||
operation: AuditTrailMapping.jobexported(),
|
operation: AuditTrailMapping.jobexported(),
|
||||||
@@ -164,7 +194,7 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
socket.disconnect();
|
socket.disconnect();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}, []);
|
}, [dms, Fortellis?.treatment, logLevel, history, insertAuditTrail, notification, t, wsssocket]);
|
||||||
|
|
||||||
if (loading) return <LoadingSpinner />;
|
if (loading) return <LoadingSpinner />;
|
||||||
if (error) return <AlertComponent message={error.message} type="error" />;
|
if (error) return <AlertComponent message={error.message} type="error" />;
|
||||||
@@ -176,15 +206,14 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{Fortellis.treatment === "on" && (
|
<AlertComponent
|
||||||
<AlertComponent
|
style={{ marginBottom: 10 }}
|
||||||
style={{ marginBottom: 10 }}
|
message={`Posting to ${determineDmsType(bodyshop)}`}
|
||||||
message={`Posting to ${determineDmsType(bodyshop)}`}
|
type="warning"
|
||||||
type="warning"
|
showIcon
|
||||||
showIcon
|
closable
|
||||||
closable
|
/>
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<Row gutter={[16, 16]}>
|
<Row gutter={[16, 16]}>
|
||||||
<Col md={24} lg={10}>
|
<Col md={24} lg={10}>
|
||||||
<DmsAllocationsSummary
|
<DmsAllocationsSummary
|
||||||
@@ -219,7 +248,12 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
value={logLevel}
|
value={logLevel}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
setLogLevel(value);
|
setLogLevel(value);
|
||||||
socket.emit("set-log-level", value);
|
// Send to the active socket type
|
||||||
|
if (dms === "rr" || Fortellis.treatment === "on") {
|
||||||
|
wsssocket.emit("set-log-level", value);
|
||||||
|
} else {
|
||||||
|
socket.emit("set-log-level", value);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Select.Option key="DEBUG">DEBUG</Select.Option>
|
<Select.Option key="DEBUG">DEBUG</Select.Option>
|
||||||
@@ -231,8 +265,14 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setLogs([]);
|
setLogs([]);
|
||||||
socket.disconnect();
|
// Reconnect appropriate socket
|
||||||
socket.connect();
|
if (dms === "rr" || Fortellis.treatment === "on") {
|
||||||
|
// wsssocket is managed by provider; emit a ping
|
||||||
|
wsssocket.emit("set-log-level", logLevel);
|
||||||
|
} else {
|
||||||
|
socket.disconnect();
|
||||||
|
socket.connect();
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Reconnect
|
Reconnect
|
||||||
|
|||||||
Reference in New Issue
Block a user