Adopt React Query and live updates across all UI pages
Replace custom useApi/useAgents hooks with @tanstack/react-query. Add LiveUpdatesProvider for WebSocket-driven cache invalidation. Add queryKeys module for centralized cache key management. Rework all pages and dialogs to use React Query mutations and queries. Improve CompanyContext with query-based data fetching. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
import { useCallback } from "react";
|
||||
import { agentsApi } from "../api/agents";
|
||||
import { useApi } from "./useApi";
|
||||
|
||||
export function useAgents(companyId: string | null) {
|
||||
const fetcher = useCallback(() => {
|
||||
if (!companyId) return Promise.resolve([]);
|
||||
return agentsApi.list(companyId);
|
||||
}, [companyId]);
|
||||
return useApi(fetcher);
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import { useState, useEffect, useCallback } from "react";
|
||||
|
||||
export function useApi<T>(fetcher: () => Promise<T>) {
|
||||
const [data, setData] = useState<T | null>(null);
|
||||
const [error, setError] = useState<Error | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
const load = useCallback(() => {
|
||||
setLoading(true);
|
||||
fetcher()
|
||||
.then(setData)
|
||||
.catch(setError)
|
||||
.finally(() => setLoading(false));
|
||||
}, [fetcher]);
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, [load]);
|
||||
|
||||
return { data, error, loading, reload: load };
|
||||
}
|
||||
Reference in New Issue
Block a user