@pagamio/frontend-commons-lib 0.8.342 → 0.8.343

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.
@@ -22,6 +22,12 @@ interface DrawerContentProps {
22
22
  processingDependencyRef?: React.MutableRefObject<boolean>;
23
23
  pendingUpdatesRef?: React.MutableRefObject<Map<string, unknown>>;
24
24
  persistenceKey?: string;
25
+ /**
26
+ * When true, persisted form data is wiped whenever the drawer transitions
27
+ * from open → closed. Use for one-shot create/register flows where the
28
+ * next open should start blank.
29
+ */
30
+ clearOnClose?: boolean;
25
31
  /** Ref updated every render with current dirty state — read by FormEngineDrawer for X-button check. */
26
32
  isDirtyRef?: React.MutableRefObject<boolean>;
27
33
  /** Ref updated every render with handleCancel — call from outside (e.g. X button) to show the same unsaved-changes modal. */
@@ -5,7 +5,7 @@ import { Button, NotificationModal } from '../../components';
5
5
  import { useToast } from '../../context';
6
6
  import { FieldWrapper } from '../../form-engine';
7
7
  import { useFormPersistence } from '../../form-engine/hooks/useFormPersistence';
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, isDirtyRef, cancelRef, }) => {
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
11
  // Determine initial values: initialValues take precedence over persisted data
@@ -39,6 +39,21 @@ const DrawerContent = ({ fields, onSubmit, isOpen, initialValues, submitButtonTe
39
39
  mountInitialValuesRef.current = initialValues || {};
40
40
  }
41
41
  wasOpenRef.current = !!isOpen;
42
+ // Clear persisted data on every open → close transition when the consumer
43
+ // opts in. Covers cancel, X, ESC, programmatic close, and post-submit close
44
+ // — all routes the user can take out of the drawer.
45
+ const clearOnCloseRef = useRef(clearOnClose);
46
+ clearOnCloseRef.current = clearOnClose;
47
+ const clearPersistedDataRef = useRef(clearPersistedData);
48
+ clearPersistedDataRef.current = clearPersistedData;
49
+ const previousIsOpenRef = useRef(!!isOpen);
50
+ useEffect(() => {
51
+ const wasOpen = previousIsOpenRef.current;
52
+ previousIsOpenRef.current = !!isOpen;
53
+ if (wasOpen && !isOpen && clearOnCloseRef.current) {
54
+ clearPersistedDataRef.current();
55
+ }
56
+ }, [isOpen]);
42
57
  const password = watch('password');
43
58
  const allFields = watch();
44
59
  // Function to check if there are unsaved changes
@@ -16,6 +16,14 @@ interface FormEngineDrawerProps {
16
16
  onFieldUpdate?: Record<string, DependentFieldUpdate[]>;
17
17
  onFieldChange?: (fieldName: string, value: unknown) => void;
18
18
  persistenceKey?: string;
19
+ /**
20
+ * When true, persisted form data is wiped whenever the drawer transitions
21
+ * from open → closed (cancel, X, ESC, programmatic close, successful submit).
22
+ * Default `false` preserves the original "resume a half-filled form" behaviour.
23
+ * Set to `true` for one-shot create/register flows where the next open should
24
+ * start blank — e.g. a "register device" or "deploy terminal" drawer.
25
+ */
26
+ clearOnClose?: boolean;
19
27
  }
20
28
  declare const FormEngineDrawer: React.FC<FormEngineDrawerProps>;
21
29
  export default FormEngineDrawer;
@@ -2,7 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useEffect, useRef, useState } from 'react';
3
3
  import BaseDrawer from './components/BaseDrawer';
4
4
  import DrawerContent from './components/DrawerContent';
5
- const FormEngineDrawer = ({ title, cancelButtonText = 'Cancel', submitButtonText = 'Submit', showForm = true, showDrawerButtons = true, isOpen, fields: initialFields, initialValues, children, marginTop = '0px', onClose, onSubmit, onFieldUpdate, onFieldChange, persistenceKey, }) => {
5
+ const FormEngineDrawer = ({ title, cancelButtonText = 'Cancel', submitButtonText = 'Submit', showForm = true, showDrawerButtons = true, isOpen, fields: initialFields, initialValues, children, marginTop = '0px', onClose, onSubmit, onFieldUpdate, onFieldChange, persistenceKey, clearOnClose = false, }) => {
6
6
  const [fields, setFields] = useState(initialFields);
7
7
  const initializedRef = useRef(false);
8
8
  const processingDependencyRef = useRef(false);
@@ -133,6 +133,6 @@ const FormEngineDrawer = ({ title, cancelButtonText = 'Cancel', submitButtonText
133
133
  processingDependencyRef.current = false;
134
134
  }
135
135
  };
136
- return (_jsx(BaseDrawer, { title: title, isOpen: isOpen, marginTop: marginTop, onClose: onClose, onCloseAttempt: () => cancelRef.current(), children: _jsx(DrawerContent, { isOpen: isOpen, fields: fields, onSubmit: onSubmit, handleCloseDrawer: onClose, initialValues: initialValues, showForm: showForm, showDrawerButtons: showDrawerButtons, cancelButtonText: cancelButtonText, submitButtonText: submitButtonText, onFieldUpdate: onFieldUpdate, onFieldChange: onFieldChange, updateFieldOptions: updateFieldOptions, updateFieldLabel: updateFieldLabel, setFieldHidden: setFieldHidden, addField: addField, updateFieldValidation: updateFieldValidation, processInitialFieldUpdates: processInitialFieldUpdates, processingDependencyRef: processingDependencyRef, pendingUpdatesRef: pendingUpdatesRef, persistenceKey: persistenceKey, cancelRef: cancelRef, children: children }, persistenceKey || 'drawer-content') }));
136
+ return (_jsx(BaseDrawer, { title: title, isOpen: isOpen, marginTop: marginTop, onClose: onClose, onCloseAttempt: () => cancelRef.current(), children: _jsx(DrawerContent, { isOpen: isOpen, fields: fields, onSubmit: onSubmit, handleCloseDrawer: onClose, initialValues: initialValues, showForm: showForm, showDrawerButtons: showDrawerButtons, cancelButtonText: cancelButtonText, submitButtonText: submitButtonText, onFieldUpdate: onFieldUpdate, onFieldChange: onFieldChange, updateFieldOptions: updateFieldOptions, updateFieldLabel: updateFieldLabel, setFieldHidden: setFieldHidden, addField: addField, updateFieldValidation: updateFieldValidation, processInitialFieldUpdates: processInitialFieldUpdates, processingDependencyRef: processingDependencyRef, pendingUpdatesRef: pendingUpdatesRef, persistenceKey: persistenceKey, clearOnClose: clearOnClose, cancelRef: cancelRef, children: children }, persistenceKey || 'drawer-content') }));
137
137
  };
138
138
  export default FormEngineDrawer;
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.342",
4
+ "version": "0.8.343",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "provenance": false