Skip to content

🧩 Refactor: Profile & Contacts – Zod Validation + Typed Query Hooks #290

@mahid797

Description

@mahid797

Standardize the Profile and Contacts flows with shared Zod schemas, typed TanStack Query hooks, and a unified form structure. This improves type safety, form consistency, and long-term maintainability.


🎯 Goals

  • Refactor name and password update flows to use Zod + RHF
  • Replace legacy useSession() and useEffect logic with useQuery-based data access
  • Introduce type-safe fetching of contact/visitor info via React Query
  • Prepare mutation hooks for future contact update/delete support

🔧 Tasks

  • Migrate name and password form logic to use useFormWithSchema() with profileSchemas.ts
  • Remove reliance on useSession() for form pre-fill; use useProfileQuery() instead
  • Implement and connect the following TanStack hooks:
    • useProfileQuery
    • useUpdateNameMutation
    • useUpdatePasswordMutation
  • Add contactSchemas.ts for contact models and future visitor info structures
  • Implement useContactsQuery and confirm server typings align with Zod types
  • Refactor frontend contact views to consume the typed query
  • Ensure all submit buttons are disabled unless form is dirty + valid
  • Replace any raw Axios/fetch calls in the above flows with the new hooks

✅ Acceptance Criteria

  • Forms for name and password updates are fully validated via RHF + Zod
  • Contact info is fetched using typed query hooks
  • No usage of useSession() remains in form logic
  • All APIs throw typed Zod errors and display them using our toast or inline error components
  • Manual testing completed for various session modes and edge cases

🧠 Notes

  • Mutations for updating or deleting contacts will be added later as needed
  • Enums such as UserRole should be used in schema validation where applicable

Metadata

Metadata

Labels

BackendBackend Related IssueFrontendFrontend Related IssueRefactorCode Improvement🌱Nice-to-HaveEnhancements, Refactors, UI tweaks, or non-critical optimizations

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions