@trackunit/react-form-wizard 0.1.70 → 0.1.71
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 +8 -5
- package/index.esm.js +9 -6
- package/package.json +1 -1
package/index.cjs.js
CHANGED
|
@@ -275,7 +275,12 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
275
275
|
});
|
|
276
276
|
setSubmitHandlerInternal(() => wrappedCallbackFunction);
|
|
277
277
|
}, [setSubmitHandlerInternal]);
|
|
278
|
-
const
|
|
278
|
+
const isEmptyStep = sharedUtils.objectKeys(form.getValues()).length === 0;
|
|
279
|
+
const emptyStepSubmitHandler = react.useCallback((e) => {
|
|
280
|
+
e === null || e === void 0 ? void 0 : e.preventDefault();
|
|
281
|
+
submitHandlerInternal === null || submitHandlerInternal === void 0 ? void 0 : submitHandlerInternal(fullFormState);
|
|
282
|
+
}, [fullFormState, submitHandlerInternal]);
|
|
283
|
+
const nonEmptyStepSubmitHandler = react.useMemo(() => form.handleSubmit((data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
279
284
|
//? This state is not updated for the submit handler below; therefore, there is duplication.
|
|
280
285
|
setFullFormState(prev => (Object.assign(Object.assign({}, prev), { [stepKey]: data })));
|
|
281
286
|
if (isLastStep) {
|
|
@@ -296,10 +301,8 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
296
301
|
stepKey,
|
|
297
302
|
submitHandlerInternal,
|
|
298
303
|
]);
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
stepSubmitHandler();
|
|
302
|
-
}, ref: formRef, children: [jsxRuntime.jsx(FormWizardHeader, { title, description }), jsxRuntime.jsx("div", { className: cvaFormWizardComponentContainer({ className: containerClassName }), children: component({
|
|
304
|
+
const handleSubmit = react.useMemo(() => (isEmptyStep ? emptyStepSubmitHandler : nonEmptyStepSubmitHandler), [emptyStepSubmitHandler, isEmptyStep, nonEmptyStepSubmitHandler]);
|
|
305
|
+
return (jsxRuntime.jsxs("form", { className: cvaFormWizardComponentStepForm(), onSubmit: handleSubmit, ref: formRef, children: [jsxRuntime.jsx(FormWizardHeader, { title, description }), jsxRuntime.jsx("div", { className: cvaFormWizardComponentContainer({ className: containerClassName }), children: component({
|
|
303
306
|
form,
|
|
304
307
|
fullForm,
|
|
305
308
|
setSubmitHandler: isLastStep ? setSubmitHandler : null,
|
package/index.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { registerTranslations, useNamespaceTranslation } from '@trackunit/i18n-library-translation';
|
|
3
3
|
import { Link, useNavigate, useParams } from '@tanstack/react-router';
|
|
4
|
-
import { objectFromEntries, objectEntries,
|
|
4
|
+
import { objectKeys, objectFromEntries, objectEntries, objectValues } from '@trackunit/shared-utils';
|
|
5
5
|
import { useState, useRef, useEffect, useCallback, useMemo } from 'react';
|
|
6
6
|
import { cvaMerge } from '@trackunit/css-class-variance-utilities';
|
|
7
7
|
import { Icon, Button, Heading } from '@trackunit/react-components';
|
|
@@ -271,7 +271,12 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
271
271
|
});
|
|
272
272
|
setSubmitHandlerInternal(() => wrappedCallbackFunction);
|
|
273
273
|
}, [setSubmitHandlerInternal]);
|
|
274
|
-
const
|
|
274
|
+
const isEmptyStep = objectKeys(form.getValues()).length === 0;
|
|
275
|
+
const emptyStepSubmitHandler = useCallback((e) => {
|
|
276
|
+
e === null || e === void 0 ? void 0 : e.preventDefault();
|
|
277
|
+
submitHandlerInternal === null || submitHandlerInternal === void 0 ? void 0 : submitHandlerInternal(fullFormState);
|
|
278
|
+
}, [fullFormState, submitHandlerInternal]);
|
|
279
|
+
const nonEmptyStepSubmitHandler = useMemo(() => form.handleSubmit((data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
275
280
|
//? This state is not updated for the submit handler below; therefore, there is duplication.
|
|
276
281
|
setFullFormState(prev => (Object.assign(Object.assign({}, prev), { [stepKey]: data })));
|
|
277
282
|
if (isLastStep) {
|
|
@@ -292,10 +297,8 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
292
297
|
stepKey,
|
|
293
298
|
submitHandlerInternal,
|
|
294
299
|
]);
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
stepSubmitHandler();
|
|
298
|
-
}, ref: formRef, children: [jsx(FormWizardHeader, { title, description }), jsx("div", { className: cvaFormWizardComponentContainer({ className: containerClassName }), children: component({
|
|
300
|
+
const handleSubmit = useMemo(() => (isEmptyStep ? emptyStepSubmitHandler : nonEmptyStepSubmitHandler), [emptyStepSubmitHandler, isEmptyStep, nonEmptyStepSubmitHandler]);
|
|
301
|
+
return (jsxs("form", { className: cvaFormWizardComponentStepForm(), onSubmit: handleSubmit, ref: formRef, children: [jsx(FormWizardHeader, { title, description }), jsx("div", { className: cvaFormWizardComponentContainer({ className: containerClassName }), children: component({
|
|
299
302
|
form,
|
|
300
303
|
fullForm,
|
|
301
304
|
setSubmitHandler: isLastStep ? setSubmitHandler : null,
|