Skip to content

Commit

Permalink
fix issue with wizard form
Browse files Browse the repository at this point in the history
  • Loading branch information
simlarsen committed May 16, 2023
1 parent 06375f4 commit 51d28b0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 42 deletions.
23 changes: 13 additions & 10 deletions CommonUI/src/Components/Forms/BasicForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -288,22 +288,25 @@ const BasicForm: ForwardRefExoticComponent<any> = forwardRef(

props.onSubmit(values);
} else if (props.steps && props.steps.length > 0) {
const currentStepIndex: number = props.steps.findIndex(
const steps: Array<FormStep<T>> = props.steps.filter(
(step: FormStep<T>) => {
if (!step.showIf) {
return true;
}

return step.showIf(refCurrentValue.current);
}
);

const currentStepIndex: number = steps.findIndex(
(step: FormStep<T>) => {
return step.id === currentFormStepId;
}
);

if (currentStepIndex > -1) {
setCurrentFormStepId(
(
props.steps.filter((step: FormStep<T>) => {
if (!step.showIf) {
return true;
}

return step.showIf(refCurrentValue.current);
})[currentStepIndex + 1] as FormStep<T>
).id
(steps[currentStepIndex + 1] as FormStep<T>).id
);
}
}
Expand Down
67 changes: 35 additions & 32 deletions CommonUI/src/Components/Forms/Steps/Steps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,48 @@ export interface ComponentProps<T> {
const Steps: Function = <T extends Object>(
props: ComponentProps<T>
): ReactElement => {
const steps: Array<FormStep<T>> = props.steps.filter(
(step: FormStep<T>) => {
if (!step.showIf) {
return true;
}

return step.showIf(props.formValues);
}
);

return (
<div className="pr-4 py-6 sm:pr-6 lg:pr-8">
<nav className="flex" aria-label="Progress">
<ol role="list" className="space-y-6">
{props.steps
.filter((step: FormStep<T>) => {
if (!step.showIf) {
return true;
{steps.map((step: FormStep<T>, index: number) => {
const indexOfCurrentState: number = steps.findIndex(
(step: FormStep<T>) => {
return step.id === props.currentFormStepId;
}
);

return step.showIf(props.formValues);
})
.map((step: FormStep<T>, index: number) => {
const indexOfCurrentState: number =
props.steps.findIndex((step: FormStep<T>) => {
return step.id === props.currentFormStepId;
});

let state: FormStepState = FormStepState.INACTIVE;

if (indexOfCurrentState > index) {
state = FormStepState.COMPLETED;
} else if (indexOfCurrentState === index) {
state = FormStepState.ACTIVE;
} else {
state = FormStepState.INACTIVE;
}
let state: FormStepState = FormStepState.INACTIVE;

if (indexOfCurrentState > index) {
state = FormStepState.COMPLETED;
} else if (indexOfCurrentState === index) {
state = FormStepState.ACTIVE;
} else {
state = FormStepState.INACTIVE;
}

return (
<Step
state={state}
step={step}
key={index}
onClick={(step: FormStep<T>) => {
props.onClick(step);
}}
/>
);
})}
return (
<Step
state={state}
step={step}
key={index}
onClick={(step: FormStep<T>) => {
props.onClick(step);
}}
/>
);
})}
</ol>
</nav>
</div>
Expand Down

0 comments on commit 51d28b0

Please sign in to comment.