From 155d0af5090858bbb2e5f77a4e09ab5b6e59a77f Mon Sep 17 00:00:00 2001 From: Dave Date: Tue, 30 Dec 2025 12:54:27 -0500 Subject: [PATCH] feature/IO-1710-prevent-duplicate-ins-companies --- .../shop-info/shop-info.general.component.jsx | 26 ++++++++++++++++++- client/src/translations/en_us/common.json | 3 ++- client/src/translations/es/common.json | 3 ++- client/src/translations/fr/common.json | 3 ++- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/client/src/components/shop-info/shop-info.general.component.jsx b/client/src/components/shop-info/shop-info.general.component.jsx index acf553bb5..955b8c217 100644 --- a/client/src/components/shop-info/shop-info.general.component.jsx +++ b/client/src/components/shop-info/shop-info.general.component.jsx @@ -934,6 +934,8 @@ export function ShopInfoGeneral({ form, bodyshop }) { }} + + {/*Start Insurance Provider Row */} {t("bodyshop.labels.insurancecos")}} @@ -950,11 +952,31 @@ export function ShopInfoGeneral({ form, bodyshop }) { label={t("bodyshop.fields.md_ins_co.name")} key={`${index}name`} name={[field.name, "name"]} + dependencies={[["md_ins_cos"]]} rules={[ { required: true //message: t("general.validation.required"), - } + }, + ({ getFieldValue }) => ({ + validator: async (_, value) => { + const normalizedValue = (value ?? "").toString().trim().toLowerCase(); + if (!normalizedValue) return Promise.resolve(); // handled by required + + const list = getFieldValue(["md_ins_cos"]) || []; + const normalizedNames = list + .map((c) => (c?.name ?? "").toString().trim().toLowerCase()) + .filter(Boolean); + + const count = normalizedNames.filter((n) => n === normalizedValue).length; + + if (count > 1) { + throw new Error(t("bodyshop.errors.duplicate_insurance_company")); + } + + return Promise.resolve(); + } + }) ]} > @@ -1031,6 +1053,8 @@ export function ShopInfoGeneral({ form, bodyshop }) { }} + {/*End Insurance Provider Row */} + {(fields, { add, remove, move }) => { diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index f79a1f166..efddd03a7 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -277,7 +277,8 @@ "errors": { "creatingdefaultview": "Error creating default view.", "loading": "Unable to load shop details. Please call technical support.", - "saving": "Error encountered while saving. {{message}}" + "saving": "Error encountered while saving. {{message}}", + "duplicate_insurance_company": "Duplicate insurance company name. Each insurance company name must be unique" }, "fields": { "ReceivableCustomField": "QBO Receivable Custom Field {{number}}", diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json index 2a9a6229b..8e3b313e4 100644 --- a/client/src/translations/es/common.json +++ b/client/src/translations/es/common.json @@ -277,7 +277,8 @@ "errors": { "creatingdefaultview": "", "loading": "No se pueden cargar los detalles de la tienda. Por favor llame al soporte técnico.", - "saving": "" + "saving": "", + "duplicate_insurance_company": "" }, "fields": { "ReceivableCustomField": "", diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json index 939f7752e..e60898129 100644 --- a/client/src/translations/fr/common.json +++ b/client/src/translations/fr/common.json @@ -277,7 +277,8 @@ "errors": { "creatingdefaultview": "", "loading": "Impossible de charger les détails de la boutique. Veuillez appeler le support technique.", - "saving": "" + "saving": "", + "duplicate_insurance_company": "" }, "fields": { "ReceivableCustomField": "",