From 95c6dbdc60d6317ed1d6dd5553b15593fb5052c0 Mon Sep 17 00:00:00 2001 From: Tony CABAYE Date: Mon, 2 Dec 2024 12:00:30 +0100 Subject: [PATCH] =?UTF-8?q?fix(pyramide):=20probl=C3=A8me=20de=20validatio?= =?UTF-8?q?n=20des=20attributs=20lors=20de=20la=20cr=C3=A9ation=20#355?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/tms/tables/TableAttributeSelection.tsx | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/assets/entrepot/pages/service/tms/tables/TableAttributeSelection.tsx b/assets/entrepot/pages/service/tms/tables/TableAttributeSelection.tsx index 9e25fc4b..4b95f77f 100644 --- a/assets/entrepot/pages/service/tms/tables/TableAttributeSelection.tsx +++ b/assets/entrepot/pages/service/tms/tables/TableAttributeSelection.tsx @@ -18,10 +18,9 @@ const TableAttributeSelection: FC = ({ visible, fo setValue: setFormValue, getValues: getFormValues, formState: { errors }, - watch, } = form; - const tableAttributes: Record = watch("table_attributes") ?? {}; + const tableAttributes: Record = getFormValues("table_attributes") ?? {}; useEffect(() => { const prevTableAttributes = getFormValues("table_attributes") ?? {}; @@ -33,9 +32,8 @@ const TableAttributeSelection: FC = ({ visible, fo setFormValue("table_attributes", tableAttributes); }, [getFormValues, setFormValue, selectedTables]); - const toggleAttributes = (tableName: string, attrName: string) => { - const prevTableAttributes = { ...tableAttributes }; - let tableAttr: string[] = prevTableAttributes[tableName]; + const toggleAttributes = (tableName: string, attrName: string, tableAttributes: string[]) => { + let tableAttr = [...tableAttributes]; if (tableAttr.includes(attrName)) { tableAttr = tableAttr.filter((el) => el !== attrName); @@ -44,9 +42,7 @@ const TableAttributeSelection: FC = ({ visible, fo tableAttr = Array.from(new Set(tableAttr)); } - prevTableAttributes[tableName] = tableAttr; - - setFormValue("table_attributes", { ...prevTableAttributes }, { shouldValidate: true }); + setFormValue(`table_attributes.${tableName}`, tableAttr, { shouldValidate: true }); }; return ( @@ -67,7 +63,7 @@ const TableAttributeSelection: FC = ({ visible, fo nativeInputProps: { value: attrName, checked: tableAttributes?.[table.name]?.includes(attrName) ?? false, - onChange: () => toggleAttributes(table.name, attrName), + onChange: () => toggleAttributes(table.name, attrName, tableAttributes[table.name]), }, }))} state={errors?.table_attributes?.[table.name]?.message ? "error" : "default"}