refactor(ui): move useForm into Rental Checkout form view (phase 16) - #378
Merged
mnindrazaka merged 2 commits intoAug 27, 2026
Merged
Conversation
Adds the FormView primitive (TRD phase 1, not yet in main) with its formRef escape hatch, then migrates Rental Checkout onto it: useForm now lives in RentalCheckoutFormView instead of the controller, the rentals field array moves into the view via FieldArray, and the sibling rentalList selection in RentalCheckoutHandler writes into the form through formRef instead of a controller-owned onAddItem. Behaviour changes: none intended. RentalCheckoutUsecase has no fetch step of its own (state is always 'loaded'), so the FormView variant is fixed loaded/uniform rather than gating on a real loading state. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014zKNfk7XgeJNzunJAg8RvX
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…m-phase-16-rental-checkout # Conflicts: # libs/ui/src/presentation/components/base/Form/FormView.stories.tsx # libs/ui/src/presentation/components/base/Form/FormView.test.tsx # libs/ui/src/presentation/components/base/Form/FormView.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements Phase 16 of
docs/trd-form-ownership-refactor.md(Rental Checkout — Tier C, introducesformRef).Since none of the earlier phases exist on
refactor/formyet, this PR also adds theFormViewprimitive (Phase 1) that Phase 16 depends on, including itsformRefescape hatch (per the TRD,formRefis introduced in Phase 16 with its first real consumer rather than sitting unused).libs/ui/src/presentation/components/base/Form/FormView.tsx(+ stories, tests): the sharedvariant: loading | loaded | errorgate,useFormmount,FormProvider/Formwiring, and the opt-informRefescape hatch (MutableRefObject<UseFormReturn<T> | null>) documented for sibling-controller writes only.domain/entities/Rental.ts: addsrentalCheckoutFormSchema(moved verbatim from the controller). It stays a partial validator ({ raw: true }, nosatisfiesclause) per §4.4.2 since it only enforces "at least one rental" and leaves each item's shape asz.any().RentalCheckoutFormView: now ownsuseFormviaFormView, and owns therentalsfield array via the existingFieldArrayprimitive instead of receiving it as a prop. Also exposes the live "already added" ids toRentalItemSelect(previously read from the controller-owned field array) so the "In Cart" affordance keeps working now that the field array lives inside the view.RentalCheckoutController: stripped down to{ state, dispatch }—useForm, the resolver,useFieldArray, andonAddItemare gone.RentalCheckoutHandler: holds aformRefand writes rentals into the form through it (getValues/setValue, with the same by-id dedupeonAddItemused to do) when the siblingrentalListcontroller reports a selection — the Tier C bridge described in TRD §4.6.RentalCheckoutScreen:form/rentalsFieldArrayprops replaced withvariant,defaultValues,formRef.useForm/useFieldArrayto passingdefaultValues.Behaviour changes
None intended.
RentalCheckoutUsecasehas no fetch step of its own —getInitialState()is synchronously{ type: 'loaded' }— so there's no real loading state to gate on.variantis effectively always{ type: 'loaded' }, kept for uniformity with the otherFormViewconsumers (same reasoning as Phase 5'sWalletTransferFormViewin the TRD) rather than special-cased away. The oldhasFilledFormRef/form.resetworkaround is removed as it was a no-op here (initial values are always{ rentals: [] }, matchingdefaultValuesalready).Deviation from the TRD
FormViewprimitive it modifies, and no earlier phase has landed onrefactor/formyet.formPropspassthrough onFormView(Tamagui<Form>style props) that isn't in the TRD's code sketch —RentalCheckoutFormView's compact vs. desktop layouts need different<Form>styling (flex={1}vsgap="$3"), which the fixedgap="$3"in the TRD's sketch doesn't support. Default behavior for every other future consumer is unchanged.Test plan
npx nx test ui— 161 suites / 1164 tests pass (ran automatically via the pre-commit hook)npx nx lint ui— 0 errors (23 pre-existing warnings, none in touched files)npx nx build-storybook ui— builds cleangrep -r "useForm" libs/ui/src/presentation/controllers/RentalCheckout*→ no hitsRentalCheckoutHandler.test.tsx's existing "In Cart" / duplicate-add / navigation / toast tests all pass unmodified against the newformRef-based add pathFormView.test.tsxcovers: loading/error/loaded rendering, mounting with fetcheddefaultValuesafter a loading→loaded transition, no reset on a loaded→loaded rerender, resolver validation errors, andformRefbeing null while loading / populated once loaded🤖 Generated with Claude Code
https://claude.ai/code/session_014zKNfk7XgeJNzunJAg8RvX
Generated by Claude Code