feat(frontend): add 6 query/mutation hooks (batches, claims, remits, providers, activity, parse)

This commit is contained in:
Tyler
2026-06-19 19:41:42 -06:00
parent 3ddf962da2
commit d7bd061ee0
6 changed files with 230 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
import { useQuery } from "@tanstack/react-query";
import { useSyncExternalStore } from "react";
import { api, type ListProvidersParams, type PaginatedResponse } from "@/lib/api";
import { useAppStore } from "@/store";
import type { Provider } from "@/types";
/**
* Lists providers. Falls back to the in-memory zustand store when no
* backend is configured; the store carries the full provider directory
* so no pagination is applied in fallback mode.
*/
export function useProviders(params: ListProvidersParams = {}) {
const fallback = useSyncExternalStore(
(cb) => useAppStore.subscribe(cb),
() => useAppStore.getState().providers,
() => useAppStore.getState().providers
);
const q = useQuery<PaginatedResponse<Provider>>({
queryKey: ["providers", params],
queryFn: () => api.listProviders<Provider>(params),
enabled: api.isConfigured,
});
if (!api.isConfigured) {
return {
data: {
items: fallback,
total: fallback.length,
returned: fallback.length,
has_more: false,
} satisfies PaginatedResponse<Provider>,
isLoading: false,
isError: false,
error: null,
refetch: () => Promise.resolve(),
} as const;
}
return q;
}