@pagamio/frontend-commons-lib 0.8.344 → 0.8.345
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -8,32 +8,38 @@ import { useFormPersistence } from '../../form-engine/hooks/useFormPersistence';
|
|
|
8
8
|
const DrawerContent = ({ fields, onSubmit, isOpen, initialValues, submitButtonText = 'Submit', cancelButtonText = 'Cancel', showForm = true, showDrawerButtons = true, handleCloseDrawer, onFieldUpdate, onFieldChange, children, updateFieldOptions, updateFieldLabel, setFieldHidden, addField, updateFieldValidation, processInitialFieldUpdates, processingDependencyRef, pendingUpdatesRef, persistenceKey, clearOnClose = false, isDirtyRef, cancelRef, }) => {
|
|
9
9
|
const { saveFormData, restoreFormData, clearPersistedData, hasPersistedData } = useFormPersistence(persistenceKey);
|
|
10
10
|
const { addToast } = useToast();
|
|
11
|
-
//
|
|
12
|
-
// controlled
|
|
13
|
-
// unspecified fields
|
|
14
|
-
//
|
|
15
|
-
//
|
|
11
|
+
// For clearOnClose drawers, seed an `{ fieldName: '' }` baseline so every
|
|
12
|
+
// registered input starts controlled with a defined string value. Without
|
|
13
|
+
// this, RHF leaves unspecified fields as `undefined`, and Radix Select
|
|
14
|
+
// refuses to update its visual state when we reset on close — the
|
|
15
|
+
// controlled→uncontrolled transition is the bug we're fixing.
|
|
16
|
+
// We intentionally only seed empties when clearOnClose is true: legacy
|
|
17
|
+
// drawers that relied on `undefined`-vs-`""` distinctions in their submit
|
|
18
|
+
// payload (e.g. "field omitted means don't update") keep their exact
|
|
19
|
+
// previous behaviour.
|
|
16
20
|
const emptyFieldValues = useMemo(() => {
|
|
21
|
+
if (!clearOnClose)
|
|
22
|
+
return undefined;
|
|
17
23
|
const acc = {};
|
|
18
24
|
for (const f of fields) {
|
|
19
25
|
acc[f.name] = '';
|
|
20
26
|
}
|
|
21
27
|
return acc;
|
|
22
|
-
}, [fields]);
|
|
28
|
+
}, [clearOnClose, fields]);
|
|
23
29
|
// Determine initial values: initialValues take precedence over persisted data.
|
|
24
30
|
// For clearOnClose drawers we always start from the empty baseline so a
|
|
25
31
|
// stale persistence entry from a previous lifetime can't leak in.
|
|
26
32
|
const getEffectiveInitialValues = () => {
|
|
27
33
|
if (initialValues && Object.keys(initialValues).length > 0) {
|
|
28
|
-
return { ...emptyFieldValues, ...initialValues };
|
|
34
|
+
return emptyFieldValues ? { ...emptyFieldValues, ...initialValues } : initialValues;
|
|
29
35
|
}
|
|
30
36
|
if (!clearOnClose && persistenceKey && hasPersistedData()) {
|
|
31
37
|
const persistedData = restoreFormData();
|
|
32
38
|
if (persistedData) {
|
|
33
|
-
return
|
|
39
|
+
return persistedData;
|
|
34
40
|
}
|
|
35
41
|
}
|
|
36
|
-
return emptyFieldValues;
|
|
42
|
+
return emptyFieldValues ?? initialValues ?? {};
|
|
37
43
|
};
|
|
38
44
|
const { control, handleSubmit, watch, setValue, clearErrors, formState: { errors, isSubmitting }, reset, getValues, } = useForm({ mode: 'onBlur', defaultValues: getEffectiveInitialValues() });
|
|
39
45
|
const [pendingUpdateCount, setPendingUpdateCount] = useState(0);
|
|
@@ -68,7 +74,7 @@ const DrawerContent = ({ fields, onSubmit, isOpen, initialValues, submitButtonTe
|
|
|
68
74
|
previousIsOpenRef.current = !!isOpen;
|
|
69
75
|
if (wasOpen && !isOpen && clearOnCloseRef.current) {
|
|
70
76
|
clearPersistedDataRef.current();
|
|
71
|
-
resetRef.current(emptyFieldValuesRef.current);
|
|
77
|
+
resetRef.current(emptyFieldValuesRef.current ?? {});
|
|
72
78
|
}
|
|
73
79
|
}, [isOpen]);
|
|
74
80
|
const password = watch('password');
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pagamio/frontend-commons-lib",
|
|
3
3
|
"description": "Pagamio library for Frontend reusable components like the form engine and table container",
|
|
4
|
-
"version": "0.8.
|
|
4
|
+
"version": "0.8.345",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
7
7
|
"provenance": false
|