Skip to content

refactor(actions): modularize auth and website logic, add useFormAction hook - #97

Merged
saifulalomdev merged 1 commit into
mainfrom
features
Jun 17, 2026
Merged

refactor(actions): modularize auth and website logic, add useFormAction hook#97
saifulalomdev merged 1 commit into
mainfrom
features

Conversation

@saifulalomdev

Copy link
Copy Markdown
Owner

📝 Description

This PR refactors the project's server actions and custom React hooks to improve code modularity, type-safety, and maintainability. It moves the codebase closer to an independent domain/module layout by breaking down global action definitions and decoupling them from legacy setups.

Key Changes:

  • Module Reorganization: Relocated authentication actions (login, logout) from global entrypoints into a dedicated @/modules/auth/ directory along with a type-safe auth.schema.ts.
  • Action Consolidation: Moved the tracking verification logic out of separate files and consolidated it inside @/modules/website/website.actions.ts under the updated name verifyWebsiteTrackingScript.
  • State & Hook Streamlining: Simplified the core useAction utility hook by swapping out React's experimental/native useTransition for standard useState asynchronous flags, minimizing state bloat.
  • New Reusable Utility: Introduced a type-safe generic useFormAction wrapper that integrates seamlessly with React Hook Form and Zod validation, dropping redundant state rendering inside component structures (like useLogIn).

Fixes # (issue number)

🧪 Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor / Chore (codebase maintenance or optimization)

🛠️ How Has This Been Tested?

  • Local development verification of the login flow and page transitions to /dashboard.

  • Manual tracking validation triggered via the WebsiteManager interface using the modularized edge handler.

  • Type integrity verified against the project build configuration.

  • Unit/Integration tests added/passed (existing Vitest/Supertest suites verified against module changes)

  • Local manual edge verification successful

📸 Screenshots / Diffs (if applicable)

File changes outline:

  • use-form-action.ts (New generic form validation wrapper)
  • auth.actions.ts / auth.schema.ts (Consolidated domain logic)
  • website.actions.ts (Unified verification pipeline script)

✅ Checklist

  • My code follows the brutalist/minimal style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new typescript compiler or linter errors

…on hook

- Relocate login and logout actions into `src/modules/auth/`
- Move `verifyTrackingScript` to `website.actions.ts` and rename to `verifyWebsiteTrackingScript`
- Introduce a reusable `useFormAction` hook using React Hook Form and Zod
- Simplify `useAction` by switching from `useTransition` to a standard async state wrapper
- Clean up unused schema and centralized types under module structures
@saifulalomdev
saifulalomdev merged commit 2d34353 into main Jun 17, 2026
1 check 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.

1 participant