@trackunit/react-form-wizard 0.1.97 → 0.1.98

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
@@ -348,7 +348,7 @@ const cvaStepContainer = cssClassVarianceUtilities.cvaMerge(["h-full", "grid", "
348
348
  * The FormWizard component is used for forms in multiple steps.
349
349
  * Use the useFormWizard hook to generate the props for this component.
350
350
  */
351
- const FormWizard = ({ lastStepPrimaryActionLabel, steps, fullFormSchema, onCancel, className, dataTestId, basePath, }) => {
351
+ const FormWizard = ({ lastStepPrimaryActionLabel, isEdit, steps, fullFormSchema, onCancel, className, dataTestId, basePath, }) => {
352
352
  var _a;
353
353
  const { stepPath, subStepPath } = reactRouter.useParams({ from: basePath });
354
354
  const [stepStates, setStepStates] = react.useState({});
@@ -367,10 +367,11 @@ const FormWizard = ({ lastStepPrimaryActionLabel, steps, fullFormSchema, onCance
367
367
  .findIndex(key => key === currentVisibleStepKey);
368
368
  return (jsxRuntime.jsx("div", { className: cvaFormWizardContainer({ className }), "data-testid": dataTestId, children: jsxRuntime.jsxs("div", { className: cvaFormWizardLayout(), children: [jsxRuntime.jsx(FormWizardSidebar, { children: sharedUtils.objectEntries(steps)
369
369
  .filter(([_, step]) => { var _a, _b; return (_b = (_a = step.shouldRender) === null || _a === void 0 ? void 0 : _a.call(step, fullFormState)) !== null && _b !== void 0 ? _b : true; })
370
- .map(([key, { path, title, sidebarDescription, parent }], index) => {
370
+ .map(([key, { path, title, sidebarDescription, parent, defaultValues }], index) => {
371
371
  const isPastStep = index < currentVisibleStepIndex;
372
372
  const isFutureStep = index > currentVisibleStepIndex;
373
373
  const isCurrentStep = key === currentVisibleStepKey;
374
+ const hasDefaultValue = defaultValues !== undefined;
374
375
  const isSubStep = parent !== undefined;
375
376
  const onlyParentSteps = sharedUtils.objectEntries(steps)
376
377
  .filter(([_, step]) => step.parent === undefined)
@@ -380,6 +381,14 @@ const FormWizard = ({ lastStepPrimaryActionLabel, steps, fullFormSchema, onCance
380
381
  if (isCurrentStep) {
381
382
  return "active";
382
383
  }
384
+ //If the step has a default value, it is considered valid, so we set it to valid in order to show the green checkmark
385
+ if (hasDefaultValue && stepStates[key] === undefined && isEdit) {
386
+ setStepStates(prev => (Object.assign(Object.assign({}, prev), { [key]: "valid" })));
387
+ }
388
+ //If the step has a default value, we return done, so we can navigate to that step
389
+ if (hasDefaultValue && isEdit) {
390
+ return "done";
391
+ }
383
392
  if (isPastStep) {
384
393
  return stepStates[key] === "valid" ? "done" : "invalid";
385
394
  }
package/index.esm.js CHANGED
@@ -344,7 +344,7 @@ const cvaStepContainer = cvaMerge(["h-full", "grid", "bg-white", "overflow-hidde
344
344
  * The FormWizard component is used for forms in multiple steps.
345
345
  * Use the useFormWizard hook to generate the props for this component.
346
346
  */
347
- const FormWizard = ({ lastStepPrimaryActionLabel, steps, fullFormSchema, onCancel, className, dataTestId, basePath, }) => {
347
+ const FormWizard = ({ lastStepPrimaryActionLabel, isEdit, steps, fullFormSchema, onCancel, className, dataTestId, basePath, }) => {
348
348
  var _a;
349
349
  const { stepPath, subStepPath } = useParams({ from: basePath });
350
350
  const [stepStates, setStepStates] = useState({});
@@ -363,10 +363,11 @@ const FormWizard = ({ lastStepPrimaryActionLabel, steps, fullFormSchema, onCance
363
363
  .findIndex(key => key === currentVisibleStepKey);
364
364
  return (jsx("div", { className: cvaFormWizardContainer({ className }), "data-testid": dataTestId, children: jsxs("div", { className: cvaFormWizardLayout(), children: [jsx(FormWizardSidebar, { children: objectEntries(steps)
365
365
  .filter(([_, step]) => { var _a, _b; return (_b = (_a = step.shouldRender) === null || _a === void 0 ? void 0 : _a.call(step, fullFormState)) !== null && _b !== void 0 ? _b : true; })
366
- .map(([key, { path, title, sidebarDescription, parent }], index) => {
366
+ .map(([key, { path, title, sidebarDescription, parent, defaultValues }], index) => {
367
367
  const isPastStep = index < currentVisibleStepIndex;
368
368
  const isFutureStep = index > currentVisibleStepIndex;
369
369
  const isCurrentStep = key === currentVisibleStepKey;
370
+ const hasDefaultValue = defaultValues !== undefined;
370
371
  const isSubStep = parent !== undefined;
371
372
  const onlyParentSteps = objectEntries(steps)
372
373
  .filter(([_, step]) => step.parent === undefined)
@@ -376,6 +377,14 @@ const FormWizard = ({ lastStepPrimaryActionLabel, steps, fullFormSchema, onCance
376
377
  if (isCurrentStep) {
377
378
  return "active";
378
379
  }
380
+ //If the step has a default value, it is considered valid, so we set it to valid in order to show the green checkmark
381
+ if (hasDefaultValue && stepStates[key] === undefined && isEdit) {
382
+ setStepStates(prev => (Object.assign(Object.assign({}, prev), { [key]: "valid" })));
383
+ }
384
+ //If the step has a default value, we return done, so we can navigate to that step
385
+ if (hasDefaultValue && isEdit) {
386
+ return "done";
387
+ }
379
388
  if (isPastStep) {
380
389
  return stepStates[key] === "valid" ? "done" : "invalid";
381
390
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-form-wizard",
3
- "version": "0.1.97",
3
+ "version": "0.1.98",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "dependencies": {
@@ -9,4 +9,4 @@ export type FormWizardStepFormReturnMap<TFullSchema extends AnyZodObject> = Part
9
9
  * The FormWizard component is used for forms in multiple steps.
10
10
  * Use the useFormWizard hook to generate the props for this component.
11
11
  */
12
- export declare const FormWizard: <TFullSchema extends AnyZodObject, TComponentStepDefinitions extends ComponentStepDefinitions<TFullSchema>>({ lastStepPrimaryActionLabel, steps, fullFormSchema, onCancel, className, dataTestId, basePath, }: FromWizardComponentProps<TFullSchema, TComponentStepDefinitions>) => JSX.Element;
12
+ export declare const FormWizard: <TFullSchema extends AnyZodObject, TComponentStepDefinitions extends ComponentStepDefinitions<TFullSchema>>({ lastStepPrimaryActionLabel, isEdit, steps, fullFormSchema, onCancel, className, dataTestId, basePath, }: FromWizardComponentProps<TFullSchema, TComponentStepDefinitions>) => JSX.Element;
@@ -1,7 +1,7 @@
1
1
  import { RegisteredRouter, RouteIds } from "@tanstack/react-router";
2
2
  import { CommonProps } from "@trackunit/react-components";
3
3
  import { ReactNode } from "react";
4
- import { DeepPartial, UseFormReturn } from "react-hook-form";
4
+ import { UseFormReturn } from "react-hook-form";
5
5
  import { AnyZodObject, SomeZodObject, z } from "zod";
6
6
  export type StepState = "active" | "done" | "invalid" | "disabled" | "ready";
7
7
  export type StepDefinitions<TFullSchema extends AnyZodObject> = {
@@ -23,7 +23,7 @@ interface DefinedStep<TStepSchema extends TFullSchemaValue[keyof TFullSchemaValu
23
23
  component: (props: StepComponentPropsInner<TStepSchema, TFullSchemaValue>) => React.ReactNode;
24
24
  parent?: keyof TFullSchemaValue;
25
25
  shouldRender?: (fullFormState: Partial<TFullSchemaValue>) => boolean;
26
- defaultValues?: DeepPartial<TStepSchema>;
26
+ defaultValues?: TStepSchema;
27
27
  }
28
28
  export type StepComponentProps<TFullSchemaHook extends () => AnyZodObject, TStepKey extends keyof z.TypeOf<ReturnType<TFullSchemaHook>>> = StepComponentPropsInner<z.TypeOf<ReturnType<TFullSchemaHook>>[TStepKey], z.TypeOf<ReturnType<TFullSchemaHook>>>;
29
29
  export type ComponentStepDefinitions<TFullSchema extends AnyZodObject> = {
@@ -42,6 +42,7 @@ export interface UseFormWizardProps<TFullSchema extends SomeZodObject, TStepDefi
42
42
  onCancel?: () => void;
43
43
  basePath: StringWithStepKey<`${RouteIds<RegisteredRouter["routeTree"]>}`>;
44
44
  steps: TStepDefinitions;
45
+ isEdit?: boolean;
45
46
  }
46
47
  /**
47
48
  * A hook to generate the props for the FormWizard component.