Abstract onboarding wizard into reusable FormWizard#663
Conversation
Extract the ~400-line OnboardingForm wizard into a reusable form.Wizard and form.WizardStep component system that integrates with TanStack Form's formComponents registry. This enables multi-step wizards for onboarding, club match, club creation, and event creation forms. Key changes: - Create FormWizard/ directory with types, context, and components - Register Wizard and WizardStep as formComponents in form.ts - Fix validation to only block forward navigation (not backward) - Auto-advance to finish step after successful form submission - Rewrite OnboardingForm from ~400 lines to ~260 lines - Delete OnboardingFormStep (content moved inline to WizardStep children) Closes #588
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@Isoscelestial, Hey Isaac wanted to follow up on this, can you check it when you get the chance? |
Isoscelestial
left a comment
There was a problem hiding this comment.
I did a quick look through, I like how it's looking so far! After you fix these things, I'll do another more in-depth review.
Co-authored-by: Isoscelestial <isoscelestial@gmail.com>
Moved startStep and finishStep from Wizard props into WizardStep children using startStep and finishStep boolean props, so the API is consistent with how body steps are declared. Restored type safety on StepConfig using a discriminated union so start and finish variants cannot have fields. Fixed the Continue button on the finish screen not working, and made the wizard wait for the API call to finish before advancing to the finish step. Fixed date picker dark mode background from neutral-900 to neutral-800.
Isoscelestial
left a comment
There was a problem hiding this comment.
Looking good, love to see it functional! Sorry that I'm requesting a lot of changes...
| @@ -121,280 +76,193 @@ export default function OnboardingForm({ | |||
| validators: { onChange: accountOnboardingSchema }, | |||
There was a problem hiding this comment.
Change this to use the onSubmit validation event instead. This serves as a last-resort for all of the other validations that I'm assuming you implemented from my previous suggestion.
| validators: { onChange: accountOnboardingSchema }, | |
| validators: { onSubmit: accountOnboardingSchema }, |
To explain why I said earlier we can't use the onSubmit validation event for fields is because that'd mean we'd need to use form.validateField(field, 'submit'); And annoyingly, this will call this form-level onSubmit validator that we just added here (there's a logical reason for this, but it's a headache). So it will validate all the fields before we want it to.
To sum up everything, TanStack Form is missing features we need. Fortunately, they just started working on it in TanStack/form#2128. Looking forward to this, but for now we'll use this workaround (we'd probably want to refactor FormWizard again whenever this feature is released)
There was a problem hiding this comment.
Don't make this change until you've made the changes here: #663 (comment). Since you've already committed this particular change, you'll need to go ahead and work on that thread I linked.
There was a problem hiding this comment.
Oh!!!! Oh my god!! Tanstack Form merged that form groups feature, that's so awesome! Let's use that instead now. We'll need to update @tanstack/react-form to the latest version since they added it in v1.33 and we're on v1.32
| goNext: () => void; | ||
| goBack: () => void; | ||
| goToStep: (index: number) => void; | ||
| goToFinish: () => void; |
There was a problem hiding this comment.
Might be useful to return the new activeStep instead of void for goNext, goBack, and goToFinish? Not necessary, just thinking ahead
|
Adding a note here to copy these changes over to Notebook after merge. |
|
Resolved all FormWizard-related threads since we're taking a different approach: fixing the two real bugs directly in What's fixed (on
Left unresolved: The thread about changing The FormWizard abstraction can be revisited when a second wizard consumer actually exists (club creation, event creation, etc.), at which point the real API surface will be clearer. |
Co-authored-by: Isoscelestial <isoscyoung@gmail.com>
You already made the full abstraction. At this point, we are just fixing bugs and code quality issues. I am unresolving all the threads so that they can be fixed. If you'd like help with some of the threads, I'd be more than happy to tackle some of them!
Not sure where this branch name came from. If your AI tends to hallucinate, I ask that you at the very least double check your code and comments before sending them to be reviewed.
I'd like these changes to be made now, as we've figured out a solution and are just waiting for the code to be written. Related PR: UTDNebula/utd-notebook#183
As we discussed earlier, we are planning to have a "second wizard consumer" by using this abstracted system with the club matching form, the club creation form, and event creation form. |
Summary
form.Wizardandform.WizardStepcomponents that any form can use<form.WizardStep>How it works
The wizard registers as a TanStack Form
formComponent, so consumers use it asform.Wizard/form.WizardStep:Each step declares its
fieldsarray, which the wizard uses for per-step validation. The wizard handles the MUI Stepper, slide transitions, dynamic height, and navigation buttons automatically.Files changed
src/components/form/FormWizard/src/utils/form.tssrc/components/getting-started/OnboardingForm.tsxsrc/components/getting-started/OnboardingFormStep.tsxsrc/components/form/FormWizard.tsxCloses #588