users update create delete tested
This commit is contained in:
21
frontend/pages/users/update/queries.tsx
Normal file
21
frontend/pages/users/update/queries.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
'use client'
|
||||
import { useMutation } from '@tanstack/react-query'
|
||||
import { UserUpdate } from './types';
|
||||
|
||||
const fetchGraphQlUsersUpdate = async (record: UserUpdate, uuid: string): Promise<{ data: UserUpdate | null; status: number }> => {
|
||||
console.log('Fetching test data from local API');
|
||||
try {
|
||||
const res = await fetch(`/api/users/update?uuid=${uuid || ''}`, { method: 'POST', cache: 'no-store', credentials: "include", body: JSON.stringify(record) });
|
||||
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, status: res.status }
|
||||
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||
};
|
||||
|
||||
export function useUpdateUserMutation() {
|
||||
return useMutation({
|
||||
mutationFn: ({ data, uuid }: { data: UserUpdate, uuid: string }) => fetchGraphQlUsersUpdate(data, uuid),
|
||||
onSuccess: () => { console.log("User updated successfully") },
|
||||
onError: (error) => { console.error("Update user failed:", error) },
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user