Skip to content

Refactor LoginForm to use react-hook-form and zod for validation - #59

Merged
maneesha-xyz merged 9 commits into
OpenGovMail:mainfrom
sanjaiyan-dev:sanjaiyan-react-hook-form
Nov 11, 2026
Merged

maneesha-xyz merged 9 commits into
OpenGovMail:mainfrom
sanjaiyan-dev:sanjaiyan-react-hook-form

Conversation

@sanjaiyan-dev

@sanjaiyan-dev sanjaiyan-dev commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Description

Refactors form handling and validation across the application by migrating from manual useState form management to react-hook-form paired with zod schema validation (@hookform/resolvers). Also includes memory and performance optimizations for recipient parsing in bulk-email workflows.


Summary of Changes

  • Form Migrations & Validation:

    • Migrated LoginForm, RegistrationForm, AddAccountForm, ProfileForm, and ComposeForm / ComposePanel to react-hook-form (useForm, Controller, useWatch).
    • Standardized schema validation and error handling using zod and @hookform/resolvers.
    • Added dependencies: react-hook-form, zod, and @hookform/resolvers.
  • Type Safety:

    • Exported inferred schema types (LoginFormData, RegistrationFormData, etc.).
    • Updated consumers/pages (LoginPage, RegisterPage, ComposePage) to use strongly typed submit handlers.
  • Bulk Recipient Parsing Optimization (ComposePage):

    • Refactored parseRecipients from chained array operations (.map().filter().map()) to a single for...of loop.
    • Why: OpenGovMail frequently deals with large bulk-recipient lists. Moving from multiple intermediate array allocations to a single-pass $O(n)$ traversal reduces memory pressure and overhead significantly compared to $O(3n)$ iterations.

Demo & Performance Proof

📹 Comparison Video: Attached/available below comparing form rendering behavior and responsiveness with React Hook Form vs. without (legacy useState).

Screen.Recording.2026-11-06.at.19.35.33.mov
Screen.Recording.2026-11-06.at.19.34.24.mov

- Replaced manual state management and validation with react-hook-form and zod.
- Introduced a login schema using zod for email and password validation.
- Updated form submission handling to utilize the new validation approach.
- Adjusted the LoginPage to type the form data correctly.
@sanjaiyan-dev
sanjaiyan-dev marked this pull request as ready for review November 9, 2026 14:56
@sanjaiyan-dev

Copy link
Copy Markdown
Contributor Author

Hi @maneesha-xyz , whenever you have some time, this PR is ready for review. No rush at all, please take your time. Any feedback would be greatly appreciated. Thank you!

@maneesha-xyz

Copy link
Copy Markdown
Member

@sanjaiyan-dev there are some conflicts.

…nctionality

- Added mini search capabilities to filter email threads based on subject, last message, and participants.
- Improved sidebar resizing logic with better performance using requestAnimationFrame.
- Added keyboard shortcuts for quick sidebar resizing and default width reset on double-click.
- Enhanced error handling for localStorage operations.
- Refactored search handling to utilize useDeferredValue for smoother user experience.
@sanjaiyan-dev

Copy link
Copy Markdown
Contributor Author

@sanjaiyan-dev there are some conflicts.

Hi @maneesha-xyz, I’ve resolved the merge conflicts with main. The PR is ready for review again whenever you have time. Thank you!

@maneesha-xyz
maneesha-xyz merged commit 152c5fb into OpenGovMail:main Nov 11, 2026
4 checks passed
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.

2 participants