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

This commit is contained in:
Dave
2025-11-04 14:19:26 -05:00
parent ccf3d7df5b
commit 5bbda89fb9
10 changed files with 532 additions and 337 deletions

View File

@@ -1,6 +1,6 @@
import { useSplitTreatments } from "@splitsoftware/splitio-react";
import { Button, Checkbox, Col, Form, Input, message, Modal, Table } from "antd";
import { useEffect, useState } from "react";
import { useEffect, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
@@ -16,6 +16,22 @@ const mapStateToProps = createStructuredSelector({
const mapDispatchToProps = () => ({});
export default connect(mapStateToProps, mapDispatchToProps)(DmsCustomerSelector);
// ---------------- Helpers ----------------
function normalizeRrList(list) {
if (!Array.isArray(list)) return [];
return list
.map((row) => {
const custNo = row.custNo || row.CustomerId || row.customerId || null;
const name =
row.name ||
[row.CustomerName?.FirstName, row.CustomerName?.LastName].filter(Boolean).join(" ").trim() ||
(custNo ? String(custNo) : "");
return custNo ? { custNo: String(custNo), name } : null;
})
.filter(Boolean);
}
export function DmsCustomerSelector({ bodyshop, jobid }) {
const { t } = useTranslation();
const [customerList, setcustomerList] = useState([]);
@@ -35,7 +51,7 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
const { socket: wsssocket } = useSocket();
const dms = determineDmsType(bodyshop);
const dms = useMemo(() => determineDmsType(bodyshop), [bodyshop]);
const bodyshopId = bodyshop?.id || bodyshop?.bodyshopid || bodyshop?.uuid;
useEffect(() => {
@@ -44,28 +60,30 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
const handleRrSelectCustomer = (list) => {
setOpen(true);
setDmsType("rr");
setcustomerList(Array.isArray(list) ? list : []);
// Normalize to { custNo, name }
setcustomerList(normalizeRrList(list));
setSelectedCustomer(null);
};
const handleRrCreateRequired = () => {
// Open selector shell + creation form
setOpen(true);
setDmsType("rr");
setcustomerList([]);
setOpenCreate(true);
};
const handleRrCustomerCreated = ({ custNo }) => {
if (custNo) {
message.success(t("dms.messages.customerCreated"));
setSelectedCustomer(custNo);
setSelectedCustomer(String(custNo));
setOpenCreate(false);
setOpen(false);
}
};
wsssocket.on("rr-select-customer", handleRrSelectCustomer);
wsssocket.on("rr-customer-create-required", handleRrCreateRequired);
wsssocket.on("rr-customer-created", handleRrCustomerCreated);
wsssocket.on("rr-select-customer", handleRrSelectCustomer);
return () => {
wsssocket.off("rr-select-customer", handleRrSelectCustomer);
@@ -79,6 +97,7 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
setOpen(true);
setDmsType("cdk");
setcustomerList(Array.isArray(list) ? list : []);
setSelectedCustomer(null);
};
wsssocket.on("fortellis-select-customer", handleFortellisSelectCustomer);
return () => {
@@ -89,11 +108,13 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
setOpen(true);
setDmsType("cdk");
setcustomerList(Array.isArray(list) ? list : []);
setSelectedCustomer(null);
};
const handlePbsSelectCustomer = (list) => {
setOpen(true);
setDmsType("pbs");
setcustomerList(Array.isArray(list) ? list : []);
setSelectedCustomer(null);
};
socket.on("cdk-select-customer", handleCdkSelectCustomer);
socket.on("pbs-select-customer", handlePbsSelectCustomer);
@@ -105,18 +126,25 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
}, [dms, Fortellis?.treatment, wsssocket]);
const onUseSelected = () => {
if (dmsType === "rr") {
// Stay open and show creation form
setOpen(true);
setOpenCreate(true);
if (!selectedCustomer) {
message.warning(t("general.actions.select"));
return;
}
if (dmsType === "rr") {
// ✅ RR now behaves like others: use the selected row and close
wsssocket.emit("rr-selected-customer", { bodyshopId, custNo: String(selectedCustomer), jobId: jobid });
setOpen(false);
setSelectedCustomer(null);
return;
}
// Non-RR behavior unchanged:
setOpen(false);
if (Fortellis.treatment === "on") {
wsssocket.emit("fortellis-selected-customer", { selectedCustomerId: null, jobid });
wsssocket.emit("fortellis-selected-customer", { selectedCustomerId: selectedCustomer, jobid });
} else {
socket.emit(`${dmsType}-selected-customer`, null);
socket.emit(`${dmsType}-selected-customer`, selectedCustomer);
}
setSelectedCustomer(null);
};
@@ -124,10 +152,9 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
const onUseGeneric = () => {
setOpen(false);
const generic = bodyshop.cdk_configuration?.generic_customer_number || null;
console.dir({ bodyshop, generic });
if (dmsType === "rr") {
if (generic) {
wsssocket.emit("rr-selected-customer", { bodyshopId, custNo: generic, jobId: jobid });
wsssocket.emit("rr-selected-customer", { bodyshopId, custNo: String(generic), jobId: jobid });
}
} else if (Fortellis.treatment === "on") {
wsssocket.emit("fortellis-selected-customer", { selectedCustomerId: generic, jobid });
@@ -138,11 +165,15 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
};
const onCreateNew = () => {
setOpen(false);
if (dmsType === "rr") {
// RR equivalent: signal create intent explicitly
wsssocket.emit("rr-selected-customer", { bodyshopId, create: true, jobId: jobid });
} else if (Fortellis.treatment === "on") {
// RR: open inline creation modal (same as before)
setOpen(true);
setOpenCreate(true);
return;
}
// Non-RR stays unchanged
setOpen(false);
if (Fortellis.treatment === "on") {
wsssocket.emit("fortellis-selected-customer", { selectedCustomerId: null, jobid });
} else {
socket.emit(`${dmsType}-selected-customer`, null);
@@ -150,12 +181,10 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
setSelectedCustomer(null);
};
// ---------- Columns ----------
const fortellisColumns = [
{
title: t("jobs.fields.dms.id"),
dataIndex: "customerId",
key: "id"
},
{ title: t("jobs.fields.dms.id"), dataIndex: "customerId", key: "id" },
{
title: t("jobs.fields.dms.vinowner"),
dataIndex: "vinOwner",
@@ -187,11 +216,7 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
];
const cdkColumns = [
{
title: t("jobs.fields.dms.id"),
dataIndex: ["id", "value"],
key: "id"
},
{ title: t("jobs.fields.dms.id"), dataIndex: ["id", "value"], key: "id" },
{
title: t("jobs.fields.dms.vinowner"),
dataIndex: "vinOwner",
@@ -215,11 +240,7 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
];
const pbsColumns = [
{
title: t("jobs.fields.dms.id"),
dataIndex: "ContactId",
key: "ContactId"
},
{ title: t("jobs.fields.dms.id"), dataIndex: "ContactId", key: "ContactId" },
{
title: t("jobs.fields.dms.name1"),
key: "name1",
@@ -233,14 +254,10 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
}
];
// RR is normalized to { custNo, name }
const rrColumns = [
{ title: t("jobs.fields.dms.id"), dataIndex: "custNo", key: "custNo" },
{
title: t("jobs.fields.dms.name1"),
dataIndex: "name",
key: "name",
sorter: (a, b) => alphaSort(a?.name, b?.name)
}
{ title: t("jobs.fields.dms.name1"), dataIndex: "name", key: "name", sorter: (a, b) => alphaSort(a?.name, b?.name) }
];
if (!open) return null;
@@ -287,12 +304,14 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
: dmsType === "cdk"
? record.id?.value || record.customerId
: record.ContactId;
setSelectedCustomer(key);
setSelectedCustomer(key ? String(key) : null);
},
type: "radio",
selectedRowKeys: [selectedCustomer]
selectedRowKeys: selectedCustomer ? [selectedCustomer] : []
}}
/>
{/* RR inline creation modal (unchanged) */}
<Modal
open={openCreate}
title={t("jobs.actions.dms.createnewcustomer")}
@@ -304,7 +323,6 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
form={createForm}
layout="vertical"
onFinish={(values) => {
// Map a few sane defaults; BE tolerates partials
const fields = {
FirstName: values.FirstName,
LastName: values.LastName,
@@ -318,7 +336,7 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
wsssocket.emit("rr-create-customer", { jobId: jobid, fields }, (ack) => {
if (ack?.ok) {
message.success(t("dms.messages.customerCreated"));
setSelectedCustomer(ack.custNo);
setSelectedCustomer(ack.custNo ? String(ack.custNo) : null);
setOpenCreate(false);
setOpen(false);
} else {