@trackunit/react-form-wizard 0.1.6 → 0.1.11
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 +12 -5
- package/index.esm.js +13 -6
- package/package.json +1 -1
- package/src/FormWizardFooter/FormWizardFooter.d.ts +2 -1
- package/translation.cjs.js +3 -3
- package/translation.cjs10.js +3 -3
- package/translation.cjs13.js +3 -3
- package/translation.cjs4.js +3 -3
- package/translation.cjs9.js +3 -3
- package/translation.esm.js +3 -3
- package/translation.esm10.js +3 -3
- package/translation.esm13.js +3 -3
- package/translation.esm4.js +3 -3
- package/translation.esm9.js +3 -3
package/index.cjs.js
CHANGED
|
@@ -200,9 +200,9 @@ const cvaNavigationContainer = cssClassVarianceUtilities.cvaMerge(["flex", "gap-
|
|
|
200
200
|
* The footer component for the FormWizard.
|
|
201
201
|
* In most cases you should not be using this component directly, but rather use the FormWizard component.
|
|
202
202
|
*/
|
|
203
|
-
const FormWizardFooter = ({ onBack, onCancel, primaryActionLabel = "Next" }) => {
|
|
203
|
+
const FormWizardFooter = ({ disablePrimaryAction = false, onBack, onCancel, primaryActionLabel = "Next", }) => {
|
|
204
204
|
const [t] = useTranslation();
|
|
205
|
-
return (jsxRuntime.jsxs("div", { className: cvaFooterContainer(), children: [jsxRuntime.jsx(reactComponents.Button, { dataTestId: "wizard-cancel", onClick: onCancel, variant: "ghost-neutral", children: t("wizard.defaults.cancel") }), jsxRuntime.jsxs("div", { className: cvaNavigationContainer(), children: [onBack ? (jsxRuntime.jsx(reactComponents.Button, { dataTestId: "wizard-back", onClick: onBack, variant: "secondary", children: t("wizard.defaults.back") })) : null, jsxRuntime.jsx(reactComponents.Button, { dataTestId: "wizard-next", type: "submit", children: primaryActionLabel ? primaryActionLabel : t("wizard.defaults.next") })] })] }));
|
|
205
|
+
return (jsxRuntime.jsxs("div", { className: cvaFooterContainer(), children: [jsxRuntime.jsx(reactComponents.Button, { dataTestId: "wizard-cancel", onClick: onCancel, variant: "ghost-neutral", children: t("wizard.defaults.cancel") }), jsxRuntime.jsxs("div", { className: cvaNavigationContainer(), children: [onBack ? (jsxRuntime.jsx(reactComponents.Button, { dataTestId: "wizard-back", onClick: onBack, variant: "secondary", children: t("wizard.defaults.back") })) : null, jsxRuntime.jsx(reactComponents.Button, { dataTestId: "wizard-next", disabled: disablePrimaryAction, type: "submit", children: primaryActionLabel ? primaryActionLabel : t("wizard.defaults.next") })] })] }));
|
|
206
206
|
};
|
|
207
207
|
|
|
208
208
|
const cvaFormWizardHeader = cssClassVarianceUtilities.cvaMerge([
|
|
@@ -230,6 +230,7 @@ const cvaFormWizardComponentStepForm = cssClassVarianceUtilities.cvaMerge(["grid
|
|
|
230
230
|
*/
|
|
231
231
|
const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, component, formSchema, nextStepPath, previousStepPath, lastStepPrimaryActionLabel, fullFormSchema, setFullFormState, fullFormState, stepForms, setStepForms, setStepStates, basePath, }) => {
|
|
232
232
|
const navigate = reactRouter.useNavigate();
|
|
233
|
+
const [isSubmitting, setIsSubmitting] = react.useState(false);
|
|
233
234
|
const formRef = react.useRef(null);
|
|
234
235
|
const [submitHandlerInternal, setSubmitHandlerInternal] = react.useState(null);
|
|
235
236
|
const form = reactHookForm.useForm({
|
|
@@ -262,7 +263,12 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
262
263
|
return onCancel ? onCancel() : navigate({ to: basePath, params: { stepPath: "" } });
|
|
263
264
|
}, [onCancel, navigate, basePath]);
|
|
264
265
|
const setSubmitHandler = react.useCallback(callback => {
|
|
265
|
-
|
|
266
|
+
const wrappedCallbackFunction = (fullFormStateInner) => __awaiter(void 0, void 0, void 0, function* () {
|
|
267
|
+
setIsSubmitting(true);
|
|
268
|
+
yield callback(fullFormStateInner);
|
|
269
|
+
setIsSubmitting(false);
|
|
270
|
+
});
|
|
271
|
+
setSubmitHandlerInternal(() => wrappedCallbackFunction);
|
|
266
272
|
}, [setSubmitHandlerInternal]);
|
|
267
273
|
const isEmptyStep = sharedUtils.objectKeys(form.getValues()).length === 0;
|
|
268
274
|
const emptyStepSubmitHandler = react.useCallback((e) => {
|
|
@@ -274,7 +280,7 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
274
280
|
setFullFormState(prev => (Object.assign(Object.assign({}, prev), { [stepKey]: data })));
|
|
275
281
|
if (isLastStep) {
|
|
276
282
|
//? This state is not updated for the submit handler below; therefore, there is duplication.
|
|
277
|
-
submitHandlerInternal === null || submitHandlerInternal === void 0 ? void 0 : submitHandlerInternal(Object.assign(Object.assign({}, fullFormState), { [stepKey]: data }));
|
|
283
|
+
yield (submitHandlerInternal === null || submitHandlerInternal === void 0 ? void 0 : submitHandlerInternal(Object.assign(Object.assign({}, fullFormState), { [stepKey]: data })));
|
|
278
284
|
}
|
|
279
285
|
else if (nextStepPath) {
|
|
280
286
|
navigate({ to: basePath, params: { stepPath: nextStepPath } });
|
|
@@ -298,7 +304,8 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
298
304
|
}) }), jsxRuntime.jsx(FormWizardFooter, { stepForms,
|
|
299
305
|
onBack: previousStepPath ? () => navigate({ to: basePath, params: { stepPath: previousStepPath } }) : null,
|
|
300
306
|
primaryActionLabel: isLastStep ? lastStepPrimaryActionLabel : undefined,
|
|
301
|
-
onCancel: handleCancel
|
|
307
|
+
onCancel: handleCancel,
|
|
308
|
+
disablePrimaryAction: isSubmitting })] }, String(stepKey)));
|
|
302
309
|
};
|
|
303
310
|
|
|
304
311
|
const cvaFormWizardContainer = cssClassVarianceUtilities.cvaMerge(["h-full"]);
|
package/index.esm.js
CHANGED
|
@@ -2,7 +2,7 @@ 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
4
|
import { objectKeys, objectEntries, objectValues, objectFromEntries } from '@trackunit/shared-utils';
|
|
5
|
-
import {
|
|
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';
|
|
8
8
|
import { zodResolver } from '@hookform/resolvers/zod';
|
|
@@ -196,9 +196,9 @@ const cvaNavigationContainer = cvaMerge(["flex", "gap-responsive-space"]);
|
|
|
196
196
|
* The footer component for the FormWizard.
|
|
197
197
|
* In most cases you should not be using this component directly, but rather use the FormWizard component.
|
|
198
198
|
*/
|
|
199
|
-
const FormWizardFooter = ({ onBack, onCancel, primaryActionLabel = "Next" }) => {
|
|
199
|
+
const FormWizardFooter = ({ disablePrimaryAction = false, onBack, onCancel, primaryActionLabel = "Next", }) => {
|
|
200
200
|
const [t] = useTranslation();
|
|
201
|
-
return (jsxs("div", { className: cvaFooterContainer(), children: [jsx(Button, { dataTestId: "wizard-cancel", onClick: onCancel, variant: "ghost-neutral", children: t("wizard.defaults.cancel") }), jsxs("div", { className: cvaNavigationContainer(), children: [onBack ? (jsx(Button, { dataTestId: "wizard-back", onClick: onBack, variant: "secondary", children: t("wizard.defaults.back") })) : null, jsx(Button, { dataTestId: "wizard-next", type: "submit", children: primaryActionLabel ? primaryActionLabel : t("wizard.defaults.next") })] })] }));
|
|
201
|
+
return (jsxs("div", { className: cvaFooterContainer(), children: [jsx(Button, { dataTestId: "wizard-cancel", onClick: onCancel, variant: "ghost-neutral", children: t("wizard.defaults.cancel") }), jsxs("div", { className: cvaNavigationContainer(), children: [onBack ? (jsx(Button, { dataTestId: "wizard-back", onClick: onBack, variant: "secondary", children: t("wizard.defaults.back") })) : null, jsx(Button, { dataTestId: "wizard-next", disabled: disablePrimaryAction, type: "submit", children: primaryActionLabel ? primaryActionLabel : t("wizard.defaults.next") })] })] }));
|
|
202
202
|
};
|
|
203
203
|
|
|
204
204
|
const cvaFormWizardHeader = cvaMerge([
|
|
@@ -226,6 +226,7 @@ const cvaFormWizardComponentStepForm = cvaMerge(["grid-rows-min-fr-min", "grid",
|
|
|
226
226
|
*/
|
|
227
227
|
const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, component, formSchema, nextStepPath, previousStepPath, lastStepPrimaryActionLabel, fullFormSchema, setFullFormState, fullFormState, stepForms, setStepForms, setStepStates, basePath, }) => {
|
|
228
228
|
const navigate = useNavigate();
|
|
229
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
229
230
|
const formRef = useRef(null);
|
|
230
231
|
const [submitHandlerInternal, setSubmitHandlerInternal] = useState(null);
|
|
231
232
|
const form = useForm({
|
|
@@ -258,7 +259,12 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
258
259
|
return onCancel ? onCancel() : navigate({ to: basePath, params: { stepPath: "" } });
|
|
259
260
|
}, [onCancel, navigate, basePath]);
|
|
260
261
|
const setSubmitHandler = useCallback(callback => {
|
|
261
|
-
|
|
262
|
+
const wrappedCallbackFunction = (fullFormStateInner) => __awaiter(void 0, void 0, void 0, function* () {
|
|
263
|
+
setIsSubmitting(true);
|
|
264
|
+
yield callback(fullFormStateInner);
|
|
265
|
+
setIsSubmitting(false);
|
|
266
|
+
});
|
|
267
|
+
setSubmitHandlerInternal(() => wrappedCallbackFunction);
|
|
262
268
|
}, [setSubmitHandlerInternal]);
|
|
263
269
|
const isEmptyStep = objectKeys(form.getValues()).length === 0;
|
|
264
270
|
const emptyStepSubmitHandler = useCallback((e) => {
|
|
@@ -270,7 +276,7 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
270
276
|
setFullFormState(prev => (Object.assign(Object.assign({}, prev), { [stepKey]: data })));
|
|
271
277
|
if (isLastStep) {
|
|
272
278
|
//? This state is not updated for the submit handler below; therefore, there is duplication.
|
|
273
|
-
submitHandlerInternal === null || submitHandlerInternal === void 0 ? void 0 : submitHandlerInternal(Object.assign(Object.assign({}, fullFormState), { [stepKey]: data }));
|
|
279
|
+
yield (submitHandlerInternal === null || submitHandlerInternal === void 0 ? void 0 : submitHandlerInternal(Object.assign(Object.assign({}, fullFormState), { [stepKey]: data })));
|
|
274
280
|
}
|
|
275
281
|
else if (nextStepPath) {
|
|
276
282
|
navigate({ to: basePath, params: { stepPath: nextStepPath } });
|
|
@@ -294,7 +300,8 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
294
300
|
}) }), jsx(FormWizardFooter, { stepForms,
|
|
295
301
|
onBack: previousStepPath ? () => navigate({ to: basePath, params: { stepPath: previousStepPath } }) : null,
|
|
296
302
|
primaryActionLabel: isLastStep ? lastStepPrimaryActionLabel : undefined,
|
|
297
|
-
onCancel: handleCancel
|
|
303
|
+
onCancel: handleCancel,
|
|
304
|
+
disablePrimaryAction: isSubmitting })] }, String(stepKey)));
|
|
298
305
|
};
|
|
299
306
|
|
|
300
307
|
const cvaFormWizardContainer = cvaMerge(["h-full"]);
|
package/package.json
CHANGED
|
@@ -4,10 +4,11 @@ interface FormWizardFooterProps extends CommonProps {
|
|
|
4
4
|
primaryActionLabel?: string;
|
|
5
5
|
onCancel: () => void;
|
|
6
6
|
onBack: (() => void) | null;
|
|
7
|
+
disablePrimaryAction?: boolean;
|
|
7
8
|
}
|
|
8
9
|
/**
|
|
9
10
|
* The footer component for the FormWizard.
|
|
10
11
|
* In most cases you should not be using this component directly, but rather use the FormWizard component.
|
|
11
12
|
*/
|
|
12
|
-
export declare const FormWizardFooter: ({ onBack, onCancel, primaryActionLabel }: FormWizardFooterProps) => JSX.Element;
|
|
13
|
+
export declare const FormWizardFooter: ({ disablePrimaryAction, onBack, onCancel, primaryActionLabel, }: FormWizardFooterProps) => JSX.Element;
|
|
13
14
|
export {};
|
package/translation.cjs.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var translation = {
|
|
4
|
-
"wizard.defaults.back": "
|
|
5
|
-
"wizard.defaults.cancel": "
|
|
6
|
-
"wizard.defaults.next": "
|
|
4
|
+
"wizard.defaults.back": "Zurück",
|
|
5
|
+
"wizard.defaults.cancel": "Abbrechen",
|
|
6
|
+
"wizard.defaults.next": "Weiter"
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
exports["default"] = translation;
|
package/translation.cjs10.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var translation = {
|
|
4
|
-
"wizard.defaults.back": "
|
|
5
|
-
"wizard.defaults.cancel": "
|
|
6
|
-
"wizard.defaults.next": "
|
|
4
|
+
"wizard.defaults.back": "Powrót",
|
|
5
|
+
"wizard.defaults.cancel": "Anuluj",
|
|
6
|
+
"wizard.defaults.next": "Dalej"
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
exports["default"] = translation;
|
package/translation.cjs13.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var translation = {
|
|
4
|
-
"wizard.defaults.back": "
|
|
5
|
-
"wizard.defaults.cancel": "
|
|
6
|
-
"wizard.defaults.next": "
|
|
4
|
+
"wizard.defaults.back": "Înapoi",
|
|
5
|
+
"wizard.defaults.cancel": "Anulare",
|
|
6
|
+
"wizard.defaults.next": "Înainte"
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
exports["default"] = translation;
|
package/translation.cjs4.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var translation = {
|
|
4
|
-
"wizard.defaults.back": "
|
|
5
|
-
"wizard.defaults.cancel": "
|
|
6
|
-
"wizard.defaults.next": "
|
|
4
|
+
"wizard.defaults.back": "Terug",
|
|
5
|
+
"wizard.defaults.cancel": "Annuleren",
|
|
6
|
+
"wizard.defaults.next": "Volgende"
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
exports["default"] = translation;
|
package/translation.cjs9.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var translation = {
|
|
4
|
-
"wizard.defaults.back": "
|
|
5
|
-
"wizard.defaults.cancel": "
|
|
6
|
-
"wizard.defaults.next": "
|
|
4
|
+
"wizard.defaults.back": "Tilbake",
|
|
5
|
+
"wizard.defaults.cancel": "Avbryt",
|
|
6
|
+
"wizard.defaults.next": "Neste"
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
exports["default"] = translation;
|
package/translation.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var translation = {
|
|
2
|
-
"wizard.defaults.back": "
|
|
3
|
-
"wizard.defaults.cancel": "
|
|
4
|
-
"wizard.defaults.next": "
|
|
2
|
+
"wizard.defaults.back": "Zurück",
|
|
3
|
+
"wizard.defaults.cancel": "Abbrechen",
|
|
4
|
+
"wizard.defaults.next": "Weiter"
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
export { translation as default };
|
package/translation.esm10.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var translation = {
|
|
2
|
-
"wizard.defaults.back": "
|
|
3
|
-
"wizard.defaults.cancel": "
|
|
4
|
-
"wizard.defaults.next": "
|
|
2
|
+
"wizard.defaults.back": "Powrót",
|
|
3
|
+
"wizard.defaults.cancel": "Anuluj",
|
|
4
|
+
"wizard.defaults.next": "Dalej"
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
export { translation as default };
|
package/translation.esm13.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var translation = {
|
|
2
|
-
"wizard.defaults.back": "
|
|
3
|
-
"wizard.defaults.cancel": "
|
|
4
|
-
"wizard.defaults.next": "
|
|
2
|
+
"wizard.defaults.back": "Înapoi",
|
|
3
|
+
"wizard.defaults.cancel": "Anulare",
|
|
4
|
+
"wizard.defaults.next": "Înainte"
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
export { translation as default };
|
package/translation.esm4.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var translation = {
|
|
2
|
-
"wizard.defaults.back": "
|
|
3
|
-
"wizard.defaults.cancel": "
|
|
4
|
-
"wizard.defaults.next": "
|
|
2
|
+
"wizard.defaults.back": "Terug",
|
|
3
|
+
"wizard.defaults.cancel": "Annuleren",
|
|
4
|
+
"wizard.defaults.next": "Volgende"
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
export { translation as default };
|
package/translation.esm9.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var translation = {
|
|
2
|
-
"wizard.defaults.back": "
|
|
3
|
-
"wizard.defaults.cancel": "
|
|
4
|
-
"wizard.defaults.next": "
|
|
2
|
+
"wizard.defaults.back": "Tilbake",
|
|
3
|
+
"wizard.defaults.cancel": "Avbryt",
|
|
4
|
+
"wizard.defaults.next": "Neste"
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
export { translation as default };
|