feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration Clean up posting form
This commit is contained in:
@@ -29,7 +29,6 @@ function normalizeRrList(list) {
|
||||
if (!custNo) return null;
|
||||
const vinOwner = !!(row.vinOwner ?? row.isVehicleOwner);
|
||||
|
||||
// Pass through address from backend if present; tolerate various shapes
|
||||
const address =
|
||||
row.address && typeof row.address === "object"
|
||||
? {
|
||||
@@ -47,7 +46,6 @@ function normalizeRrList(list) {
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
// Small formatter used by the RR Address column render
|
||||
function rrAddressToString(addr) {
|
||||
if (!addr) return "";
|
||||
const parts = [
|
||||
@@ -89,16 +87,12 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
|
||||
const rrHasVinOwner = rrOwnerSet.size > 0;
|
||||
|
||||
useEffect(() => {
|
||||
// RR takes precedence
|
||||
if (dms === "rr") {
|
||||
const handleRrSelectCustomer = (list) => {
|
||||
const normalized = normalizeRrList(list);
|
||||
|
||||
setOpen(true);
|
||||
setDmsType("rr");
|
||||
setcustomerList(normalized);
|
||||
|
||||
// PRESELECT VIN OWNER (first one if multiple)
|
||||
const firstOwner = normalized.find((r) => r.vinOwner)?.custNo;
|
||||
setSelectedCustomer(firstOwner ? String(firstOwner) : null);
|
||||
};
|
||||
@@ -142,7 +136,6 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
|
||||
}
|
||||
}, [dms, Fortellis?.treatment, wsssocket]);
|
||||
|
||||
// Safety: if owner info arrives later or list changes, keep the owner preselected.
|
||||
useEffect(() => {
|
||||
if (dmsType !== "rr" || !rrHasVinOwner) return;
|
||||
const firstOwner = (customerList.find((c) => c.vinOwner) || {}).custNo;
|
||||
@@ -157,7 +150,6 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If there is a VIN owner, only allow owner selection
|
||||
if (dmsType === "rr" && rrHasVinOwner && !rrOwnerSet.has(String(selectedCustomer))) {
|
||||
message.warning(
|
||||
"This VIN is already assigned in Reynolds. Only the VIN owner can be selected. To choose a different customer, change ownership in Reynolds first."
|
||||
@@ -187,15 +179,12 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
|
||||
};
|
||||
|
||||
const onUseGeneric = () => {
|
||||
if (dmsType === "rr" && rrHasVinOwner) return;
|
||||
if (dmsType === "rr" && rrHasVinOwner) return; // not rendered in RR, but keep guard
|
||||
const generic = bodyshop.cdk_configuration?.generic_customer_number || null;
|
||||
|
||||
if (dmsType === "rr") {
|
||||
if (generic) {
|
||||
wsssocket.emit("rr-selected-customer", { jobId: jobid, custNo: String(generic) }, (ack) => {
|
||||
if (!ack?.ok && ack?.error) message.error(ack.error);
|
||||
});
|
||||
}
|
||||
setOpen(false);
|
||||
// Not rendered in RR anymore
|
||||
return;
|
||||
} else if (Fortellis.treatment === "on") {
|
||||
setOpen(false);
|
||||
wsssocket.emit("fortellis-selected-customer", { selectedCustomerId: generic, jobid });
|
||||
@@ -357,12 +346,14 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
|
||||
<Button onClick={onUseSelected} disabled={!selectedCustomer}>
|
||||
{t("jobs.actions.dms.useselected")}
|
||||
</Button>
|
||||
<Button
|
||||
onClick={onUseGeneric}
|
||||
disabled={dmsType === "rr" ? rrHasVinOwner : !bodyshop.cdk_configuration?.generic_customer_number}
|
||||
>
|
||||
{t("jobs.actions.dms.usegeneric")}
|
||||
</Button>
|
||||
|
||||
{/* Hide "Use Generic" entirely in RR mode */}
|
||||
{dmsType !== "rr" && (
|
||||
<Button onClick={onUseGeneric} disabled={!bodyshop.cdk_configuration?.generic_customer_number}>
|
||||
{t("jobs.actions.dms.usegeneric")}
|
||||
</Button>
|
||||
)}
|
||||
|
||||
<Button onClick={onCreateNew} disabled={dmsType === "rr" ? rrHasVinOwner : false}>
|
||||
{t("jobs.actions.dms.createnewcustomer")}
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user