evyos-frontend-development/frontend/pages/living-space/tables/living-spaces/list/queries.tsx

22 lines
1009 B
TypeScript

'use client'
import { useMutation } from '@tanstack/react-query'
const fetchGraphQlDeleteLivingSpace = async (uuid: string): Promise<boolean> => {
console.log('Fetching test data from local API');
try {
const res = await fetch(`/api/living-space/delete?uuid=${uuid}`, { method: 'GET', cache: 'no-store', credentials: "include" });
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
} catch (error) { console.error('Error fetching test data:', error); throw error }
};
export function useDeleteLivingSpacesMutation() {
return useMutation({
mutationFn: ({ uuid }: { uuid: string }) => fetchGraphQlDeleteLivingSpace(uuid),
onSuccess: () => { console.log("Living space deleted successfully") },
onError: (error) => { console.error("Delete living space failed:", error) },
})
}