Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve call validation by checking validation of form using native html input before changing step #850

Merged
merged 9 commits into from
Nov 26, 2024
18 changes: 15 additions & 3 deletions apps/frontend/src/components/common/MultistepWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,17 @@ export const Wizard = ({
setStepNumber(Math.max(stepNumber - 1, 0));
};

const handleStep = (step: number, values: FormikValues) => () => {
const handleStep = (stepIndex: number, values: FormikValues) => () => {
const form = document.querySelector('form');

if (form && !form.checkValidity()) {
form.reportValidity();

return;
}

setSnapshot(values);
setStepNumber(step);
setStepNumber(stepIndex);
};

const handleSubmit = async (
Expand Down Expand Up @@ -134,7 +142,11 @@ export const Wizard = ({
disabled={formik.isSubmitting}
>
{formik.isSubmitting && <UOLoader size={14} />}
{isLastStep ? (shouldCreate ? 'Create' : 'Update') : 'Next'}
{isLastStep
? shouldCreate
? 'Create'
: 'Update'
: 'Save and Continue'}
</Button>
</ActionButtonContainer>
</Form>
Expand Down
Loading