Some checks failed
Deploy to Test Environment / deploy-to-test (push) Failing after 46s
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
// src/hooks/queries/useSuggestedCorrectionsQuery.ts
|
|
import { useQuery } from '@tanstack/react-query';
|
|
import { apiClient } from '../../services/apiClient';
|
|
import type { SuggestedCorrection } from '../../types';
|
|
|
|
/**
|
|
* Query hook for fetching user-submitted corrections (admin feature).
|
|
*
|
|
* Returns a list of pending corrections that need admin review/approval.
|
|
*
|
|
* Uses TanStack Query for automatic caching and refetching (ADR-0005 Phase 5).
|
|
*
|
|
* @returns TanStack Query result with SuggestedCorrection[] data
|
|
*/
|
|
export const useSuggestedCorrectionsQuery = () => {
|
|
return useQuery({
|
|
queryKey: ['suggested-corrections'],
|
|
queryFn: async (): Promise<SuggestedCorrection[]> => {
|
|
const response = await apiClient.getSuggestedCorrections();
|
|
|
|
if (!response.ok) {
|
|
const error = await response.json().catch(() => ({
|
|
message: `Request failed with status ${response.status}`,
|
|
}));
|
|
throw new Error(error.message || 'Failed to fetch suggested corrections');
|
|
}
|
|
|
|
return response.json();
|
|
},
|
|
staleTime: 1000 * 60, // 1 minute - corrections change moderately
|
|
});
|
|
};
|