feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration -Cleaned up DMS key check (consolidated into a helper function), Clean up DMS post form and make it agnostic, same with customer selector.
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
export const determineDmsType = (bodyshop) => {
|
||||
const dmsMapping = {
|
||||
cdk_dealerid: "cdk",
|
||||
pbs_serialnumber: "pbs",
|
||||
rr_dealerid: "rr"
|
||||
};
|
||||
|
||||
return Object.keys(dmsMapping).find((key) => bodyshop[key])
|
||||
? dmsMapping[Object.keys(dmsMapping).find((key) => bodyshop[key])]
|
||||
: "pbs";
|
||||
};
|
||||
72
client/src/utils/dmsUtils.js
Normal file
72
client/src/utils/dmsUtils.js
Normal file
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* DMS type mapping constants.
|
||||
* CAREFUL: the values here are used as canonical "mode" strings elsewhere in the app.
|
||||
* @type {{reynolds: string, cdk: string, pbs: string, fortellis: string}}
|
||||
*/
|
||||
export const DMS_MAP = {
|
||||
reynolds: "rr",
|
||||
cdk: "cdk",
|
||||
pbs: "pbs",
|
||||
fortellis: "fortellis"
|
||||
};
|
||||
|
||||
/**
|
||||
* Determines the DMS type for a given bodyshop object.
|
||||
* @param bodyshop
|
||||
* @returns {*|string}
|
||||
*/
|
||||
export const determineDMSTypeByBodyshop = (bodyshop) => {
|
||||
const dmsMapping = {
|
||||
cdk_dealerid: DMS_MAP.cdk,
|
||||
pbs_serialnumber: DMS_MAP.pbs,
|
||||
rr_dealerid: DMS_MAP.reynolds
|
||||
};
|
||||
|
||||
return Object.keys(dmsMapping).find((key) => bodyshop[key])
|
||||
? dmsMapping[Object.keys(dmsMapping).find((key) => bodyshop[key])]
|
||||
: DMS_MAP.pbs;
|
||||
};
|
||||
|
||||
/**
|
||||
* Determines the translation key for a given DMS type.
|
||||
* @param dmsType
|
||||
* @returns {*|string}
|
||||
*/
|
||||
export const determineDmsTypeTranslationKey = (dmsType) => {
|
||||
const dmsTypeMapping = {
|
||||
[DMS_MAP.cdk]: "bodyshop.labels.dms.cdk",
|
||||
[DMS_MAP.pbs]: "bodyshop.labels.dms.pbs",
|
||||
[DMS_MAP.reynolds]: "bodyshop.labels.dms.rr"
|
||||
};
|
||||
|
||||
return dmsTypeMapping[dmsType] || dmsTypeMapping[DMS_MAP.pbs];
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a normalized "mode" we can switch on:
|
||||
* @param bodyshop
|
||||
* @param fortellisTreatment
|
||||
* @returns {*|string|string}
|
||||
*/
|
||||
export const getDmsMode = (bodyshop, fortellisTreatment) => {
|
||||
const base = determineDMSTypeByBodyshop(bodyshop); // "rr" | "cdk" | "pbs" | undefined
|
||||
if (base === DMS_MAP.cdk && fortellisTreatment === "on") return DMS_MAP.fortellis;
|
||||
return base ?? "none";
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if the DMS mode uses WSS.
|
||||
* @param mode
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export const isWssMode = (mode) => {
|
||||
return mode === DMS_MAP.reynolds || mode === DMS_MAP.fortellis;
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if the bodyshop has any DMS key configured.
|
||||
* @param bodyshop
|
||||
* @returns {*|string}
|
||||
*/
|
||||
export const bodyshopHasDmsKey = (bodyshop) =>
|
||||
bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid;
|
||||
16
client/src/utils/legacySocket.js
Normal file
16
client/src/utils/legacySocket.js
Normal file
@@ -0,0 +1,16 @@
|
||||
// client/src/utils/legacySocket.js
|
||||
import SocketIO from "socket.io-client";
|
||||
import { auth } from "../firebase/firebase.utils";
|
||||
|
||||
// Create once, reuse everywhere.
|
||||
const legacySocket = SocketIO(import.meta.env.PROD ? import.meta.env.VITE_APP_AXIOS_BASE_API_URL : "", {
|
||||
path: "/ws",
|
||||
withCredentials: true,
|
||||
autoConnect: false,
|
||||
auth: async (callback) => {
|
||||
const token = auth.currentUser && (await auth.currentUser.getIdToken());
|
||||
callback({ token });
|
||||
}
|
||||
});
|
||||
|
||||
export default legacySocket;
|
||||
Reference in New Issue
Block a user