Basic posting up to fortellis-select-customer.

This commit is contained in:
Patrick Fic
2025-04-16 15:55:22 -07:00
parent 567171c722
commit e2b4b408ed
9 changed files with 433 additions and 317 deletions

View File

@@ -21,6 +21,8 @@ import { selectBodyshop } from "../../redux/user/user.selectors";
import InstanceRenderManager from "../../utils/instanceRenderMgr";
import AuditTrailMapping from "../../utils/AuditTrailMappings";
import { useNotification } from "../../contexts/Notifications/notificationContext.jsx";
import { useSplitTreatments } from "@splitsoftware/splitio-react";
import { useSocket } from "../../contexts/SocketIO/useSocket.js";
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop
@@ -54,6 +56,14 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
const search = queryString.parse(useLocation().search);
const { jobId } = search;
const notification = useNotification();
const {
treatments: { Fortellis }
} = useSplitTreatments({
attributes: {},
names: ["Fortellis"],
splitKey: bodyshop.imexshopid
});
const { socket: wsssocket } = useSocket();
const { loading, error, data } = useQuery(QUERY_JOB_EXPORT_DMS, {
variables: { id: jobId },
@@ -84,45 +94,75 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
}, [t, setBreadcrumbs, setSelectedHeader]);
useEffect(() => {
socket.on("connect", () => socket.emit("set-log-level", logLevel));
socket.on("reconnect", () => {
setLogs((logs) => {
return [
...logs,
{
timestamp: new Date(),
level: "warn",
message: "Reconnected to CDK Export Service"
}
];
});
});
socket.on("connect_error", (err) => {
console.log(`connect_error due to ${err}`, err);
notification.error({ message: err.message });
});
socket.on("log-event", (payload) => {
setLogs((logs) => {
return [...logs, payload];
});
});
socket.on("export-success", (payload) => {
notification.success({
message: t("jobs.successes.exported")
});
insertAuditTrail({
jobid: payload,
operation: AuditTrailMapping.jobexported(),
type: "jobexported"
});
history("/manage/accounting/receivables");
});
if (Fortellis.treatment === "on") {
wsssocket.emit("set-log-level", logLevel);
if (socket.disconnected) socket.connect();
return () => {
socket.removeAllListeners();
socket.disconnect();
};
const handleLogEvent = (payload) => {
setLogs((logs) => {
return [...logs, payload];
});
};
const handleExportSuccess = (payload) => {
notification.success({
message: t("jobs.successes.exported")
});
insertAuditTrail({
jobid: payload,
operation: AuditTrailMapping.jobexported(),
type: "jobexported"
});
history("/manage/accounting/receivables");
};
wsssocket.on("fortellis-log-event", handleLogEvent);
wsssocket.on("export-success", handleExportSuccess);
return () => {
wsssocket.off("fortellis-log-event", handleLogEvent);
wsssocket.off("export-success", handleExportSuccess);
};
} else {
socket.on("connect", () => socket.emit("set-log-level", logLevel));
socket.on("reconnect", () => {
setLogs((logs) => {
return [
...logs,
{
timestamp: new Date(),
level: "warn",
message: "Reconnected to CDK Export Service"
}
];
});
});
socket.on("connect_error", (err) => {
console.log(`connect_error due to ${err}`, err);
notification.error({ message: err.message });
});
socket.on("log-event", (payload) => {
setLogs((logs) => {
return [...logs, payload];
});
});
socket.on("export-success", (payload) => {
notification.success({
message: t("jobs.successes.exported")
});
insertAuditTrail({
jobid: payload,
operation: AuditTrailMapping.jobexported(),
type: "jobexported"
});
history("/manage/accounting/receivables");
});
if (socket.disconnected) socket.connect();
return () => {
socket.removeAllListeners();
socket.disconnect();
};
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
@@ -137,6 +177,9 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
return (
<div>
{Fortellis.treatment === "on" && (
<AlertComponent message="Posting to Fortellis" type="warning" showIcon closable />
)}
<Row gutter={[16, 16]}>
<Col md={24} lg={10}>
<DmsAllocationsSummary