Repository navigation
fix(site/src/pages/TemplateBuilder): validate customizations form before submit - #28081
Conversation
| TemplateBuilderWizardState, | ||
| } from "./wizardState"; | ||
|
|
||
| export const TEMPLATE_CUSTOMIZATIONS_FORM_ID = "template-customizations-form"; |
There was a problem hiding this comment.
this feels slightly hacky to me so suggestions welcome! right now this is used to point the submit button at the form since the button lives outside this view
There was a problem hiding this comment.
this is a data-testid type thing, not a real dom id concern
There was a problem hiding this comment.
this binds the submit button to the form:
|
some good feedback in slack, so I'm going to take this back into draft for now |
| function renderStepContent( | ||
| stepId: StepId, | ||
| state: TemplateBuilderWizardState, | ||
| dispatch: (action: WizardAction) => void, | ||
| moduleVarMap: Record<string, Record<string, string>>, | ||
| createError: Error | null, | ||
| onProvisionerStatusChange: (value: boolean | undefined) => void, | ||
| onRemoveModule: (moduleId: string) => void, | ||
| registerModuleRef: (moduleId: string, node: HTMLDivElement | null) => void, | ||
| onCreate: (values: CustomizationsFormValues) => void, |
There was a problem hiding this comment.
note for a future PR: renderStepContent has too many arguments, refactor into a params object
…ore submit Convert the Template Builder customizations step to a Formik form with a Yup schema and surface aggregated validation errors in an Alert at the top of the step. This avoids inline field errors that would disrupt the horizontal two-column layout, and stops empty organization/name submissions from hitting the API with an unhelpful backend error. The wizard's Create Template button submits the step form via the form attribute. Only valid submits reach the create mutation; a genuinely invalid organization still surfaces the backend message via the existing error alert.
…inline Display Formik validation errors inline under each field instead of an aggregated summary at the top of the step. Reuse the shared getFormHelpers and FormField primitives for touched-gated error display rather than hand-rolling the logic.
2f958c9 to
6993e74
Compare
| <Button | ||
| type="submit" | ||
| form={TEMPLATE_CUSTOMIZATIONS_FORM_ID} | ||
| disabled={state.hasProvisioners === false} |
There was a problem hiding this comment.
| disabled={state.hasProvisioners === false} | |
| disabled={!state.hasProvisioners} |
wouldn't this be correct?
There was a problem hiding this comment.
this would also be correct. since hasProvisioners: boolean | undefined, that'll work, and I really don't have a strong opinion either way.
| ); | ||
| case "customizations": | ||
| return state.name.trim() !== "" && state.hasProvisioners !== false; | ||
| return state.hasProvisioners !== false; |
There was a problem hiding this comment.
same here. is this value not a boolean? this is a weird treatment
There was a problem hiding this comment.
it's a hasProvisioners: boolean | undefined, and it's undefined until the user reaches the last step with the form. I'm open to changing it to negation if you think this was weird to read
There was a problem hiding this comment.
yeah, or if undefined and true should be treated similarly then it should be inverted to something like hasNoProvisioner instead so it can be used more plainly
There was a problem hiding this comment.
they're not exactly similar. we don't know the provisioners status until we make the orgs call at the final step (we don't do it up front because we don't know the org). I think this indeterminate or initial state makes sense as undefined. hasNoProvisioner suffers from the same problem as hasProvisioners– until we make the call it'd have to either be true or false, which are both lies. I'm down to introduce a variable and/or comment to make this clear in the code, but I am definitely leaning towards keeping undefined in the type
| TemplateBuilderWizardState, | ||
| } from "./wizardState"; | ||
|
|
||
| export const TEMPLATE_CUSTOMIZATIONS_FORM_ID = "template-customizations-form"; |
There was a problem hiding this comment.
this is a data-testid type thing, not a real dom id concern
Drop the useCallback around handleCreate, remove the useExhaustiveDependencies biome-ignore in favor of a real dependency, inline the provisioner query key helper in the story, and trim the RESET_CUSTOMIZATIONS comment.
Summary
Fixes the unhelpful backend error when creating a template in the Template Builder with no organization selected (DEVEX-744).
The customizations step is now a Formik form with a Yup schema. Validation runs on submit and errors are presented inline or in a single
Alertat the top of the step. Only valid submits reach the create API, so an empty organization now shows "Select an organization to continue." instead of hitting the backend. A genuinely invalid selection still surfaces the backend's message via the existing error alert.Changes
TemplateCustomizationsStep.tsx: Formik + Yup form; organization is always required (the page is gated on the create-template permission, so there is always at least one permitted org and it is auto-selected when only one exists); aggregated top-of-step error summary.TemplateBuilderPageView.tsx: the wizard's "Create Template" button submits the step form via theformattribute; addedonCreateplumbing; relaxed the customizations continue gate to the provisioner check.wizardState.ts:toCreateTemplateRequest(state, customizations)builds the request from the submitted form values; removed the now-vestigialorganizationIdfrom the reducer.TemplateBuilderPage.tsx: adapts the create call to the new signature.TemplateCustomizationsStep.stories.tsx: interaction tests for missing organization, missing name, single-org auto-select, and valid submit.Testing
pnpm --dir site exec tsc -p . --noEmit(clean)pnpm --dir site exec biome check src/pages/TemplateBuilder(clean)wizardState.test.ts(27 passed) andTemplateCustomizationsStep.stories.tsx(4 passed)Screen.Recording.2026-08-17.at.3.59.07.PM.mov
Implementation plan
DEVEX-744: Form validation for the Template Builder customizations step
Problem
In the new Template Builder wizard, creating a template with no organization selected produces an unhelpful backend error (empty
organization_idsent to the API). There is no client-side validation on the final "Customizations" step:computeCanContinueonly checksnameand provisioner availability, so the "Create Template" button is enabled even when the organization is missing.The customizations form is a horizontal two-column grid. Showing per-field inline errors (Formik
helperText) would push fields down and break column alignment. We want validation before submit, with messages aggregated at the top of the step rather than inline under fields.Decision (confirmed with user)
CreateTemplateForm), rather than ad-hoc reducer validation.utils/formUtils.ts.Approach
Make
TemplateCustomizationsStepa Formik form that is the source of truth for the five customization fields. Validate on submit; render an aggregated error summary Alert at the top of the step. Connect the wizard's existing "Create Template" button (which lives in the parent nav bar) to the child form using the standardform="<id>" type="submit"HTML association, so no imperative handle or extra callback is needed. Only valid submits reach the API.Steps
TemplateCustomizationsStep.tsx: convert to Formik with a Yup schema (nameValidator,displayNameValidator, description max 128,iconValidator, organization always required); initial values seeded from wizard state; aggregated error Alert at the top; keep provisioner reporting and org auto-select.TemplateBuilderPageView.tsx: wire the last-step button to submit the form via theformattribute; add anonCreateprop; relax the customizations continue gate to the provisioner check.wizardState.ts:toCreateTemplateRequest(state, customizations)composes the request from base/modules in state plus submitted values.TemplateBuilderPage.tsx: adapthandleCreate.Behavior notes
createErroralert; only the empty-org case is caught client-side.Post-plan refinements (from review)
orgRequired), since the page is permission-gated and always has at least one permitted org.toCreateTemplateRequestkeeps the submitted form values authoritative (no fallback to state, which would resurrect optional fields a user deliberately cleared).organizationIdfield from the reducer state.Buttoncomponent.Testing
wizardState.test.tsfor the newtoCreateTemplateRequestsignature.Generated by Coder Agents on behalf of @jeremyruppel.