Skip to content

feat(hooks): add useApiMutation hook for API write flows (#301) - #462

Merged
mikewheeleer merged 2 commits into
Agentpay-Org:mainfrom
mysterio123865:feature/hooks-use-api-mutation
Jul 28, 2026
Merged

feat(hooks): add useApiMutation hook for API write flows (#301)#462
mikewheeleer merged 2 commits into
Agentpay-Org:mainfrom
mysterio123865:feature/hooks-use-api-mutation

Conversation

@mysterio123865

Copy link
Copy Markdown
Contributor

Closes #301

Summary

Implements Issue #301 by introducing a reusable useApiMutation hook to simplify and standardize API mutation handling across the application.

Changes

  • Added src/lib/useApiMutation.ts

    • Exposes mutate, status, error, and reset
    • Handles request cancellation on component unmount or mutation supersession
    • Prevents stale responses from updating state after cancellation
  • Added comprehensive tests:

    • src/lib/__tests__/useApiMutation.test.tsx
    • 14 tests covering mutation states, cancellation behavior, error handling, reset flow, and edge cases
    • Achieved ~97% branch coverage
  • Migrated src/app/services/new/page.tsx to use the new mutation hook

  • Added documentation:

    • Updated docs/hooks.md with usage details and examples

Validation

✅ Lint passed on changed files
✅ Related tests passed (29 tests)
npm run build completed successfully

Note: The full test suite still reports existing failures in api-keys/page.test.tsx, which are already present on the main branch and are unrelated to this change.

Tracking

Closes #301

Commit

feat(hooks): add useApiMutation for write flows

@mikewheeleer

Copy link
Copy Markdown
Contributor

solid PR @mysterio123865 — clear diff, good coverage. merging 🙌

@mikewheeleer
mikewheeleer merged commit fb85dd4 into Agentpay-Org:main Jul 28, 2026
0 of 2 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.

Add a useApiMutation hook for POST and DELETE flows

2 participants