@trackunit/react-compound-components 1.4.19 → 1.4.22

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.
package/index.cjs.js CHANGED
@@ -69,11 +69,28 @@ const ConfirmationDialogModal = ({ title, message, handlePrimaryActionClick, han
69
69
  };
70
70
 
71
71
  /**
72
+ * Helper that resolves the promise with the given action and immediately clears the resolver to prevent double resolution
72
73
  *
74
+ * Prevents scenarios where both a button click and modal auto-close would resolve the same promise
75
+ */
76
+ const resolveAndClear = (resolveAction, setResolveAction, action) => {
77
+ if (resolveAction) {
78
+ resolveAction(action);
79
+ setResolveAction(null);
80
+ }
81
+ };
82
+ /**
83
+ * ConfirmationDialogContextProvider
84
+ *
85
+ * Provides confirmation dialog context and manages modal state with Promise-based resolution
73
86
  */
74
87
  const ConfirmationDialogContextProvider = ({ children }) => {
75
88
  const [t] = useTranslation();
76
- const modal = reactModal.useModal();
89
+ const modal = reactModal.useModal({
90
+ onClose: () => {
91
+ resolveAndClear(resolveAction, setResolveAction, "CLOSE");
92
+ },
93
+ });
77
94
  const [resolveAction, setResolveAction] = react.useState(null);
78
95
  const [confirmationDialogProps, setConfirmationDialogProps] = react.useState({
79
96
  title: t("confirmationDialog.default.title"),
@@ -85,14 +102,14 @@ const ConfirmationDialogContextProvider = ({ children }) => {
85
102
  const confirmationDialogModalProps = react.useMemo(() => ({
86
103
  ...confirmationDialogProps,
87
104
  handlePrimaryActionClick: () => {
88
- resolveAction?.("PRIMARY");
105
+ resolveAndClear(resolveAction, setResolveAction, "PRIMARY");
89
106
  modal.close();
90
107
  },
91
108
  handleSecondaryActionClick: () => {
92
- resolveAction?.("SECONDARY");
109
+ resolveAndClear(resolveAction, setResolveAction, "SECONDARY");
93
110
  modal.close();
94
111
  },
95
- }), [confirmationDialogProps, resolveAction, modal]);
112
+ }), [confirmationDialogProps, resolveAction, setResolveAction, modal]);
96
113
  const confirm = react.useCallback(async (props) => {
97
114
  setConfirmationDialogProps(prev => ({ ...prev, ...props }));
98
115
  modal.open();
package/index.esm.js CHANGED
@@ -67,11 +67,28 @@ const ConfirmationDialogModal = ({ title, message, handlePrimaryActionClick, han
67
67
  };
68
68
 
69
69
  /**
70
+ * Helper that resolves the promise with the given action and immediately clears the resolver to prevent double resolution
70
71
  *
72
+ * Prevents scenarios where both a button click and modal auto-close would resolve the same promise
73
+ */
74
+ const resolveAndClear = (resolveAction, setResolveAction, action) => {
75
+ if (resolveAction) {
76
+ resolveAction(action);
77
+ setResolveAction(null);
78
+ }
79
+ };
80
+ /**
81
+ * ConfirmationDialogContextProvider
82
+ *
83
+ * Provides confirmation dialog context and manages modal state with Promise-based resolution
71
84
  */
72
85
  const ConfirmationDialogContextProvider = ({ children }) => {
73
86
  const [t] = useTranslation();
74
- const modal = useModal();
87
+ const modal = useModal({
88
+ onClose: () => {
89
+ resolveAndClear(resolveAction, setResolveAction, "CLOSE");
90
+ },
91
+ });
75
92
  const [resolveAction, setResolveAction] = useState(null);
76
93
  const [confirmationDialogProps, setConfirmationDialogProps] = useState({
77
94
  title: t("confirmationDialog.default.title"),
@@ -83,14 +100,14 @@ const ConfirmationDialogContextProvider = ({ children }) => {
83
100
  const confirmationDialogModalProps = useMemo(() => ({
84
101
  ...confirmationDialogProps,
85
102
  handlePrimaryActionClick: () => {
86
- resolveAction?.("PRIMARY");
103
+ resolveAndClear(resolveAction, setResolveAction, "PRIMARY");
87
104
  modal.close();
88
105
  },
89
106
  handleSecondaryActionClick: () => {
90
- resolveAction?.("SECONDARY");
107
+ resolveAndClear(resolveAction, setResolveAction, "SECONDARY");
91
108
  modal.close();
92
109
  },
93
- }), [confirmationDialogProps, resolveAction, modal]);
110
+ }), [confirmationDialogProps, resolveAction, setResolveAction, modal]);
94
111
  const confirm = useCallback(async (props) => {
95
112
  setConfirmationDialogProps(prev => ({ ...prev, ...props }));
96
113
  modal.open();
package/package.json CHANGED
@@ -1,21 +1,21 @@
1
1
  {
2
2
  "name": "@trackunit/react-compound-components",
3
- "version": "1.4.19",
3
+ "version": "1.4.22",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "dependencies": {
7
7
  "react": "19.0.0",
8
8
  "tailwind-merge": "^2.0.0",
9
9
  "react-image-gallery": "1.3.0",
10
- "@trackunit/react-core-contexts-api": "1.5.12",
11
- "@trackunit/react-core-hooks": "1.4.12",
12
- "@trackunit/react-components": "1.5.16",
13
- "@trackunit/react-modal": "1.4.17",
14
- "@trackunit/css-class-variance-utilities": "1.4.10",
15
- "@trackunit/date-and-time-utils": "1.4.10",
16
- "@trackunit/react-form-components": "1.4.19",
17
- "@trackunit/i18n-library-translation": "1.4.13",
18
- "@trackunit/react-test-setup": "1.1.10"
10
+ "@trackunit/react-core-contexts-api": "1.5.14",
11
+ "@trackunit/react-core-hooks": "1.4.14",
12
+ "@trackunit/react-components": "1.5.18",
13
+ "@trackunit/react-modal": "1.4.19",
14
+ "@trackunit/css-class-variance-utilities": "1.4.12",
15
+ "@trackunit/date-and-time-utils": "1.4.12",
16
+ "@trackunit/react-form-components": "1.4.21",
17
+ "@trackunit/i18n-library-translation": "1.4.15",
18
+ "@trackunit/react-test-setup": "1.1.12"
19
19
  },
20
20
  "engines": {
21
21
  "node": ">=22.x",
@@ -3,6 +3,8 @@ export interface ConfirmationDialogProviderProps {
3
3
  children: ReactNode;
4
4
  }
5
5
  /**
6
+ * ConfirmationDialogContextProvider
6
7
  *
8
+ * Provides confirmation dialog context and manages modal state with Promise-based resolution
7
9
  */
8
10
  export declare const ConfirmationDialogContextProvider: ({ children }: ConfirmationDialogProviderProps) => import("react/jsx-runtime").JSX.Element;