Skip to content

Replace manual fetch wrappers with TanStack Query #4

Description

@charming-wicket-5502

Summary

The admin UI currently manages all server state manually using useState + useEffect + custom fetch wrappers (apiGet, apiPost, apiPut, apiDelete in admin-ui/src/services/api.ts). This results in repetitive boilerplate across every page: manual loading/error state, no caching, no background refetching, and no deduplication of in-flight requests.

Current approach

Each resource module (e.g. adminsApi.ts, realmsApi.ts, credentialsApi.ts) wraps raw fetch calls. Pages like CredentialsPage, DashboardPage, and AdminsPage manually wire setLoading(true/false) and setError(...) around every request.

Proposed change

Introduce TanStack Query (@tanstack/react-query) and replace:

  • useEffect + useState data-fetching patterns → useQuery hooks
  • Manual mutation handlers → useMutation hooks with onSuccess cache invalidation
  • Ad-hoc loading/error state → standard isPending / isError from TanStack Query

The existing *Api.ts service functions remain as plain async functions and serve directly as queryFn/mutationFn inputs — no rewrite of the HTTP layer is required.

Benefits

  • Eliminates repetitive loading/error state boilerplate across all pages
  • Automatic caching and background refetching keeps the UI fresh
  • Request deduplication out of the box
  • Simpler, more readable page components

Scope

  • Add @tanstack/react-query to package.json
  • Wrap the app in QueryClientProvider
  • Refactor each page/context that currently uses manual fetch state (CredentialsPage, AdminsPage, RealmsPage, DashboardPage, useRealm context, etc.)
  • Update or replace LoadingState usage where TanStack Query's built-in state suffices

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions