From 546238830e9fb6956c30205ff1e85cfba52df6e6 Mon Sep 17 00:00:00 2001 From: mkurczewski Date: Mon, 9 Dec 2024 11:09:49 +0100 Subject: [PATCH] Improved form implementation for contacts import list --- libs/generic-view/models/src/lib/form.ts | 1 - .../ui/src/lib/generated/mc-contacts-view.ts | 5 --- .../interactive/form/input/checkbox-input.tsx | 13 ++++--- .../import-contacts/import-contacts-list.tsx | 35 +++---------------- .../import-contacts/import-contacts.tsx | 11 +++++- 5 files changed, 23 insertions(+), 42 deletions(-) diff --git a/libs/generic-view/models/src/lib/form.ts b/libs/generic-view/models/src/lib/form.ts index 1c4901b526..dac1c2057c 100644 --- a/libs/generic-view/models/src/lib/form.ts +++ b/libs/generic-view/models/src/lib/form.ts @@ -22,7 +22,6 @@ const configValidator: z.ZodType = z reValidateMode: z.enum(["onChange", "onBlur", "onSubmit"]).optional(), defaultValues: z.record(z.string(), z.any()).optional(), }), - defaultValues: z.record(z.string(), z.any()).optional(), }) .optional() diff --git a/libs/generic-view/ui/src/lib/generated/mc-contacts-view.ts b/libs/generic-view/ui/src/lib/generated/mc-contacts-view.ts index a9eed190b2..820243649e 100644 --- a/libs/generic-view/ui/src/lib/generated/mc-contacts-view.ts +++ b/libs/generic-view/ui/src/lib/generated/mc-contacts-view.ts @@ -36,11 +36,6 @@ export const generateMcContactsView: ComponentGenerator = ( activeContactId: null, }, }, - defaultValues: { - selectedContacts: [], - allContacts: [], - searchedContact: "", - }, }, childrenKeys: ["contactsLoader"], }, diff --git a/libs/generic-view/ui/src/lib/interactive/form/input/checkbox-input.tsx b/libs/generic-view/ui/src/lib/interactive/form/input/checkbox-input.tsx index 728a497335..72b1df1f3a 100644 --- a/libs/generic-view/ui/src/lib/interactive/form/input/checkbox-input.tsx +++ b/libs/generic-view/ui/src/lib/interactive/form/input/checkbox-input.tsx @@ -77,6 +77,14 @@ export const CheckboxInput: APIFC = ({ [config, fieldRegistrar, getValues, inputName, multiSelect, setValue] ) + const handleRef = useCallback( + (e: HTMLInputElement) => { + inputRef.current = e + fieldRegistrar.ref(e) + }, + [fieldRegistrar] + ) + useEffect(() => { if (multiSelect) { if (multiSelect.selectedValues.length === multiSelect.allValues.length) { @@ -108,10 +116,7 @@ export const CheckboxInput: APIFC = ({ disabled={config.disabled} {...fieldRegistrar} onChange={handleChange} - ref={(e) => { - inputRef.current = e - fieldRegistrar.ref(e) - }} + ref={handleRef} />