@@ -23,13 +23,13 @@ export default connect(mapStateToProps, mapDispatchToProps)(DmsCustomerSelector)
|
||||
* @constructor
|
||||
*/
|
||||
export function DmsCustomerSelector(props) {
|
||||
const { bodyshop, jobid, socket, rrOptions = {} } = props;
|
||||
const { bodyshop, jobid, job, socket, rrOptions = {} } = props;
|
||||
|
||||
// Centralized "mode" (provider + transport)
|
||||
const mode = props.mode;
|
||||
|
||||
// Stable base props for children
|
||||
const base = useMemo(() => ({ bodyshop, jobid, socket }), [bodyshop, jobid, socket]);
|
||||
const base = useMemo(() => ({ bodyshop, jobid, job, socket }), [bodyshop, jobid, job, socket]);
|
||||
|
||||
switch (mode) {
|
||||
case DMS_MAP.reynolds: {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Alert, Button, Checkbox, Col, message, Space, Table } from "antd";
|
||||
import { Alert, Button, Checkbox, message, Modal, Space, Table } from "antd";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { alphaSort } from "../../utils/sorters";
|
||||
@@ -47,6 +47,7 @@ const rrAddressToString = (addr) => {
|
||||
export default function RRCustomerSelector({
|
||||
jobid,
|
||||
socket,
|
||||
job,
|
||||
rrOpenRoLimit = false,
|
||||
onRrOpenRoFinished,
|
||||
rrValidationPending = false,
|
||||
@@ -59,15 +60,26 @@ export default function RRCustomerSelector({
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
|
||||
// Show dialog automatically when validation is pending
|
||||
// BUT: skip this for early RO flow (job already has dms_id)
|
||||
useEffect(() => {
|
||||
if (rrValidationPending) setOpen(true);
|
||||
}, [rrValidationPending]);
|
||||
if (rrValidationPending && !job?.dms_id) {
|
||||
setOpen(true);
|
||||
}
|
||||
}, [rrValidationPending, job?.dms_id]);
|
||||
|
||||
// Listen for RR customer selection list
|
||||
useEffect(() => {
|
||||
if (!socket) return;
|
||||
const handleRrSelectCustomer = (list) => {
|
||||
const normalized = normalizeRrList(list);
|
||||
|
||||
// If list is empty, it means early RO exists and customer selection should be skipped
|
||||
// Don't open the modal in this case
|
||||
if (normalized.length === 0) {
|
||||
setRefreshing(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setOpen(true);
|
||||
setCustomerList(normalized);
|
||||
const firstOwner = normalized.find((r) => r.vinOwner)?.custNo;
|
||||
@@ -127,6 +139,10 @@ export default function RRCustomerSelector({
|
||||
});
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
const refreshRrSearch = () => {
|
||||
setRefreshing(true);
|
||||
const to = setTimeout(() => setRefreshing(false), 12000);
|
||||
@@ -141,8 +157,6 @@ export default function RRCustomerSelector({
|
||||
socket.emit("rr-export-job", { jobId: jobid });
|
||||
};
|
||||
|
||||
if (!open) return null;
|
||||
|
||||
const columns = [
|
||||
{ title: t("jobs.fields.dms.id"), dataIndex: "custNo", key: "custNo" },
|
||||
{
|
||||
@@ -169,8 +183,45 @@ export default function RRCustomerSelector({
|
||||
return !rrOwnerSet.has(String(record.custNo));
|
||||
};
|
||||
|
||||
// For early RO flow: show validation banner even when modal is closed
|
||||
if (!open) {
|
||||
if (rrValidationPending && job?.dms_id) {
|
||||
return (
|
||||
<div style={{ marginBottom: 16 }}>
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
title="Complete Validation in Reynolds"
|
||||
description={
|
||||
<div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
|
||||
<div>
|
||||
We created the Repair Order. Please validate the totals and taxes in the DMS system. When done,
|
||||
click <strong>Finished</strong> to finalize and mark this export as complete.
|
||||
</div>
|
||||
<div>
|
||||
<Space>
|
||||
<Button type="primary" onClick={onValidationFinished}>
|
||||
Finished
|
||||
</Button>
|
||||
</Space>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Col span={24}>
|
||||
<Modal
|
||||
open={open}
|
||||
onCancel={handleClose}
|
||||
footer={null}
|
||||
width={800}
|
||||
title={t("dms.selectCustomer")}
|
||||
>
|
||||
<Table
|
||||
title={() => (
|
||||
<div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
|
||||
@@ -196,8 +247,8 @@ export default function RRCustomerSelector({
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Validation step banner */}
|
||||
{rrValidationPending && (
|
||||
{/* Validation step banner - only show for NON-early RO flow (legacy) */}
|
||||
{rrValidationPending && !job?.dms_id && (
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
@@ -262,6 +313,6 @@ export default function RRCustomerSelector({
|
||||
getCheckboxProps: (record) => ({ disabled: rrDisableRow(record) })
|
||||
}}
|
||||
/>
|
||||
</Col>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ export function DmsLogEvents({
|
||||
return {
|
||||
key: idx,
|
||||
color: logLevelColor(level),
|
||||
children: (
|
||||
content: (
|
||||
<Space orientation="vertical" size={4} style={{ display: "flex" }}>
|
||||
{/* Row 1: summary + inline "Details" toggle */}
|
||||
<Space wrap align="start">
|
||||
@@ -113,7 +113,7 @@ export function DmsLogEvents({
|
||||
[logs, openSet, colorizeJson, isDarkMode, showDetails]
|
||||
);
|
||||
|
||||
return <Timeline pending reverse items={items} />;
|
||||
return <Timeline reverse items={items} />;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -208,8 +208,18 @@ export default function RRPostForm({
|
||||
});
|
||||
};
|
||||
|
||||
// Check if early RO was created (job has dms_id)
|
||||
const hasEarlyRO = !!job?.dms_id;
|
||||
|
||||
return (
|
||||
<Card title={t("jobs.labels.dms.postingform")}>
|
||||
{hasEarlyRO && (
|
||||
<Typography.Paragraph type="success" strong style={{ marginBottom: 16 }}>
|
||||
✅ Early RO Created: {job.dms_id}
|
||||
<br />
|
||||
<Typography.Text type="secondary">This will update the existing RO with full job data.</Typography.Text>
|
||||
</Typography.Paragraph>
|
||||
)}
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
@@ -218,96 +228,96 @@ export default function RRPostForm({
|
||||
initialValues={initialValues}
|
||||
>
|
||||
<Row gutter={[16, 12]} align="bottom">
|
||||
{/* Advisor + inline Refresh */}
|
||||
<Col xs={24} sm={24} md={12} lg={8}>
|
||||
<Form.Item label={t("jobs.fields.dms.advisor")} required>
|
||||
<Space.Compact block>
|
||||
<Form.Item
|
||||
name="advisorNo"
|
||||
noStyle
|
||||
rules={[{ required: true, message: t("general.validation.required") }]}
|
||||
>
|
||||
<Select
|
||||
style={{ flex: 1 }}
|
||||
loading={advLoading}
|
||||
allowClear
|
||||
placeholder={t("general.actions.select", "Select...")}
|
||||
popupMatchSelectWidth
|
||||
options={advisors
|
||||
.map((a) => {
|
||||
const value = getAdvisorNumber(a);
|
||||
if (value == null) return null;
|
||||
return { value: String(value), label: getAdvisorLabel(a) || String(value) };
|
||||
})
|
||||
.filter(Boolean)}
|
||||
notFoundContent={advLoading ? t("general.labels.loading") : t("general.labels.none")}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Tooltip title={t("general.actions.refresh")}>
|
||||
<Button
|
||||
aria-label={t("general.actions.refresh")}
|
||||
icon={<ReloadOutlined />}
|
||||
onClick={() => fetchRrAdvisors(true)}
|
||||
loading={advLoading}
|
||||
/>
|
||||
</Tooltip>
|
||||
</Space.Compact>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
|
||||
{/* RR OpCode (prefix / base / suffix) */}
|
||||
<Col xs={24} sm={12} md={12} lg={8}>
|
||||
<Form.Item
|
||||
required
|
||||
label={
|
||||
<Space size="small" align="center">
|
||||
{t("jobs.fields.dms.rr_opcode", "RR OpCode")}
|
||||
{isCustomOpCode && (
|
||||
{/* Advisor + inline Refresh - Only show if no early RO */}
|
||||
{!hasEarlyRO && (
|
||||
<Col xs={24} sm={24} md={12} lg={8}>
|
||||
<Form.Item label={t("jobs.fields.dms.advisor")} required>
|
||||
<Space.Compact block>
|
||||
<Form.Item
|
||||
name="advisorNo"
|
||||
noStyle
|
||||
rules={[{ required: true, message: t("general.validation.required") }]}
|
||||
>
|
||||
<Select
|
||||
style={{ flex: 1 }}
|
||||
loading={advLoading}
|
||||
allowClear
|
||||
placeholder={t("general.actions.select", "Select...")}
|
||||
popupMatchSelectWidth
|
||||
options={advisors
|
||||
.map((a) => {
|
||||
const value = getAdvisorNumber(a);
|
||||
if (value == null) return null;
|
||||
return { value: String(value), label: getAdvisorLabel(a) || String(value) };
|
||||
})
|
||||
.filter(Boolean)}
|
||||
notFoundContent={advLoading ? t("general.labels.loading") : t("general.labels.none")}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Tooltip title={t("general.actions.refresh")}>
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
icon={<RollbackOutlined />}
|
||||
onClick={handleResetOpCode}
|
||||
style={{ padding: 0 }}
|
||||
>
|
||||
{t("jobs.fields.dms.rr_opcode_reset", "Reset")}
|
||||
</Button>
|
||||
)}
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
<Space.Compact block>
|
||||
<Form.Item name="opPrefix" noStyle>
|
||||
<Input
|
||||
allowClear
|
||||
maxLength={4}
|
||||
style={{ width: "30%" }}
|
||||
placeholder={t("jobs.fields.dms.rr_opcode_prefix", "Prefix")}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="opBase"
|
||||
noStyle
|
||||
rules={[{ required: true, message: t("general.validation.required") }]}
|
||||
>
|
||||
<Input
|
||||
allowClear
|
||||
maxLength={10}
|
||||
style={{ width: "40%" }}
|
||||
placeholder={t("jobs.fields.dms.rr_opcode_base", "Base")}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item name="opSuffix" noStyle>
|
||||
<Input
|
||||
allowClear
|
||||
maxLength={4}
|
||||
style={{ width: "30%" }}
|
||||
placeholder={t("jobs.fields.dms.rr_opcode_suffix", "Suffix")}
|
||||
/>
|
||||
</Form.Item>
|
||||
</Space.Compact>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
aria-label={t("general.actions.refresh")}
|
||||
icon={<ReloadOutlined />}
|
||||
onClick={() => fetchRrAdvisors(true)}
|
||||
loading={advLoading}
|
||||
/>
|
||||
</Tooltip>
|
||||
</Space.Compact>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
)}
|
||||
|
||||
{/* RR OpCode (prefix / base / suffix) - Only show if no early RO */}
|
||||
{!hasEarlyRO && (
|
||||
<Col xs={24} sm={12} md={12} lg={8}>
|
||||
<Form.Item
|
||||
required
|
||||
label={
|
||||
<Space size="small" align="center">
|
||||
{t("jobs.fields.dms.rr_opcode", "RR OpCode")}
|
||||
{isCustomOpCode && (
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
icon={<RollbackOutlined />}
|
||||
onClick={handleResetOpCode}
|
||||
style={{ padding: 0 }}
|
||||
>
|
||||
{t("jobs.fields.dms.rr_opcode_reset", "Reset")}
|
||||
</Button>
|
||||
)}
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
<Space.Compact block>
|
||||
<Form.Item name="opPrefix" noStyle>
|
||||
<Input
|
||||
allowClear
|
||||
maxLength={4}
|
||||
style={{ width: "30%" }}
|
||||
placeholder={t("jobs.fields.dms.rr_opcode_prefix", "Prefix")}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item name="opBase" noStyle rules={[{ required: true }]}>
|
||||
<Input
|
||||
allowClear
|
||||
maxLength={10}
|
||||
style={{ width: "40%" }}
|
||||
placeholder={t("jobs.fields.dms.rr_opcode_base", "Base")}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item name="opSuffix" noStyle>
|
||||
<Input
|
||||
allowClear
|
||||
maxLength={4}
|
||||
style={{ width: "30%" }}
|
||||
placeholder={t("jobs.fields.dms.rr_opcode_suffix", "Suffix")}
|
||||
/>
|
||||
</Form.Item>
|
||||
</Space.Compact>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
)}
|
||||
|
||||
<Col xs={12} sm={8} md={6} lg={4}>
|
||||
<Form.Item name="kmin" label={t("jobs.fields.kmin")} initialValue={job?.kmin} rules={[{ required: true }]}>
|
||||
@@ -355,13 +365,14 @@ export default function RRPostForm({
|
||||
{/* Validation */}
|
||||
<Form.Item shouldUpdate>
|
||||
{() => {
|
||||
const advisorOk = !!form.getFieldValue("advisorNo");
|
||||
// When early RO exists, advisor is already set, so we don't need to validate it
|
||||
const advisorOk = hasEarlyRO ? true : !!form.getFieldValue("advisorNo");
|
||||
return (
|
||||
<Space size="large" wrap align="center">
|
||||
<Statistic title={t("jobs.labels.subtotal")} value={totals.totalSale.toFormat()} />
|
||||
<Typography.Title>=</Typography.Title>
|
||||
<Button disabled={!advisorOk} htmlType="submit">
|
||||
{t("jobs.actions.dms.post")}
|
||||
<Button disabled={!advisorOk} htmlType="submit" type={hasEarlyRO ? "default" : "primary"}>
|
||||
{hasEarlyRO ? t("jobs.actions.dms.update_ro", "Update RO") : t("jobs.actions.dms.post")}
|
||||
</Button>
|
||||
</Space>
|
||||
);
|
||||
|
||||
367
client/src/components/dms-post-form/rr-early-ro-form.jsx
Normal file
367
client/src/components/dms-post-form/rr-early-ro-form.jsx
Normal file
@@ -0,0 +1,367 @@
|
||||
import { ReloadOutlined } from "@ant-design/icons";
|
||||
import { Alert, Button, Form, Input, InputNumber, Modal, Radio, Select, Space, Table, Typography } from "antd";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
|
||||
// Simple customer selector table
|
||||
function CustomerSelectorTable({ customers, onSelect, isSubmitting }) {
|
||||
const [selectedCustNo, setSelectedCustNo] = useState(null);
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: "Select",
|
||||
key: "select",
|
||||
width: 80,
|
||||
render: (_, record) => (
|
||||
<Radio checked={selectedCustNo === record.custNo} onChange={() => setSelectedCustNo(record.custNo)} />
|
||||
)
|
||||
},
|
||||
{ title: "Customer ID", dataIndex: "custNo", key: "custNo" },
|
||||
{ title: "Name", dataIndex: "name", key: "name" },
|
||||
{
|
||||
title: "VIN Owner",
|
||||
key: "vinOwner",
|
||||
render: (_, record) => (record.vinOwner || record.isVehicleOwner ? "Yes" : "No")
|
||||
}
|
||||
];
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Table columns={columns} dataSource={customers} rowKey="custNo" pagination={false} size="small" />
|
||||
<div style={{ marginTop: 16, display: "flex", gap: 8 }}>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={() => onSelect(selectedCustNo, false)}
|
||||
disabled={!selectedCustNo || isSubmitting}
|
||||
loading={isSubmitting}
|
||||
>
|
||||
Use Selected Customer
|
||||
</Button>
|
||||
<Button onClick={() => onSelect(null, true)} disabled={isSubmitting} loading={isSubmitting}>
|
||||
Create New Customer
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* RR Early RO Creation Form
|
||||
* Used from convert button or admin page to create minimal RO before full export
|
||||
* @param bodyshop
|
||||
* @param socket
|
||||
* @param job
|
||||
* @param onSuccess - callback when RO is created successfully
|
||||
* @param onCancel - callback to close modal
|
||||
* @param showCancelButton - whether to show cancel button
|
||||
* @returns {JSX.Element}
|
||||
* @constructor
|
||||
*/
|
||||
export default function RREarlyROForm({ bodyshop, socket, job, onSuccess, onCancel, showCancelButton = true }) {
|
||||
const [form] = Form.useForm();
|
||||
|
||||
// Advisors
|
||||
const [advisors, setAdvisors] = useState([]);
|
||||
const [advLoading, setAdvLoading] = useState(false);
|
||||
|
||||
// Customer selection
|
||||
const [customerCandidates, setCustomerCandidates] = useState([]);
|
||||
const [showCustomerSelector, setShowCustomerSelector] = useState(false);
|
||||
|
||||
// Loading and success states
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [earlyRoCreated, setEarlyRoCreated] = useState(!!job?.dms_id);
|
||||
const [createdRoNumber, setCreatedRoNumber] = useState(job?.dms_id || null);
|
||||
|
||||
// Derive default OpCode parts from bodyshop config (matching dms.container.jsx logic)
|
||||
const initialValues = useMemo(() => {
|
||||
const cfg = bodyshop?.rr_configuration || {};
|
||||
const defaults =
|
||||
cfg.opCodeDefault ||
|
||||
cfg.op_code_default ||
|
||||
cfg.op_codes?.default ||
|
||||
cfg.defaults?.opCode ||
|
||||
cfg.defaults ||
|
||||
cfg.default ||
|
||||
{};
|
||||
|
||||
const prefix = defaults.prefix ?? defaults.opCodePrefix ?? "";
|
||||
const base = defaults.base ?? defaults.opCodeBase ?? "";
|
||||
const suffix = defaults.suffix ?? defaults.opCodeSuffix ?? "";
|
||||
|
||||
return {
|
||||
kmin: job?.kmin || 0,
|
||||
opPrefix: prefix,
|
||||
opBase: base,
|
||||
opSuffix: suffix
|
||||
};
|
||||
}, [bodyshop, job]);
|
||||
|
||||
const getAdvisorNumber = (a) => a?.advisorId;
|
||||
const getAdvisorLabel = (a) => `${a?.firstName || ""} ${a?.lastName || ""}`.trim();
|
||||
|
||||
const fetchRrAdvisors = (refresh = false) => {
|
||||
if (!socket) return;
|
||||
setAdvLoading(true);
|
||||
|
||||
const onResult = (payload) => {
|
||||
try {
|
||||
const list = payload?.result ?? payload ?? [];
|
||||
setAdvisors(Array.isArray(list) ? list : []);
|
||||
} finally {
|
||||
setAdvLoading(false);
|
||||
socket.off("rr-get-advisors:result", onResult);
|
||||
}
|
||||
};
|
||||
|
||||
socket.once("rr-get-advisors:result", onResult);
|
||||
socket.emit("rr-get-advisors", { departmentType: "B", refresh }, (ack) => {
|
||||
if (ack?.ok) {
|
||||
const list = ack.result ?? [];
|
||||
setAdvisors(Array.isArray(list) ? list : []);
|
||||
} else if (ack) {
|
||||
console.error("Error fetching RR Advisors:", ack.error);
|
||||
}
|
||||
setAdvLoading(false);
|
||||
socket.off("rr-get-advisors:result", onResult);
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchRrAdvisors(false);
|
||||
}, [bodyshop?.id, socket]);
|
||||
|
||||
const handleStartEarlyRO = async (values) => {
|
||||
if (!socket) {
|
||||
console.error("Socket not available");
|
||||
return;
|
||||
}
|
||||
|
||||
setIsSubmitting(true);
|
||||
|
||||
const txEnvelope = {
|
||||
advisorNo: values.advisorNo,
|
||||
story: values.story || "",
|
||||
kmin: values.kmin || job?.kmin || 0,
|
||||
opPrefix: values.opPrefix || "",
|
||||
opBase: values.opBase || "",
|
||||
opSuffix: values.opSuffix || ""
|
||||
};
|
||||
|
||||
// Emit the early RO creation request
|
||||
socket.emit("rr-create-early-ro", {
|
||||
jobId: job.id,
|
||||
txEnvelope
|
||||
});
|
||||
|
||||
// Wait for customer selection
|
||||
const customerListener = (candidates) => {
|
||||
console.log("Received rr-select-customer event with candidates:", candidates);
|
||||
setCustomerCandidates(candidates || []);
|
||||
setShowCustomerSelector(true);
|
||||
setIsSubmitting(false);
|
||||
socket.off("rr-select-customer", customerListener);
|
||||
};
|
||||
|
||||
socket.once("rr-select-customer", customerListener);
|
||||
|
||||
// Handle failures
|
||||
const failureListener = (payload) => {
|
||||
if (payload?.jobId === job.id) {
|
||||
console.error("Early RO creation failed:", payload.error);
|
||||
alert(`Failed to create early RO: ${payload.error}`);
|
||||
setIsSubmitting(false);
|
||||
setShowCustomerSelector(false);
|
||||
socket.off("export-failed", failureListener);
|
||||
socket.off("rr-select-customer", customerListener);
|
||||
}
|
||||
};
|
||||
|
||||
socket.once("export-failed", failureListener);
|
||||
};
|
||||
|
||||
const handleCustomerSelected = (custNo, createNew = false) => {
|
||||
if (!socket) return;
|
||||
|
||||
console.log("handleCustomerSelected called:", { custNo, createNew, custNoType: typeof custNo });
|
||||
|
||||
setIsSubmitting(true);
|
||||
setShowCustomerSelector(false);
|
||||
|
||||
const payload = {
|
||||
jobId: job.id,
|
||||
custNo: createNew ? null : custNo,
|
||||
create: createNew
|
||||
};
|
||||
|
||||
console.log("Emitting rr-early-customer-selected:", payload);
|
||||
|
||||
// Emit customer selection
|
||||
socket.emit("rr-early-customer-selected", payload, (ack) => {
|
||||
console.log("Received ack from rr-early-customer-selected:", ack);
|
||||
setIsSubmitting(false);
|
||||
|
||||
if (ack?.ok) {
|
||||
const roNumber = ack.dmsRoNo || ack.outsdRoNo;
|
||||
setEarlyRoCreated(true);
|
||||
setCreatedRoNumber(roNumber);
|
||||
onSuccess?.({ roNumber, ...ack });
|
||||
} else {
|
||||
alert(`Failed to create early RO: ${ack?.error || "Unknown error"}`);
|
||||
}
|
||||
});
|
||||
|
||||
// Also listen for socket events
|
||||
const successListener = (payload) => {
|
||||
if (payload?.jobId === job.id) {
|
||||
const roNumber = payload.dmsRoNo || payload.outsdRoNo;
|
||||
console.log("Early RO created:", roNumber);
|
||||
socket.off("rr-early-ro-created", successListener);
|
||||
socket.off("export-failed", failureListener);
|
||||
}
|
||||
};
|
||||
|
||||
const failureListener = (payload) => {
|
||||
if (payload?.jobId === job.id) {
|
||||
console.error("Early RO creation failed:", payload.error);
|
||||
setIsSubmitting(false);
|
||||
setEarlyRoCreated(false);
|
||||
socket.off("rr-early-ro-created", successListener);
|
||||
socket.off("export-failed", failureListener);
|
||||
}
|
||||
};
|
||||
|
||||
socket.once("rr-early-ro-created", successListener);
|
||||
socket.once("export-failed", failureListener);
|
||||
};
|
||||
|
||||
// If early RO already created, show success message
|
||||
if (earlyRoCreated) {
|
||||
return (
|
||||
<Alert
|
||||
title="Early Reynolds RO Created"
|
||||
description={`RO Number: ${createdRoNumber || "N/A"} - You can now convert the job.`}
|
||||
type="success"
|
||||
showIcon
|
||||
style={{ marginBottom: 16 }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
// If showing customer selector, render modal
|
||||
if (showCustomerSelector) {
|
||||
return (
|
||||
<>
|
||||
<Typography.Title level={5}>Create Early Reynolds RO</Typography.Title>
|
||||
<Typography.Paragraph type="secondary">Waiting for customer selection...</Typography.Paragraph>
|
||||
|
||||
<Modal
|
||||
title="Select Customer for Early RO"
|
||||
open={true}
|
||||
width={800}
|
||||
footer={null}
|
||||
onCancel={() => {
|
||||
setShowCustomerSelector(false);
|
||||
setIsSubmitting(false);
|
||||
}}
|
||||
>
|
||||
<CustomerSelectorTable
|
||||
customers={customerCandidates}
|
||||
onSelect={handleCustomerSelected}
|
||||
isSubmitting={isSubmitting}
|
||||
/>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
// Handle manual submit (since we can't nest forms)
|
||||
const handleManualSubmit = async () => {
|
||||
try {
|
||||
const values = await form.validateFields();
|
||||
handleStartEarlyRO(values);
|
||||
} catch (error) {
|
||||
console.error("Validation failed:", error);
|
||||
}
|
||||
};
|
||||
|
||||
// Show the form
|
||||
return (
|
||||
<div style={{ marginTop: 16 }}>
|
||||
<Typography.Title level={5}>Create Early Reynolds RO</Typography.Title>
|
||||
<Typography.Paragraph type="secondary" style={{ fontSize: "12px" }}>
|
||||
Complete this section to create a minimal RO in Reynolds before converting the job.
|
||||
</Typography.Paragraph>
|
||||
|
||||
<Form form={form} layout="vertical" component={false} initialValues={initialValues}>
|
||||
<Form.Item name="advisorNo" label="Advisor" rules={[{ required: true, message: "Please select an advisor" }]}>
|
||||
<Select
|
||||
showSearch={{
|
||||
optionFilterProp: "children",
|
||||
filterOption: (input, option) => (option?.children?.toLowerCase() ?? "").includes(input.toLowerCase())
|
||||
}}
|
||||
loading={advLoading}
|
||||
placeholder="Select advisor..."
|
||||
popupRender={(menu) => (
|
||||
<>
|
||||
{menu}
|
||||
<Button
|
||||
type="link"
|
||||
icon={<ReloadOutlined />}
|
||||
onClick={() => fetchRrAdvisors(true)}
|
||||
style={{ width: "100%", textAlign: "left" }}
|
||||
>
|
||||
Refresh Advisors
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
>
|
||||
{advisors.map((adv) => (
|
||||
<Select.Option key={getAdvisorNumber(adv)} value={getAdvisorNumber(adv)}>
|
||||
{getAdvisorLabel(adv)}
|
||||
</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="kmin"
|
||||
label="Mileage In"
|
||||
rules={[
|
||||
{ required: true, message: "Please enter initial mileage" },
|
||||
{ type: "number", min: 1, message: "Mileage must be greater than 0" }
|
||||
]}
|
||||
>
|
||||
<InputNumber min={1} style={{ width: "100%" }} />
|
||||
</Form.Item>
|
||||
|
||||
{/* RR OpCode (prefix / base / suffix) */}
|
||||
<Form.Item required label="RR OpCode">
|
||||
<Space.Compact block>
|
||||
<Form.Item name="opPrefix" noStyle>
|
||||
<Input allowClear maxLength={4} style={{ width: "30%" }} placeholder="Prefix" />
|
||||
</Form.Item>
|
||||
<Form.Item name="opBase" noStyle rules={[{ required: true, message: "Base Required" }]}>
|
||||
<Input allowClear maxLength={10} style={{ width: "40%" }} placeholder="Base" />
|
||||
</Form.Item>
|
||||
<Form.Item name="opSuffix" noStyle>
|
||||
<Input allowClear maxLength={4} style={{ width: "30%" }} placeholder="Suffix" />
|
||||
</Form.Item>
|
||||
</Space.Compact>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item name="story" label="Comments / Story (Optional)">
|
||||
<Input.TextArea rows={2} maxLength={240} showCount placeholder="Enter comments or story..." />
|
||||
</Form.Item>
|
||||
|
||||
<div style={{ marginTop: 16 }}>
|
||||
<Space>
|
||||
<Button type="primary" onClick={handleManualSubmit} loading={isSubmitting} disabled={advLoading}>
|
||||
Create Early RO
|
||||
</Button>
|
||||
{showCancelButton && <Button onClick={onCancel}>Cancel</Button>}
|
||||
</Space>
|
||||
</div>
|
||||
</Form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
33
client/src/components/dms-post-form/rr-early-ro-modal.jsx
Normal file
33
client/src/components/dms-post-form/rr-early-ro-modal.jsx
Normal file
@@ -0,0 +1,33 @@
|
||||
import { Modal } from "antd";
|
||||
import RREarlyROForm from "./rr-early-ro-form";
|
||||
|
||||
/**
|
||||
* Modal wrapper for RR Early RO Creation Form
|
||||
* @param open - boolean to control modal visibility
|
||||
* @param onClose - callback when modal is closed
|
||||
* @param onSuccess - callback when RO is created successfully
|
||||
* @param bodyshop - bodyshop object
|
||||
* @param socket - socket.io connection
|
||||
* @param job - job object
|
||||
* @returns {JSX.Element}
|
||||
* @constructor
|
||||
*/
|
||||
export default function RREarlyROModal({ open, onClose, onSuccess, bodyshop, socket, job }) {
|
||||
const handleSuccess = (result) => {
|
||||
onSuccess?.(result);
|
||||
onClose?.();
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
open={open}
|
||||
onCancel={onClose}
|
||||
footer={null}
|
||||
width={700}
|
||||
destroyOnHidden
|
||||
title="Create Reynolds Repair Order"
|
||||
>
|
||||
<RREarlyROForm bodyshop={bodyshop} socket={socket} job={job} onSuccess={handleSuccess} onCancel={onClose} />
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
@@ -42,11 +42,11 @@ export function JobsCloseLines({ bodyshop, job, jobRO }) {
|
||||
<tbody>
|
||||
{fields.map((field, index) => (
|
||||
<tr key={field.key}>
|
||||
{/* Hidden field to preserve jobline ID */}
|
||||
<Form.Item hidden name={[field.name, "id"]}>
|
||||
<input />
|
||||
</Form.Item>
|
||||
<td>
|
||||
{/* Hidden field to preserve jobline ID without injecting a div under <tr> */}
|
||||
<Form.Item noStyle name={[field.name, "id"]}>
|
||||
<input type="hidden" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
// label={t("joblines.fields.line_desc")}
|
||||
key={`${index}line_desc`}
|
||||
|
||||
@@ -1,18 +1,22 @@
|
||||
import { useMutation } from "@apollo/client/react";
|
||||
import { Button, Form, Input, Popover, Select, Space, Switch } from "antd";
|
||||
import { Button, Divider, Form, Input, Modal, Select, Space, Switch } from "antd";
|
||||
import axios from "axios";
|
||||
import { some } from "lodash";
|
||||
import { useCallback, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { useTreatmentsWithConfig } from "@splitsoftware/splitio-react";
|
||||
import { CONVERT_JOB_TO_RO } from "../../graphql/jobs.queries";
|
||||
import { insertAuditTrail } from "../../redux/application/application.actions";
|
||||
import { selectJobReadOnly } from "../../redux/application/application.selectors";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import AuditTrailMapping from "../../utils/AuditTrailMappings";
|
||||
import InstanceRenderManager from "../../utils/instanceRenderMgr";
|
||||
import { DMS_MAP, getDmsMode } from "../../utils/dmsUtils";
|
||||
import { useNotification } from "../../contexts/Notifications/notificationContext.jsx";
|
||||
import { useSocket } from "../../contexts/SocketIO/useSocket.js";
|
||||
import RREarlyROForm from "../dms-post-form/rr-early-ro-form";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
//currentUser: selectCurrentUser
|
||||
@@ -33,11 +37,29 @@ const mapDispatchToProps = (dispatch) => ({
|
||||
export function JobsConvertButton({ bodyshop, job, refetch, jobRO, insertAuditTrail, parentFormIsFieldsTouched }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [earlyRoCreated, setEarlyRoCreated] = useState(!!job?.dms_id); // Track early RO creation state
|
||||
const [mutationConvertJob] = useMutation(CONVERT_JOB_TO_RO);
|
||||
const { t } = useTranslation();
|
||||
const [form] = Form.useForm();
|
||||
const notification = useNotification();
|
||||
const allFormValues = Form.useWatch([], form);
|
||||
const { socket } = useSocket(); // Extract socket from context
|
||||
|
||||
// Get Fortellis treatment for proper DMS mode detection
|
||||
const {
|
||||
treatments: { Fortellis }
|
||||
} = useTreatmentsWithConfig({
|
||||
attributes: {},
|
||||
names: ["Fortellis"],
|
||||
splitKey: bodyshop?.imexshopid
|
||||
});
|
||||
|
||||
// Check if bodyshop has Reynolds integration using the proper getDmsMode function
|
||||
const dmsMode = getDmsMode(bodyshop, Fortellis.treatment);
|
||||
const isReynoldsMode = dmsMode === DMS_MAP.reynolds;
|
||||
|
||||
console.log(`2309-829038721093820938290382903`);
|
||||
console.log(isReynoldsMode);
|
||||
|
||||
const handleConvert = async ({ employee_csr, category, ...values }) => {
|
||||
if (parentFormIsFieldsTouched()) {
|
||||
@@ -82,177 +104,229 @@ export function JobsConvertButton({ bodyshop, job, refetch, jobRO, insertAuditTr
|
||||
|
||||
const submitDisabled = useCallback(() => some(allFormValues, (v) => v === undefined), [allFormValues]);
|
||||
|
||||
const popMenu = (
|
||||
<div>
|
||||
<Form
|
||||
layout="vertical"
|
||||
form={form}
|
||||
onFinish={handleConvert}
|
||||
initialValues={{
|
||||
driveable: true,
|
||||
towin: job.towin,
|
||||
ca_gst_registrant: job.ca_gst_registrant,
|
||||
employee_csr: job.employee_csr,
|
||||
category: job.category,
|
||||
referral_source: job.referral_source,
|
||||
referral_source_extra: job.referral_source_extra ?? ""
|
||||
const handleEarlyROSuccess = (result) => {
|
||||
console.log("Early RO Success - result:", result);
|
||||
setEarlyRoCreated(true); // Mark early RO as created
|
||||
notification.success({
|
||||
title: t("jobs.successes.early_ro_created", "Early RO Created"),
|
||||
message: `RO Number: ${result.roNumber || "N/A"}`
|
||||
});
|
||||
// Delay refetch to keep success message visible for 2 seconds
|
||||
setTimeout(() => {
|
||||
refetch?.();
|
||||
}, 2000);
|
||||
};
|
||||
|
||||
const handleModalClose = () => {
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
if (job.converted) return <></>;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
key="convert"
|
||||
type="primary"
|
||||
danger
|
||||
disabled={job.converted || jobRO}
|
||||
loading={loading}
|
||||
onClick={() => {
|
||||
setEarlyRoCreated(!!job?.dms_id); // Initialize state based on current job
|
||||
setOpen(true);
|
||||
}}
|
||||
>
|
||||
<Form.Item
|
||||
name={["ins_co_nm"]}
|
||||
label={t("jobs.fields.ins_co_nm")}
|
||||
rules={[
|
||||
{
|
||||
required: true
|
||||
//message: t("general.validation.required"),
|
||||
}
|
||||
]}
|
||||
{t("jobs.actions.convert")}
|
||||
</Button>
|
||||
|
||||
{/* Convert Job Modal */}
|
||||
<Modal
|
||||
open={open}
|
||||
onCancel={handleModalClose}
|
||||
closable={!(earlyRoCreated && !job.converted)} // Disable X button if early RO created but not converted
|
||||
maskClosable={!(earlyRoCreated && !job.converted)} // Disable clicking outside to close
|
||||
title={t("jobs.actions.convert")}
|
||||
footer={null}
|
||||
width={700}
|
||||
destroyOnHidden
|
||||
>
|
||||
{/* Standard Convert Form */}
|
||||
<Form
|
||||
layout="vertical"
|
||||
form={form}
|
||||
onFinish={handleConvert}
|
||||
initialValues={{
|
||||
driveable: true,
|
||||
towin: job.towin,
|
||||
ca_gst_registrant: job.ca_gst_registrant,
|
||||
employee_csr: job.employee_csr,
|
||||
category: job.category,
|
||||
referral_source: job.referral_source,
|
||||
referral_source_extra: job.referral_source_extra ?? ""
|
||||
}}
|
||||
>
|
||||
<Select showSearch>
|
||||
{bodyshop.md_ins_cos.map((s, i) => (
|
||||
<Select.Option key={i} value={s.name}>
|
||||
{s.name}
|
||||
</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
{bodyshop.enforce_class && (
|
||||
{/* Show Reynolds Early RO section at the top if applicable */}
|
||||
{isReynoldsMode && !job.dms_id && !earlyRoCreated && (
|
||||
<>
|
||||
<RREarlyROForm
|
||||
bodyshop={bodyshop}
|
||||
socket={socket}
|
||||
job={job}
|
||||
onSuccess={handleEarlyROSuccess}
|
||||
showCancelButton={false}
|
||||
/>
|
||||
<Divider />
|
||||
</>
|
||||
)}
|
||||
|
||||
<Form.Item
|
||||
name={"class"}
|
||||
label={t("jobs.fields.class")}
|
||||
name={["ins_co_nm"]}
|
||||
label={t("jobs.fields.ins_co_nm")}
|
||||
rules={[
|
||||
{
|
||||
required: bodyshop.enforce_class
|
||||
required: true
|
||||
//message: t("general.validation.required"),
|
||||
}
|
||||
]}
|
||||
>
|
||||
<Select>
|
||||
{bodyshop.md_classes.map((s) => (
|
||||
<Select.Option key={s} value={s}>
|
||||
{s}
|
||||
<Select showSearch>
|
||||
{bodyshop.md_ins_cos.map((s, i) => (
|
||||
<Select.Option key={i} value={s.name}>
|
||||
{s.name}
|
||||
</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
)}
|
||||
{bodyshop.enforce_referral && (
|
||||
<>
|
||||
{bodyshop.enforce_class && (
|
||||
<Form.Item
|
||||
name={"referral_source"}
|
||||
label={t("jobs.fields.referralsource")}
|
||||
name={"class"}
|
||||
label={t("jobs.fields.class")}
|
||||
rules={[
|
||||
{
|
||||
required: bodyshop.enforce_referral
|
||||
required: bodyshop.enforce_class
|
||||
//message: t("general.validation.required"),
|
||||
}
|
||||
]}
|
||||
>
|
||||
<Select>
|
||||
{bodyshop.md_referral_sources.map((s) => (
|
||||
{bodyshop.md_classes.map((s) => (
|
||||
<Select.Option key={s} value={s}>
|
||||
{s}
|
||||
</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label={t("jobs.fields.referral_source_extra")} name="referral_source_extra">
|
||||
<Input />
|
||||
</Form.Item>
|
||||
</>
|
||||
)}
|
||||
{bodyshop.enforce_conversion_csr && (
|
||||
<Form.Item
|
||||
name={"employee_csr"}
|
||||
label={t(
|
||||
InstanceRenderManager({
|
||||
imex: "jobs.fields.employee_csr",
|
||||
rome: "jobs.fields.employee_csr_writer"
|
||||
})
|
||||
)}
|
||||
rules={[
|
||||
{
|
||||
required: bodyshop.enforce_conversion_csr
|
||||
//message: t("general.validation.required"),
|
||||
}
|
||||
]}
|
||||
>
|
||||
<Select
|
||||
showSearch={{
|
||||
optionFilterProp: "children",
|
||||
filterOption: (input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
|
||||
}}
|
||||
style={{ width: 200 }}
|
||||
)}
|
||||
{bodyshop.enforce_referral && (
|
||||
<>
|
||||
<Form.Item
|
||||
name={"referral_source"}
|
||||
label={t("jobs.fields.referralsource")}
|
||||
rules={[
|
||||
{
|
||||
required: bodyshop.enforce_referral
|
||||
//message: t("general.validation.required"),
|
||||
}
|
||||
]}
|
||||
>
|
||||
<Select>
|
||||
{bodyshop.md_referral_sources.map((s) => (
|
||||
<Select.Option key={s} value={s}>
|
||||
{s}
|
||||
</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label={t("jobs.fields.referral_source_extra")} name="referral_source_extra">
|
||||
<Input />
|
||||
</Form.Item>
|
||||
</>
|
||||
)}
|
||||
{bodyshop.enforce_conversion_csr && (
|
||||
<Form.Item
|
||||
name={"employee_csr"}
|
||||
label={t(
|
||||
InstanceRenderManager({
|
||||
imex: "jobs.fields.employee_csr",
|
||||
rome: "jobs.fields.employee_csr_writer"
|
||||
})
|
||||
)}
|
||||
rules={[
|
||||
{
|
||||
required: bodyshop.enforce_conversion_csr
|
||||
//message: t("general.validation.required"),
|
||||
}
|
||||
]}
|
||||
>
|
||||
{bodyshop.employees
|
||||
.filter((emp) => emp.active)
|
||||
.map((emp) => (
|
||||
<Select.Option value={emp.id} key={emp.id} name={`${emp.first_name} ${emp.last_name}`}>
|
||||
{`${emp.first_name} ${emp.last_name}`}
|
||||
<Select
|
||||
showSearch={{
|
||||
optionFilterProp: "children",
|
||||
filterOption: (input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
|
||||
}}
|
||||
style={{ width: 200 }}
|
||||
>
|
||||
{bodyshop.employees
|
||||
.filter((emp) => emp.active)
|
||||
.map((emp) => (
|
||||
<Select.Option value={emp.id} key={emp.id} name={`${emp.first_name} ${emp.last_name}`}>
|
||||
{`${emp.first_name} ${emp.last_name}`}
|
||||
</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
)}
|
||||
{bodyshop.enforce_conversion_category && (
|
||||
<Form.Item
|
||||
name={"category"}
|
||||
label={t("jobs.fields.category")}
|
||||
rules={[
|
||||
{
|
||||
required: bodyshop.enforce_conversion_category
|
||||
//message: t("general.validation.required"),
|
||||
}
|
||||
]}
|
||||
>
|
||||
<Select allowClear>
|
||||
{bodyshop.md_categories.map((s) => (
|
||||
<Select.Option key={s} value={s}>
|
||||
{s}
|
||||
</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
)}
|
||||
{bodyshop.enforce_conversion_category && (
|
||||
<Form.Item
|
||||
name={"category"}
|
||||
label={t("jobs.fields.category")}
|
||||
rules={[
|
||||
{
|
||||
required: bodyshop.enforce_conversion_category
|
||||
//message: t("general.validation.required"),
|
||||
}
|
||||
]}
|
||||
>
|
||||
<Select allowClear>
|
||||
{bodyshop.md_categories.map((s) => (
|
||||
<Select.Option key={s} value={s}>
|
||||
{s}
|
||||
</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
)}
|
||||
{bodyshop.region_config.toLowerCase().startsWith("ca") && (
|
||||
<Form.Item label={t("jobs.fields.ca_gst_registrant")} name="ca_gst_registrant" valuePropName="checked">
|
||||
</Select>
|
||||
</Form.Item>
|
||||
)}
|
||||
{bodyshop.region_config.toLowerCase().startsWith("ca") && (
|
||||
<Form.Item label={t("jobs.fields.ca_gst_registrant")} name="ca_gst_registrant" valuePropName="checked">
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
)}
|
||||
<Form.Item label={t("jobs.fields.driveable")} name="driveable" valuePropName="checked">
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
<Form.Item label={t("jobs.fields.towin")} name="towin" valuePropName="checked">
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
)}
|
||||
<Form.Item label={t("jobs.fields.driveable")} name="driveable" valuePropName="checked">
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
<Form.Item label={t("jobs.fields.towin")} name="towin" valuePropName="checked">
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
<Space wrap>
|
||||
<Button disabled={submitDisabled()} type="primary" danger onClick={() => form.submit()} loading={loading}>
|
||||
{t("jobs.actions.convert")}
|
||||
</Button>
|
||||
<Button onClick={() => setOpen(false)}>{t("general.actions.close")}</Button>
|
||||
</Space>
|
||||
</Form>
|
||||
</div>
|
||||
);
|
||||
|
||||
if (job.converted) return <></>;
|
||||
|
||||
return (
|
||||
<Popover open={open} content={popMenu}>
|
||||
<Button
|
||||
key="convert"
|
||||
type="primary"
|
||||
danger
|
||||
// style={{ display: job.converted ? "none" : "" }}
|
||||
disabled={job.converted || jobRO}
|
||||
loading={loading}
|
||||
onClick={() => {
|
||||
setOpen(true);
|
||||
}}
|
||||
>
|
||||
{t("jobs.actions.convert")}
|
||||
</Button>
|
||||
</Popover>
|
||||
<Space wrap style={{ marginTop: 16 }}>
|
||||
<Button
|
||||
disabled={submitDisabled() || (isReynoldsMode && !job.dms_id && !earlyRoCreated)}
|
||||
type="primary"
|
||||
danger
|
||||
onClick={() => form.submit()}
|
||||
loading={loading}
|
||||
>
|
||||
{t("jobs.actions.convert")}
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleModalClose}
|
||||
disabled={earlyRoCreated && !job.converted}
|
||||
>
|
||||
{t("general.actions.close")}
|
||||
</Button>
|
||||
</Space>
|
||||
</Form>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -470,6 +470,9 @@ export const GET_JOB_BY_PK = gql`
|
||||
clm_total
|
||||
comment
|
||||
converted
|
||||
dms_id
|
||||
dms_customer_id
|
||||
dms_advisor_id
|
||||
csiinvites {
|
||||
completedon
|
||||
id
|
||||
@@ -2216,6 +2219,9 @@ export const QUERY_JOB_EXPORT_DMS = gql`
|
||||
plate_no
|
||||
plate_st
|
||||
ownr_co_nm
|
||||
dms_id
|
||||
dms_customer_id
|
||||
dms_advisor_id
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -486,6 +486,7 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
||||
|
||||
<DmsCustomerSelector
|
||||
jobid={jobId}
|
||||
job={data?.jobs_by_pk}
|
||||
bodyshop={bodyshop}
|
||||
socket={activeSocket}
|
||||
mode={mode}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { useQuery } from "@apollo/client/react";
|
||||
import { Card, Col, Result, Row, Space, Typography } from "antd";
|
||||
import { useEffect } from "react";
|
||||
import { Button, Card, Col, Result, Row, Space, Typography } from "antd";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { useTreatmentsWithConfig } from "@splitsoftware/splitio-react";
|
||||
import AlertComponent from "../../components/alert/alert.component";
|
||||
import JobCalculateTotals from "../../components/job-calculate-totals/job-calculate-totals.component";
|
||||
import ScoreboardAddButton from "../../components/job-scoreboard-add-button/job-scoreboard-add-button.component";
|
||||
@@ -19,10 +20,20 @@ import JobsAdminRemoveAR from "../../components/jobs-admin-remove-ar/jobs-admin-
|
||||
import LoadingSpinner from "../../components/loading-spinner/loading-spinner.component";
|
||||
import NotFound from "../../components/not-found/not-found.component";
|
||||
import RbacWrapper from "../../components/rbac-wrapper/rbac-wrapper.component";
|
||||
import RREarlyROModal from "../../components/dms-post-form/rr-early-ro-modal";
|
||||
import { GET_JOB_BY_PK } from "../../graphql/jobs.queries";
|
||||
import { setBreadcrumbs, setSelectedHeader } from "../../redux/application/application.actions";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { useSocket } from "../../contexts/SocketIO/useSocket";
|
||||
import { useNotification } from "../../contexts/Notifications/notificationContext";
|
||||
import { DMS_MAP, getDmsMode } from "../../utils/dmsUtils";
|
||||
import InstanceRenderManager from "../../utils/instanceRenderMgr";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop
|
||||
});
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
setBreadcrumbs: (breadcrumbs) => dispatch(setBreadcrumbs(breadcrumbs)),
|
||||
setSelectedHeader: (key) => dispatch(setSelectedHeader(key))
|
||||
@@ -39,14 +50,31 @@ const cardStyle = {
|
||||
height: "100%"
|
||||
};
|
||||
|
||||
export function JobsCloseContainer({ setBreadcrumbs, setSelectedHeader }) {
|
||||
export function JobsCloseContainer({ setBreadcrumbs, setSelectedHeader, bodyshop }) {
|
||||
const { jobId } = useParams();
|
||||
const { loading, error, data } = useQuery(GET_JOB_BY_PK, {
|
||||
const { loading, error, data, refetch } = useQuery(GET_JOB_BY_PK, {
|
||||
variables: { id: jobId },
|
||||
fetchPolicy: "network-only",
|
||||
nextFetchPolicy: "network-only"
|
||||
});
|
||||
const { t } = useTranslation();
|
||||
const { socket } = useSocket(); // Extract socket from context
|
||||
const notification = useNotification();
|
||||
const [showEarlyROModal, setShowEarlyROModal] = useState(false);
|
||||
|
||||
// Get Fortellis treatment for proper DMS mode detection
|
||||
const {
|
||||
treatments: { Fortellis }
|
||||
} = useTreatmentsWithConfig({
|
||||
attributes: {},
|
||||
names: ["Fortellis"],
|
||||
splitKey: bodyshop?.imexshopid
|
||||
});
|
||||
|
||||
// Check if bodyshop has Reynolds integration using the proper getDmsMode function
|
||||
const dmsMode = getDmsMode(bodyshop, Fortellis.treatment);
|
||||
const isReynoldsMode = dmsMode === DMS_MAP.reynolds;
|
||||
const job = data?.jobs_by_pk;
|
||||
useEffect(() => {
|
||||
setSelectedHeader("activejobs");
|
||||
document.title = t("titles.jobs-admin", {
|
||||
@@ -75,6 +103,15 @@ export function JobsCloseContainer({ setBreadcrumbs, setSelectedHeader }) {
|
||||
]);
|
||||
}, [setBreadcrumbs, t, jobId, data, setSelectedHeader]);
|
||||
|
||||
const handleEarlyROSuccess = (result) => {
|
||||
notification.success({
|
||||
title: t("jobs.successes.early_ro_created", "Early RO Created"),
|
||||
message: `RO Number: ${result.roNumber || "N/A"}`
|
||||
});
|
||||
setShowEarlyROModal(false);
|
||||
refetch?.();
|
||||
};
|
||||
|
||||
if (loading) return <LoadingSpinner />;
|
||||
if (error) return <AlertComponent title={error.message} type="error" />;
|
||||
if (!data.jobs_by_pk) return <NotFound />;
|
||||
@@ -99,6 +136,11 @@ export function JobsCloseContainer({ setBreadcrumbs, setSelectedHeader }) {
|
||||
<JobsAdminUnvoid job={data ? data.jobs_by_pk : {}} />
|
||||
<JobsAdminStatus job={data ? data.jobs_by_pk : {}} />
|
||||
<JobsAdminRemoveAR job={data ? data.jobs_by_pk : {}} />
|
||||
{isReynoldsMode && job?.converted && !job?.dms_id && !job?.dms_customer_id && !job?.dms_advisor_id && (
|
||||
<Button className="ant-btn ant-btn-default" onClick={() => setShowEarlyROModal(true)}>
|
||||
Create RR RO
|
||||
</Button>
|
||||
)}
|
||||
</Space>
|
||||
</Card>
|
||||
</Col>
|
||||
@@ -124,8 +166,18 @@ export function JobsCloseContainer({ setBreadcrumbs, setSelectedHeader }) {
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
{/* Early RO Modal */}
|
||||
<RREarlyROModal
|
||||
open={showEarlyROModal}
|
||||
onClose={() => setShowEarlyROModal(false)}
|
||||
onSuccess={handleEarlyROSuccess}
|
||||
bodyshop={bodyshop}
|
||||
socket={socket}
|
||||
job={job}
|
||||
/>
|
||||
</RbacWrapper>
|
||||
);
|
||||
}
|
||||
|
||||
export default connect(null, mapDispatchToProps)(JobsCloseContainer);
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(JobsCloseContainer);
|
||||
|
||||
@@ -1818,7 +1818,11 @@
|
||||
"sale": "Sale",
|
||||
"sale_dms_acctnumber": "Sale DMS Acct #",
|
||||
"story": "Story",
|
||||
"vinowner": "VIN Owner"
|
||||
"vinowner": "VIN Owner",
|
||||
"rr_opcode": "RR OpCode",
|
||||
"rr_opcode_prefix": "Prefix",
|
||||
"rr_opcode_suffix": "Suffix",
|
||||
"rr_opcode_base": "Base"
|
||||
},
|
||||
"dms_allocation": "DMS Allocation",
|
||||
"driveable": "Driveable",
|
||||
|
||||
@@ -1818,7 +1818,11 @@
|
||||
"sale": "",
|
||||
"sale_dms_acctnumber": "",
|
||||
"story": "",
|
||||
"vinowner": ""
|
||||
"vinowner": "",
|
||||
"rr_opcode": "",
|
||||
"rr_opcode_prefix": "",
|
||||
"rr_opcode_suffix": "",
|
||||
"rr_opcode_base": ""
|
||||
},
|
||||
"dms_allocation": "",
|
||||
"driveable": "",
|
||||
|
||||
@@ -1818,7 +1818,11 @@
|
||||
"sale": "",
|
||||
"sale_dms_acctnumber": "",
|
||||
"story": "",
|
||||
"vinowner": ""
|
||||
"vinowner": "",
|
||||
"rr_opcode": "",
|
||||
"rr_opcode_prefix": "",
|
||||
"rr_opcode_suffix": "",
|
||||
"rr_opcode_base": ""
|
||||
},
|
||||
"dms_allocation": "",
|
||||
"driveable": "",
|
||||
|
||||
Reference in New Issue
Block a user