IO-233 WIP CDK
This commit is contained in:
@@ -0,0 +1,79 @@
|
|||||||
|
import React, { useEffect, useState } from "react";
|
||||||
|
import { socket } from "../../pages/dms/dms.container";
|
||||||
|
import { alphaSort } from "../../utils/sorters";
|
||||||
|
import { Table } from "antd";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
|
export default function DmsCustomerSelector() {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [customerList, setcustomerList] = useState([]);
|
||||||
|
const [selectedCustomer, setSelectedCustomer] = useState(null);
|
||||||
|
useEffect(() => {
|
||||||
|
socket.on("cdk-select-customer", (customerList) => {
|
||||||
|
setcustomerList(customerList);
|
||||||
|
console.log("Received a customer list.", customerList);
|
||||||
|
});
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
socket.removeListener("cdk-select-customer");
|
||||||
|
};
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
title: t("owners.fields.ownr_ln"),
|
||||||
|
dataIndex: "ownr_ln",
|
||||||
|
key: "ownr_ln",
|
||||||
|
sorter: (a, b) => alphaSort(a.ownr_ln, b.ownr_ln),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: t("owners.fields.ownr_fn"),
|
||||||
|
dataIndex: "ownr_fn",
|
||||||
|
key: "ownr_fn",
|
||||||
|
sorter: (a, b) => alphaSort(a.ownr_fn, b.ownr_fn),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: t("owners.fields.ownr_co_nm"),
|
||||||
|
dataIndex: "ownr_co_nm",
|
||||||
|
key: "ownr_co_nm",
|
||||||
|
sorter: (a, b) => alphaSort(a.ownr_co_nm, b.ownr_co_nm),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: t("owners.fields.ownr_addr1"),
|
||||||
|
dataIndex: "ownr_addr1",
|
||||||
|
key: "ownr_addr1",
|
||||||
|
sorter: (a, b) => alphaSort(a.ownr_addr1, b.ownr_addr1),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: t("owners.fields.ownr_city"),
|
||||||
|
dataIndex: "ownr_city",
|
||||||
|
key: "ownr_city",
|
||||||
|
sorter: (a, b) => alphaSort(a.ownr_city, b.ownr_city),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: t("owners.fields.ownr_ea"),
|
||||||
|
dataIndex: "ownr_ea",
|
||||||
|
key: "ownr_ea",
|
||||||
|
sorter: (a, b) => alphaSort(a.ownr_ea, b.ownr_ea),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Table
|
||||||
|
//scroll={{ x: true }}
|
||||||
|
pagination={{ position: "top" }}
|
||||||
|
columns={columns}
|
||||||
|
rowKey="id.value"
|
||||||
|
dataSource={customerList}
|
||||||
|
//onChange={handleTableChange}
|
||||||
|
rowSelection={{
|
||||||
|
onSelect: (props) => {
|
||||||
|
setSelectedCustomer(props.id);
|
||||||
|
},
|
||||||
|
type: "radio",
|
||||||
|
selectedRowKeys: [selectedCustomer],
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Result, Timeline, Space, Tag, Divider, Button } from "antd";
|
import { Result, Timeline, Space, Tag, Divider, Button, Select } from "antd";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
@@ -11,6 +11,7 @@ import { useTranslation } from "react-i18next";
|
|||||||
import SocketIO from "socket.io-client";
|
import SocketIO from "socket.io-client";
|
||||||
import { auth } from "../../firebase/firebase.utils";
|
import { auth } from "../../firebase/firebase.utils";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
|
import DmsCustomerSelector from "../../components/dms-customer-selector/dms-customer-selector.component";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
@@ -38,6 +39,7 @@ export const socket = SocketIO(
|
|||||||
|
|
||||||
export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader }) {
|
export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const [logLevel, setLogLevel] = useState("DEBUG");
|
||||||
const [logs, setLogs] = useState([]);
|
const [logs, setLogs] = useState([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -57,7 +59,16 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader }) {
|
|||||||
});
|
});
|
||||||
socket.on("reconnect", () => {
|
socket.on("reconnect", () => {
|
||||||
console.log("Connected again.");
|
console.log("Connected again.");
|
||||||
setLogs([]);
|
setLogs((logs) => {
|
||||||
|
return [
|
||||||
|
...logs,
|
||||||
|
{
|
||||||
|
timestamp: new Date(),
|
||||||
|
level: "WARNING",
|
||||||
|
message: "Reconnected to CDK Export Service",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("log-event", (payload) => {
|
socket.on("log-event", (payload) => {
|
||||||
@@ -67,12 +78,13 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader }) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.connect();
|
socket.connect();
|
||||||
socket.emit("set-log-level", "TRACE");
|
socket.emit("set-log-level", logLevel);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
socket.removeAllListeners();
|
socket.removeAllListeners();
|
||||||
socket.disconnect();
|
socket.disconnect();
|
||||||
};
|
};
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
if (!bodyshop.cdk_dealerid) return <Result status="404" />;
|
if (!bodyshop.cdk_dealerid) return <Result status="404" />;
|
||||||
@@ -81,27 +93,43 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Button
|
<Space>
|
||||||
onClick={() => {
|
<Select
|
||||||
socket.emit(
|
placeholder="Log Level"
|
||||||
`${dmsType}-export-job`,
|
value={logLevel}
|
||||||
"752a4f5f-22ab-414b-b182-98d4e62227ef"
|
onChange={(value) => {
|
||||||
);
|
setLogLevel(value);
|
||||||
}}
|
socket.emit("set-log-level", value);
|
||||||
>
|
}}
|
||||||
Export
|
>
|
||||||
</Button>
|
<Select.Option>TRACE</Select.Option>
|
||||||
|
<Select.Option>DEBUG</Select.Option>
|
||||||
<Button
|
<Select.Option>INFO</Select.Option>
|
||||||
onClick={() => {
|
<Select.Option>WARNING</Select.Option>
|
||||||
setLogs([]);
|
<Select.Option>ERROR</Select.Option>
|
||||||
socket.disconnect();
|
</Select>
|
||||||
socket.connect();
|
<Button
|
||||||
}}
|
onClick={() => {
|
||||||
>
|
socket.emit(
|
||||||
reconnect
|
`${dmsType}-export-job`,
|
||||||
</Button>
|
"752a4f5f-22ab-414b-b182-98d4e62227ef"
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Export
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
setLogs([]);
|
||||||
|
socket.disconnect();
|
||||||
|
socket.connect();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Reconnect
|
||||||
|
</Button>
|
||||||
|
<Button onClick={() => setLogs([])}>Clear Logs</Button>
|
||||||
|
</Space>
|
||||||
|
<DmsCustomerSelector />
|
||||||
<Timeline pending={socket.connected && "Processing..."} reverse={true}>
|
<Timeline pending={socket.connected && "Processing..."} reverse={true}>
|
||||||
{logs.map((log, idx) => (
|
{logs.map((log, idx) => (
|
||||||
<Timeline.Item key={idx} color={LogLevelHierarchy(log.level)}>
|
<Timeline.Item key={idx} color={LogLevelHierarchy(log.level)}>
|
||||||
|
|||||||
@@ -44,13 +44,13 @@ exports.default = async function (socket, jobid) {
|
|||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"DEBUG",
|
"DEBUG",
|
||||||
`{1.2} clVFV DMSVid does *not* exist. clVFV: ${JSON.stringify(
|
`{1.2} clVFV DMSVid does *not* exist.`
|
||||||
clVFV,
|
);
|
||||||
null,
|
CdkBase.createLogEvent(
|
||||||
2
|
socket,
|
||||||
)}`
|
"TRACE",
|
||||||
|
`{1.2} clVFV: ${JSON.stringify(clVFV, null, 2)}`
|
||||||
);
|
);
|
||||||
|
|
||||||
//Check if DMSCustId is Empty - which it should always be?
|
//Check if DMSCustId is Empty - which it should always be?
|
||||||
//{6.6} Should check to see if a customer exists so that we can marry it to the new vehicle.
|
//{6.6} Should check to see if a customer exists so that we can marry it to the new vehicle.
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
@@ -65,12 +65,30 @@ exports.default = async function (socket, jobid) {
|
|||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"DEBUG",
|
"DEBUG",
|
||||||
`{8.2} Customer ID(s) found. strIDS: ${JSON.stringify(
|
`{8.2} ${strIDS.length} Customer ID(s) found.`
|
||||||
strIDS,
|
|
||||||
null,
|
|
||||||
2
|
|
||||||
)}`
|
|
||||||
);
|
);
|
||||||
|
CdkBase.createLogEvent(
|
||||||
|
socket,
|
||||||
|
"TRACE",
|
||||||
|
`{8.2} strIDS: ${JSON.stringify(strIDS, null, 2)}`
|
||||||
|
);
|
||||||
|
if (strIDS.length > 1) {
|
||||||
|
//We have multiple IDs
|
||||||
|
//TODO: Do we need to let the person select it?
|
||||||
|
CdkBase.createLogEvent(
|
||||||
|
socket,
|
||||||
|
"WARNING",
|
||||||
|
`{F} Mutliple customer ids have been found (${strIDS.length})`
|
||||||
|
);
|
||||||
|
CdkBase.createLogEvent(
|
||||||
|
socket,
|
||||||
|
"DEBUG",
|
||||||
|
`Asking for user intervention to select customer.`
|
||||||
|
);
|
||||||
|
socket.emit("cdk-select-customer", strIDS);
|
||||||
|
|
||||||
|
//TOOD: Need to find a way to wait and determine which customer to use.
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
@@ -94,22 +112,20 @@ exports.default = async function (socket, jobid) {
|
|||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"DEBUG",
|
"DEBUG",
|
||||||
`{11.1} New Customer inserted. customer: ${JSON.stringify(
|
`{11.1} New Customer inserted.`
|
||||||
clADPC,
|
);
|
||||||
null,
|
CdkBase.createLogEvent(
|
||||||
2
|
socket,
|
||||||
)}`
|
"TRACE",
|
||||||
|
`{11.1} clADPC: ${JSON.stringify(clADPC, null, 2)}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
CdkBase.createLogEvent(socket, "DEBUG", `{1.1} clVFV DMSVid does exist.`);
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"DEBUG",
|
"TRACE",
|
||||||
`{1.1} clVFV DMSVid does exist. clVFV: ${JSON.stringify(
|
`{1.1} clVFV: ${JSON.stringify(clVFV, null, 2)}`
|
||||||
clVFV,
|
|
||||||
null,
|
|
||||||
2
|
|
||||||
)}`
|
|
||||||
);
|
);
|
||||||
|
|
||||||
//{2} Begin Find Vehicle in DMS
|
//{2} Begin Find Vehicle in DMS
|
||||||
@@ -121,22 +137,24 @@ exports.default = async function (socket, jobid) {
|
|||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"DEBUG",
|
"DEBUG",
|
||||||
`{1.4} Vehicle was found in the DMS. clADPV: ${JSON.stringify(
|
`{1.4} Vehicle was found in the DMS.`
|
||||||
clADPV,
|
);
|
||||||
null,
|
CdkBase.createLogEvent(
|
||||||
2
|
socket,
|
||||||
)}`
|
"TRACE",
|
||||||
|
`{1.4} clADPV: ${JSON.stringify(clADPV, null, 2)}`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
//Vehicle was not found.
|
//Vehicle was not found.
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"DEBUG",
|
"DEBUG",
|
||||||
`{6.4} Vehicle does not exist in DMS. Will have to create one. clVFV: ${JSON.stringify(
|
`{6.4} Vehicle does not exist in DMS. Will have to create one.`
|
||||||
clVFV,
|
);
|
||||||
null,
|
CdkBase.createLogEvent(
|
||||||
2
|
socket,
|
||||||
)}`
|
"TRACE",
|
||||||
|
`{6.4} clVFV: ${JSON.stringify(clVFV, null, 2)}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -167,7 +185,7 @@ async function QueryJobData(socket, jobid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function CreateCustomerInDms(socket, JobData, newCustomerNumber) {
|
async function CreateCustomerInDms(socket, JobData, newCustomerNumber) {
|
||||||
CdkBase.createLogEvent(socket, "DEBUG", `{10} Begin Create Customer in DMS`);
|
CdkBase.createLogEvent(socket, "DEBUG", `{11} Begin Create Customer in DMS`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const soapClientCustomerInsertUpdate = await soap.createClientAsync(
|
const soapClientCustomerInsertUpdate = await soap.createClientAsync(
|
||||||
@@ -209,8 +227,9 @@ async function CreateCustomerInDms(socket, JobData, newCustomerNumber) {
|
|||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
CheckCdkResponseForError(socket, soapResponseCustomerInsertUpdate);
|
CheckCdkResponseForError(socket, soapResponseCustomerInsertUpdate);
|
||||||
const [result, rawResponse, soapheader, rawRequest] =
|
const [
|
||||||
soapResponseCustomerInsertUpdate;
|
result, //rawResponse, soapheader, rawRequest
|
||||||
|
] = soapResponseCustomerInsertUpdate;
|
||||||
|
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
@@ -303,7 +322,7 @@ async function FindCustomerIdFromDms(socket, JobData) {
|
|||||||
arg0: CDK_CREDENTIALS,
|
arg0: CDK_CREDENTIALS,
|
||||||
arg1: { dealerId: JobData.bodyshop.cdk_dealerid }, //TODO: Verify why this does not follow the other standards.
|
arg1: { dealerId: JobData.bodyshop.cdk_dealerid }, //TODO: Verify why this does not follow the other standards.
|
||||||
arg2: {
|
arg2: {
|
||||||
// verb: "EXACT",
|
verb: "EXACT",
|
||||||
key: ownerName,
|
key: ownerName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -363,17 +382,6 @@ async function FindVehicleInDms(socket, JobData, clVFV) {
|
|||||||
const [
|
const [
|
||||||
result, //rawResponse, soapheader, rawRequest
|
result, //rawResponse, soapheader, rawRequest
|
||||||
] = soapResponseVehicleInsertUpdate;
|
] = soapResponseVehicleInsertUpdate;
|
||||||
//result format
|
|
||||||
// return: [
|
|
||||||
// {
|
|
||||||
// code: 'success',
|
|
||||||
// carInvStockNo: '',
|
|
||||||
// errorLevel: '0',
|
|
||||||
// errorMessage: '',
|
|
||||||
// newId: 'Y',
|
|
||||||
// vehiclesVehId: 'HM263407'
|
|
||||||
// }
|
|
||||||
// ]
|
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"TRACE",
|
"TRACE",
|
||||||
@@ -420,17 +428,6 @@ async function CalculateDmsVid(socket, JobData) {
|
|||||||
const [
|
const [
|
||||||
result, //rawResponse, soapheader, rawRequest
|
result, //rawResponse, soapheader, rawRequest
|
||||||
] = soapResponseVehicleInsertUpdate;
|
] = soapResponseVehicleInsertUpdate;
|
||||||
//result format
|
|
||||||
// return: [
|
|
||||||
// {
|
|
||||||
// code: 'success',
|
|
||||||
// carInvStockNo: '',
|
|
||||||
// errorLevel: '0',
|
|
||||||
// errorMessage: '',
|
|
||||||
// newId: 'Y',
|
|
||||||
// vehiclesVehId: 'HM263407'
|
|
||||||
// }
|
|
||||||
// ]
|
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"TRACE",
|
"TRACE",
|
||||||
@@ -465,14 +462,21 @@ function CheckCdkResponseForError(socket, soapResponse) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ResultToCheck = Array.isArray(soapResponse[0] && soapResponse[0].return)
|
const ResultToCheck = soapResponse[0].return;
|
||||||
? soapResponse[0].return[0]
|
|
||||||
: soapResponse[0].return;
|
|
||||||
|
|
||||||
|
if (Array.isArray(ResultToCheck)) {
|
||||||
|
ResultToCheck.forEach((result) => checkIndividualResult(socket, result));
|
||||||
|
} else {
|
||||||
|
checkIndividualResult(socket, ResultToCheck);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkIndividualResult(socket, ResultToCheck) {
|
||||||
if (
|
if (
|
||||||
ResultToCheck.errorLevel === 0 ||
|
ResultToCheck.errorLevel === 0 ||
|
||||||
ResultToCheck.errorLevel === "0" ||
|
ResultToCheck.errorLevel === "0" ||
|
||||||
ResultToCheck.code === "success"
|
ResultToCheck.code === "success" ||
|
||||||
|
(!ResultToCheck.code && !ResultToCheck.errorLevel)
|
||||||
)
|
)
|
||||||
//TODO: Verify that this is the best way to detect errors.
|
//TODO: Verify that this is the best way to detect errors.
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user