feature/IO-1710-prevent-duplicate-ins-companies
This commit is contained in:
@@ -934,6 +934,8 @@ export function ShopInfoGeneral({ form, bodyshop }) {
|
||||
}}
|
||||
</Form.List>
|
||||
</LayoutFormRow>
|
||||
|
||||
{/*Start Insurance Provider Row */}
|
||||
<LayoutFormRow
|
||||
grow
|
||||
header={<span id="insurancecos-header">{t("bodyshop.labels.insurancecos")}</span>}
|
||||
@@ -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();
|
||||
}
|
||||
})
|
||||
]}
|
||||
>
|
||||
<Input />
|
||||
@@ -1031,6 +1053,8 @@ export function ShopInfoGeneral({ form, bodyshop }) {
|
||||
}}
|
||||
</Form.List>
|
||||
</LayoutFormRow>
|
||||
{/*End Insurance Provider Row */}
|
||||
|
||||
<LayoutFormRow grow header={t("bodyshop.labels.estimators")} id="estimators">
|
||||
<Form.List name={["md_estimators"]}>
|
||||
{(fields, { add, remove, move }) => {
|
||||
|
||||
Reference in New Issue
Block a user