Skip to content

feat: migrate NewConversation to React Hook Form#453

Draft
stephen-dahl wants to merge 7 commits intoChurchApps:mainfrom
stephen-dahl:feat/react-hook-form-newconversation
Draft

feat: migrate NewConversation to React Hook Form#453
stephen-dahl wants to merge 7 commits intoChurchApps:mainfrom
stephen-dahl:feat/react-hook-form-newconversation

Conversation

@stephen-dahl
Copy link

@stephen-dahl stephen-dahl commented Feb 5, 2026

Replace manual useState-based form handling with React Hook Form:

  • Remove useState for message, errors, and isSubmitting
  • Use useForm hook with built-in validation and submission state
  • Register TextField with required and trim validation rules
  • Bridge RHF field errors to existing ErrorMessages component

This serves as a proof-of-concept for adopting RHF in B1App.
NewConversation.tsx was chosen as a minimal example.
ProfileEdit.tsx is the big example.
Not tested locally...

Replace manual useState-based form handling with React Hook Form:
- Remove useState for message, errors, and isSubmitting
- Use useForm hook with built-in validation and submission state
- Register TextField with required and trim validation rules
- Bridge RHF field errors to existing ErrorMessages component

This serves as a proof-of-concept for adopting RHF in B1App.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Feb 5, 2026

Someone is attempting to deploy a commit to the Live Church Solutions Team on Vercel.

A member of the Team first needs to authorize it.

stephen-dahl and others added 4 commits February 5, 2026 08:40
This commit provides a comprehensive, well-documented example of migrating
a complex form from manual useState handling to React Hook Form with Zod.

Key concepts demonstrated with inline comments:
- Zod schema definition with nested objects (name.*, contactInfo.*)
- Email validation pattern: .email().or(z.literal("")) for optional emails
- Type inference with z.infer<typeof schema>
- useForm hook configuration (resolver, defaultValues, mode)
- Controller component pattern for MUI TextField integration
- Dirty field tracking via formState.dirtyFields
- Programmatic setValue() for non-standard inputs (photo editor)
- Async form submission with automatic isSubmitting state
- Form reset to sync with external props

Dependencies added:
- zod: Schema validation library
- @hookform/resolvers: Connects Zod to React Hook Form

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Replace manual field-by-field dirty checking with recursive utilities:
  - flattenDirtyFields(): Converts nested dirtyFields to dot-notation paths
  - getValueByPath(): Generic accessor for nested values
  - buildChangesFromDirtyFields(): Builds changes without manual mapping

- Add documentation explaining RHF's dirty field comparison behavior
  (changing a field back to its default value makes it not dirty)

- Remove unused 'errors' destructuring from formState

- Add TODO comment for deprecated InputLabelProps (MUI v7)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add PROFILE_DEFAULTS constant as single source of truth
- Use spread operator to merge defaults with person data
- Remove verbose educational comments, keep essential ones

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- FormTextField gets control from useFormContext()
- No more passing control prop to every field
- fieldLabels provides labels automatically

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@stephen-dahl stephen-dahl force-pushed the feat/react-hook-form-newconversation branch from b7ca3b6 to a3d36a1 Compare February 5, 2026 19:52
stephen-dahl and others added 2 commits February 5, 2026 16:29
RHF's dirtyFields already handles dirty tracking via defaultValues comparison.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace register() with Controller to match ProfileEdit pattern.
Both forms now use the same approach for MUI TextField integration.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant