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:
Dave
2025-11-13 11:18:11 -05:00
parent 577c3bec04
commit 09ea6dff2b
32 changed files with 1747 additions and 1411 deletions

View 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;