20 lines
1.1 KiB
TypeScript
20 lines
1.1 KiB
TypeScript
'use client'
|
|
import { useQuery } from '@tanstack/react-query'
|
|
import { ListArguments } from '@/types/listRequest'
|
|
import { schemaType } from "./schema";
|
|
|
|
const fetchGraphQlPeopleList = async (params: ListArguments): Promise<{ data: schemaType[], totalCount: number }> => {
|
|
console.log('Fetching test data from local API');
|
|
const { limit, skip, sort, filters } = params;
|
|
try {
|
|
const res = await fetch('/api/people/list', { method: 'POST', cache: 'no-store', credentials: "include", body: JSON.stringify({ limit, skip, sort, filters }) });
|
|
if (!res.ok) { const errorText = await res.text(); console.error('Test data API error:', errorText); throw new Error(`API error: ${res.status} ${res.statusText}`) }
|
|
const data = await res.json();
|
|
return { data: data.data, totalCount: data.totalCount }
|
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
|
};
|
|
|
|
export function useGraphQlPeopleList(params: ListArguments) {
|
|
return useQuery({ queryKey: ['graphql-people-list', params], queryFn: () => fetchGraphQlPeopleList(params) })
|
|
}
|