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

This commit is contained in:
Dave
2025-11-04 11:45:54 -05:00
parent ea14606538
commit eeb685802e
4 changed files with 238 additions and 41 deletions

View File

@@ -50,14 +50,11 @@ export function DmsAllocationsSummary({ socket, bodyshop, jobId, title }) {
setAllocationsSummary(ack);
socket.allocationsSummary = ack;
});
} else {
// Default to CDK path
if (socket.connected) {
socket.emit("cdk-calculate-allocations", jobId, (ack) => {
setAllocationsSummary(ack);
socket.allocationsSummary = ack;
});
}
} else if (socket.connected) {
socket.emit("cdk-calculate-allocations", jobId, (ack) => {
setAllocationsSummary(ack);
socket.allocationsSummary = ack;
});
}
};

View File

@@ -1,5 +1,5 @@
import { useSplitTreatments } from "@splitsoftware/splitio-react";
import { Button, Checkbox, Col, Table } from "antd";
import { Button, Checkbox, Col, Form, Input, message, Modal, Table } from "antd";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
@@ -22,6 +22,8 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
const [open, setOpen] = useState(false);
const [selectedCustomer, setSelectedCustomer] = useState(null);
const [dmsType, setDmsType] = useState("cdk");
const [openCreate, setOpenCreate] = useState(false);
const [createForm] = Form.useForm();
const {
treatments: { Fortellis }
@@ -44,9 +46,31 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
setDmsType("rr");
setcustomerList(Array.isArray(list) ? list : []);
};
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);
setOpenCreate(false);
setOpen(false);
}
};
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);
wsssocket.off("rr-customer-create-required", handleRrCreateRequired);
wsssocket.off("rr-customer-created", handleRrCustomerCreated);
};
}
@@ -81,13 +105,18 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
}, [dms, Fortellis?.treatment, wsssocket]);
const onUseSelected = () => {
setOpen(false);
if (dmsType === "rr") {
wsssocket.emit("rr-selected-customer", { bodyshopId, custNo: selectedCustomer, jobId: jobid });
} else if (Fortellis.treatment === "on") {
wsssocket.emit("fortellis-selected-customer", { selectedCustomerId: selectedCustomer, jobid });
// Stay open and show creation form
setOpen(true);
setOpenCreate(true);
return;
}
// Non-RR behavior unchanged:
setOpen(false);
if (Fortellis.treatment === "on") {
wsssocket.emit("fortellis-selected-customer", { selectedCustomerId: null, jobid });
} else {
socket.emit(`${dmsType}-selected-customer`, selectedCustomer);
socket.emit(`${dmsType}-selected-customer`, null);
}
setSelectedCustomer(null);
};
@@ -264,6 +293,66 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
selectedRowKeys: [selectedCustomer]
}}
/>
<Modal
open={openCreate}
title={t("jobs.actions.dms.createnewcustomer")}
onCancel={() => setOpenCreate(false)}
onOk={() => createForm.submit()}
destroyOnClose
>
<Form
form={createForm}
layout="vertical"
onFinish={(values) => {
// Map a few sane defaults; BE tolerates partials
const fields = {
FirstName: values.FirstName,
LastName: values.LastName,
CompanyName: values.CompanyName,
Phone: values.Phone,
AddressLine1: values.AddressLine1,
City: values.City,
StateProvince: values.StateProvince,
PostalCode: values.PostalCode
};
wsssocket.emit("rr-create-customer", { jobId: jobid, fields }, (ack) => {
if (ack?.ok) {
message.success(t("dms.messages.customerCreated"));
setSelectedCustomer(ack.custNo);
setOpenCreate(false);
setOpen(false);
} else {
message.error(ack?.error || t("general.errors.unknown"));
}
});
}}
>
<Form.Item name="FirstName" label={t("jobs.fields.firstName")}>
<Input />
</Form.Item>
<Form.Item name="LastName" label={t("jobs.fields.lastName")} rules={[{ required: true }]}>
<Input />
</Form.Item>
<Form.Item name="CompanyName" label={t("jobs.fields.companyName")}>
<Input />
</Form.Item>
<Form.Item name="Phone" label={t("jobs.fields.phone")}>
<Input />
</Form.Item>
<Form.Item name="AddressLine1" label={t("jobs.fields.address")}>
<Input />
</Form.Item>
<Form.Item name="City" label={t("jobs.fields.city")}>
<Input />
</Form.Item>
<Form.Item name="StateProvince" label={t("jobs.fields.state")}>
<Input />
</Form.Item>
<Form.Item name="PostalCode" label={t("jobs.fields.postalCode")}>
<Input />
</Form.Item>
</Form>
</Modal>
</Col>
);
}