@trackunit/react-form-wizard 0.1.272 → 0.1.273
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
|
@@ -209,7 +209,7 @@ const cvaFormWizardComponentStepForm = cssClassVarianceUtilities.cvaMerge(["grid
|
|
|
209
209
|
* A wrapper component used by the FormWizard component to render each step.
|
|
210
210
|
* In most cases you should not be using this component directly, but rather use the FormWizard component.
|
|
211
211
|
*/
|
|
212
|
-
const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, component, nextStepPath, previousStepPath, lastStepPrimaryActionLabel, fullFormSchema, setFullFormState, fullFormState, stepForms, setStepForms, setStepStates, basePath, containerClassName, }) => {
|
|
212
|
+
const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, component, nextStepPath, previousStepPath, lastStepPrimaryActionLabel, fullFormSchema, setFullFormState, fullFormState, stepForms, setStepForms, setStepStates, basePath, containerClassName, onPrimaryAction, }) => {
|
|
213
213
|
const navigate = reactRouter.useNavigate();
|
|
214
214
|
const [isSubmitting, setIsSubmitting] = react.useState(false);
|
|
215
215
|
const [submitHandlerInternal, setSubmitHandlerInternal] = react.useState(null);
|
|
@@ -297,8 +297,14 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
297
297
|
document.removeEventListener("keydown", handleKeyDown);
|
|
298
298
|
};
|
|
299
299
|
}, [stepSubmitHandler]);
|
|
300
|
-
return (jsxRuntime.jsxs("form", { className: cvaFormWizardComponentStepForm(), noValidate: true, onSubmit: e => {
|
|
300
|
+
return (jsxRuntime.jsxs("form", { className: cvaFormWizardComponentStepForm(), noValidate: true, onSubmit: async (e) => {
|
|
301
301
|
e.preventDefault();
|
|
302
|
+
try {
|
|
303
|
+
await (onPrimaryAction === null || onPrimaryAction === void 0 ? void 0 : onPrimaryAction(form));
|
|
304
|
+
}
|
|
305
|
+
catch (error) {
|
|
306
|
+
sharedUtils.doNothing();
|
|
307
|
+
}
|
|
302
308
|
handleSubmit();
|
|
303
309
|
}, children: [jsxRuntime.jsx(FormWizardHeader, { title, description }), jsxRuntime.jsx("div", { className: cvaFormWizardComponentContainer({ className: containerClassName }), children: jsxRuntime.jsx(reactHookForm.FormProvider, { ...form, children: component({
|
|
304
310
|
form,
|
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 { objectKeys, objectFromEntries, objectEntries } from '@trackunit/shared-utils';
|
|
4
|
+
import { objectKeys, doNothing, objectFromEntries, objectEntries } from '@trackunit/shared-utils';
|
|
5
5
|
import { useState, 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';
|
|
@@ -207,7 +207,7 @@ const cvaFormWizardComponentStepForm = cvaMerge(["grid-rows-min-fr-min", "grid",
|
|
|
207
207
|
* A wrapper component used by the FormWizard component to render each step.
|
|
208
208
|
* In most cases you should not be using this component directly, but rather use the FormWizard component.
|
|
209
209
|
*/
|
|
210
|
-
const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, component, nextStepPath, previousStepPath, lastStepPrimaryActionLabel, fullFormSchema, setFullFormState, fullFormState, stepForms, setStepForms, setStepStates, basePath, containerClassName, }) => {
|
|
210
|
+
const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, component, nextStepPath, previousStepPath, lastStepPrimaryActionLabel, fullFormSchema, setFullFormState, fullFormState, stepForms, setStepForms, setStepStates, basePath, containerClassName, onPrimaryAction, }) => {
|
|
211
211
|
const navigate = useNavigate();
|
|
212
212
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
213
213
|
const [submitHandlerInternal, setSubmitHandlerInternal] = useState(null);
|
|
@@ -295,8 +295,14 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
295
295
|
document.removeEventListener("keydown", handleKeyDown);
|
|
296
296
|
};
|
|
297
297
|
}, [stepSubmitHandler]);
|
|
298
|
-
return (jsxs("form", { className: cvaFormWizardComponentStepForm(), noValidate: true, onSubmit: e => {
|
|
298
|
+
return (jsxs("form", { className: cvaFormWizardComponentStepForm(), noValidate: true, onSubmit: async (e) => {
|
|
299
299
|
e.preventDefault();
|
|
300
|
+
try {
|
|
301
|
+
await (onPrimaryAction === null || onPrimaryAction === void 0 ? void 0 : onPrimaryAction(form));
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
doNothing();
|
|
305
|
+
}
|
|
300
306
|
handleSubmit();
|
|
301
307
|
}, children: [jsx(FormWizardHeader, { title, description }), jsx("div", { className: cvaFormWizardComponentContainer({ className: containerClassName }), children: jsx(FormProvider, { ...form, children: component({
|
|
302
308
|
form,
|
package/package.json
CHANGED
|
@@ -22,6 +22,7 @@ export interface SimpleStepProps {
|
|
|
22
22
|
}
|
|
23
23
|
interface DefinedStep<TStepSchema extends TFullSchemaValue[keyof TFullSchemaValue], TFullSchemaValue extends z.TypeOf<AnyZodObject>> extends SimpleStepProps {
|
|
24
24
|
component: (props: StepComponentPropsInner<TStepSchema, TFullSchemaValue>) => React.ReactNode;
|
|
25
|
+
onPrimaryAction?: (form: UseFormReturn<TStepSchema>) => Promise<unknown> | void;
|
|
25
26
|
defaultValues?: Partial<TStepSchema>;
|
|
26
27
|
}
|
|
27
28
|
export type StepComponentProps<TFullSchemaHook extends () => AnyZodObject, TStepKey extends keyof z.TypeOf<ReturnType<TFullSchemaHook>>> = StepComponentPropsInner<z.TypeOf<ReturnType<TFullSchemaHook>>[TStepKey], z.TypeOf<ReturnType<TFullSchemaHook>>>;
|
|
@@ -22,9 +22,10 @@ export interface FormWizardStepWrapperProps<TStepKey extends keyof z.TypeOf<TFul
|
|
|
22
22
|
setStepForms: Dispatch<SetStateAction<Partial<{
|
|
23
23
|
[TStepKey2 in keyof z.TypeOf<TFullSchema>]: UseFormReturn<z.TypeOf<TFullSchema>[TStepKey2]>;
|
|
24
24
|
}>>>;
|
|
25
|
+
onPrimaryAction?: (form: UseFormReturn<DeepPartial<z.TypeOf<TFullSchema>[TStepKey]>>) => Promise<unknown> | void;
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
27
28
|
* A wrapper component used by the FormWizard component to render each step.
|
|
28
29
|
* In most cases you should not be using this component directly, but rather use the FormWizard component.
|
|
29
30
|
*/
|
|
30
|
-
export declare const FormWizardStepWrapper: <TFullSchema extends AnyZodObject, TStepKey extends keyof z.TypeOf<TFullSchema>>({ stepKey, onCancel, description, title, component, nextStepPath, previousStepPath, lastStepPrimaryActionLabel, fullFormSchema, setFullFormState, fullFormState, stepForms, setStepForms, setStepStates, basePath, containerClassName, }: FormWizardStepWrapperProps<TStepKey, TFullSchema>) => import("react/jsx-runtime").JSX.Element;
|
|
31
|
+
export declare const FormWizardStepWrapper: <TFullSchema extends AnyZodObject, TStepKey extends keyof z.TypeOf<TFullSchema>>({ stepKey, onCancel, description, title, component, nextStepPath, previousStepPath, lastStepPrimaryActionLabel, fullFormSchema, setFullFormState, fullFormState, stepForms, setStepForms, setStepStates, basePath, containerClassName, onPrimaryAction, }: FormWizardStepWrapperProps<TStepKey, TFullSchema>) => import("react/jsx-runtime").JSX.Element;
|