35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
import { EditInventory } from "../schemas/inventory";
|
|
import { updateUserAction, createProductAction, updateUserAction2 } from "../actions/actions";
|
|
|
|
// Create mutation
|
|
export function useCreateUser() {
|
|
const queryClient = useQueryClient();
|
|
const mutation = useMutation({
|
|
mutationFn: (data: any) => createProductAction(data),
|
|
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['product'] }),
|
|
})
|
|
return mutation
|
|
}
|
|
|
|
// Update mutation
|
|
export function useUpdateUser() {
|
|
const queryClient = useQueryClient();
|
|
const mutation = useMutation({
|
|
// mutationFn: (data: EditInventory) => updateUserAction(data),
|
|
mutationFn: (data: any) => updateUserAction2(data),
|
|
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['product'] }),
|
|
onError: (e) => console.error('Error:', e)
|
|
})
|
|
return mutation;
|
|
}
|
|
|
|
// Delete mutation
|
|
// export function useDeleteUser() {
|
|
// const queryClient = useQueryClient();
|
|
// return useMutation({
|
|
// mutationFn: (id: number) => deleteUserAction(id),
|
|
// onSuccess: () => queryClient.invalidateQueries({ queryKey: ['users'] }),
|
|
// onError: (e) => console.error('Error:', e)
|
|
// })
|
|
// }
|