@trackunit/react-form-wizard 2.17.24 → 2.17.26
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 +28 -4
- package/index.esm.js +28 -4
- package/package.json +6 -5
- package/src/translation.d.ts +2 -2
package/index.cjs.js
CHANGED
|
@@ -8,12 +8,14 @@ var react = require('react');
|
|
|
8
8
|
var cssClassVarianceUtilities = require('@trackunit/css-class-variance-utilities');
|
|
9
9
|
var reactComponents = require('@trackunit/react-components');
|
|
10
10
|
var zod = require('@hookform/resolvers/zod');
|
|
11
|
+
var reactCoreHooks = require('@trackunit/react-core-hooks');
|
|
11
12
|
var reactHookForm = require('react-hook-form');
|
|
12
13
|
|
|
13
14
|
var defaultTranslations = {
|
|
14
15
|
"wizard.defaults.back": "Back",
|
|
15
16
|
"wizard.defaults.cancel": "Cancel",
|
|
16
|
-
"wizard.defaults.next": "Next"
|
|
17
|
+
"wizard.defaults.next": "Next",
|
|
18
|
+
"wizard.submit.failed": "Something went wrong. Please try again."
|
|
17
19
|
};
|
|
18
20
|
|
|
19
21
|
/** The translation namespace for this library */
|
|
@@ -218,6 +220,9 @@ const cvaFormWizardComponentStepForm = cssClassVarianceUtilities.cva({
|
|
|
218
220
|
*/
|
|
219
221
|
const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, component, nextStepPath, previousStepPath, lastStepPrimaryActionLabel, fullFormSchema, setFullFormState, fullFormState, stepForms, setStepForms, setStepStates, basePath, containerClassName, onPrimaryAction, initialFullFormState, }) => {
|
|
220
222
|
const navigate = reactRouter.useNavigate();
|
|
223
|
+
const [t] = useTranslation();
|
|
224
|
+
const { addToast } = reactCoreHooks.useToast();
|
|
225
|
+
const { captureException } = reactCoreHooks.useErrorHandler();
|
|
221
226
|
const [isSubmitting, setIsSubmitting] = react.useState(false);
|
|
222
227
|
const [primaryActionDisabledByStep, setPrimaryActionDisabledByStep] = react.useState(false);
|
|
223
228
|
const [submitHandlerInternal, setSubmitHandlerInternal] = react.useState(null);
|
|
@@ -253,11 +258,30 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
253
258
|
const setSubmitHandler = react.useCallback(callback => {
|
|
254
259
|
const wrappedCallbackFunction = async (fullFormStateInner) => {
|
|
255
260
|
setIsSubmitting(true);
|
|
256
|
-
|
|
257
|
-
|
|
261
|
+
try {
|
|
262
|
+
await callback(fullFormStateInner);
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
// A rejected submit (typically a failed mutation) must not leave the primary action
|
|
266
|
+
// spinning with no feedback: tell the user, report it, and hand the wizard back.
|
|
267
|
+
// The toast is deliberately generic. Every wizard shares it, and a server message is
|
|
268
|
+
// not always meant for customers' eyes, so the error goes to the error handler only.
|
|
269
|
+
// Revisit (e.g. pass the message as the description) if product wants more detail.
|
|
270
|
+
captureException(error);
|
|
271
|
+
void addToast({
|
|
272
|
+
id: "form-wizard-submit-failed",
|
|
273
|
+
intent: "danger",
|
|
274
|
+
title: t("wizard.submit.failed"),
|
|
275
|
+
// The failure blocks the wizard, so the toast stays until the user closes it.
|
|
276
|
+
behavior: "persistent",
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
finally {
|
|
280
|
+
setIsSubmitting(false);
|
|
281
|
+
}
|
|
258
282
|
};
|
|
259
283
|
setSubmitHandlerInternal(() => wrappedCallbackFunction);
|
|
260
|
-
}, [setSubmitHandlerInternal]);
|
|
284
|
+
}, [addToast, captureException, setSubmitHandlerInternal, t]);
|
|
261
285
|
const beforeStepSubmit = react.useCallback(callback => {
|
|
262
286
|
const wrappedCallbackFunction = async (fullFormStateInner) => {
|
|
263
287
|
await callback(fullFormStateInner);
|
package/index.esm.js
CHANGED
|
@@ -6,12 +6,14 @@ import { useState, useEffect, useCallback, useMemo } from 'react';
|
|
|
6
6
|
import { cva } from '@trackunit/css-class-variance-utilities';
|
|
7
7
|
import { Icon, Button, Heading } from '@trackunit/react-components';
|
|
8
8
|
import { zodResolver } from '@hookform/resolvers/zod';
|
|
9
|
+
import { useToast, useErrorHandler } from '@trackunit/react-core-hooks';
|
|
9
10
|
import { useForm, useWatch, FormProvider } from 'react-hook-form';
|
|
10
11
|
|
|
11
12
|
var defaultTranslations = {
|
|
12
13
|
"wizard.defaults.back": "Back",
|
|
13
14
|
"wizard.defaults.cancel": "Cancel",
|
|
14
|
-
"wizard.defaults.next": "Next"
|
|
15
|
+
"wizard.defaults.next": "Next",
|
|
16
|
+
"wizard.submit.failed": "Something went wrong. Please try again."
|
|
15
17
|
};
|
|
16
18
|
|
|
17
19
|
/** The translation namespace for this library */
|
|
@@ -216,6 +218,9 @@ const cvaFormWizardComponentStepForm = cva({
|
|
|
216
218
|
*/
|
|
217
219
|
const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, component, nextStepPath, previousStepPath, lastStepPrimaryActionLabel, fullFormSchema, setFullFormState, fullFormState, stepForms, setStepForms, setStepStates, basePath, containerClassName, onPrimaryAction, initialFullFormState, }) => {
|
|
218
220
|
const navigate = useNavigate();
|
|
221
|
+
const [t] = useTranslation();
|
|
222
|
+
const { addToast } = useToast();
|
|
223
|
+
const { captureException } = useErrorHandler();
|
|
219
224
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
220
225
|
const [primaryActionDisabledByStep, setPrimaryActionDisabledByStep] = useState(false);
|
|
221
226
|
const [submitHandlerInternal, setSubmitHandlerInternal] = useState(null);
|
|
@@ -251,11 +256,30 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
251
256
|
const setSubmitHandler = useCallback(callback => {
|
|
252
257
|
const wrappedCallbackFunction = async (fullFormStateInner) => {
|
|
253
258
|
setIsSubmitting(true);
|
|
254
|
-
|
|
255
|
-
|
|
259
|
+
try {
|
|
260
|
+
await callback(fullFormStateInner);
|
|
261
|
+
}
|
|
262
|
+
catch (error) {
|
|
263
|
+
// A rejected submit (typically a failed mutation) must not leave the primary action
|
|
264
|
+
// spinning with no feedback: tell the user, report it, and hand the wizard back.
|
|
265
|
+
// The toast is deliberately generic. Every wizard shares it, and a server message is
|
|
266
|
+
// not always meant for customers' eyes, so the error goes to the error handler only.
|
|
267
|
+
// Revisit (e.g. pass the message as the description) if product wants more detail.
|
|
268
|
+
captureException(error);
|
|
269
|
+
void addToast({
|
|
270
|
+
id: "form-wizard-submit-failed",
|
|
271
|
+
intent: "danger",
|
|
272
|
+
title: t("wizard.submit.failed"),
|
|
273
|
+
// The failure blocks the wizard, so the toast stays until the user closes it.
|
|
274
|
+
behavior: "persistent",
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
finally {
|
|
278
|
+
setIsSubmitting(false);
|
|
279
|
+
}
|
|
256
280
|
};
|
|
257
281
|
setSubmitHandlerInternal(() => wrappedCallbackFunction);
|
|
258
|
-
}, [setSubmitHandlerInternal]);
|
|
282
|
+
}, [addToast, captureException, setSubmitHandlerInternal, t]);
|
|
259
283
|
const beforeStepSubmit = useCallback(callback => {
|
|
260
284
|
const wrappedCallbackFunction = async (fullFormStateInner) => {
|
|
261
285
|
await callback(fullFormStateInner);
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-form-wizard",
|
|
3
|
-
"version": "2.17.
|
|
3
|
+
"version": "2.17.26",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"zod": "^3.25.76",
|
|
8
8
|
"@hookform/resolvers": "^7.0.2",
|
|
9
9
|
"@tanstack/router-core": "1.114.29",
|
|
10
|
-
"@trackunit/shared-utils": "1.22.
|
|
11
|
-
"@trackunit/css-class-variance-utilities": "2.6.
|
|
12
|
-
"@trackunit/react-components": "6.0.
|
|
13
|
-
"@trackunit/i18n-library-translation": "2.14.
|
|
10
|
+
"@trackunit/shared-utils": "1.22.33",
|
|
11
|
+
"@trackunit/css-class-variance-utilities": "2.6.33",
|
|
12
|
+
"@trackunit/react-components": "6.0.24",
|
|
13
|
+
"@trackunit/i18n-library-translation": "2.14.24",
|
|
14
|
+
"@trackunit/react-core-hooks": "1.31.24"
|
|
14
15
|
},
|
|
15
16
|
"engines": {
|
|
16
17
|
"node": ">=24.x",
|
package/src/translation.d.ts
CHANGED
|
@@ -14,8 +14,8 @@ export declare const translations: TranslationResource<TranslationKeys>;
|
|
|
14
14
|
/**
|
|
15
15
|
* Local useTranslation for this specific library
|
|
16
16
|
*/
|
|
17
|
-
export declare const useTranslation: () => [TransForLibs<"wizard.defaults.back" | "wizard.defaults.cancel" | "wizard.defaults.next">, import("i18next").i18n, boolean] & {
|
|
18
|
-
t: TransForLibs<"wizard.defaults.back" | "wizard.defaults.cancel" | "wizard.defaults.next">;
|
|
17
|
+
export declare const useTranslation: () => [TransForLibs<"wizard.defaults.back" | "wizard.defaults.cancel" | "wizard.defaults.next" | "wizard.submit.failed">, import("i18next").i18n, boolean] & {
|
|
18
|
+
t: TransForLibs<"wizard.defaults.back" | "wizard.defaults.cancel" | "wizard.defaults.next" | "wizard.submit.failed">;
|
|
19
19
|
i18n: import("i18next").i18n;
|
|
20
20
|
ready: boolean;
|
|
21
21
|
};
|