Tabla de inventario agregada
This commit is contained in:
45
apps/web/feactures/inventory/hooks/use-mutation-users.ts
Normal file
45
apps/web/feactures/inventory/hooks/use-mutation-users.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { CreateUser, UpdateUser } from "../schemas/inventory";
|
||||
import { updateUserAction, createUserAction, deleteUserAction, updateProfileAction } from "../actions/actions";
|
||||
|
||||
// Create mutation
|
||||
export function useCreateUser() {
|
||||
const queryClient = useQueryClient();
|
||||
const mutation = useMutation({
|
||||
mutationFn: (data: CreateUser) => createUserAction(data),
|
||||
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['users'] }),
|
||||
// onError: (e) => console.error('Error:', e),
|
||||
})
|
||||
return mutation
|
||||
}
|
||||
|
||||
// Update mutation
|
||||
export function useUpdateUser() {
|
||||
const queryClient = useQueryClient();
|
||||
const mutation = useMutation({
|
||||
mutationFn: (data: UpdateUser) => updateUserAction(data),
|
||||
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['users'] }),
|
||||
onError: (e) => console.error('Error:', e)
|
||||
})
|
||||
return mutation;
|
||||
}
|
||||
|
||||
export function useUpdateProfile() {
|
||||
const queryClient = useQueryClient();
|
||||
const mutation = useMutation({
|
||||
mutationFn: (data: UpdateUser) => updateProfileAction(data),
|
||||
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['users'] }),
|
||||
// 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)
|
||||
})
|
||||
}
|
||||
12
apps/web/feactures/inventory/hooks/use-query-surveys.ts
Normal file
12
apps/web/feactures/inventory/hooks/use-query-surveys.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
'use client'
|
||||
import { useSafeQuery } from "@/hooks/use-safe-query";
|
||||
import { getUsersAction,getProfileAction} from "../actions/actions";
|
||||
|
||||
// Hook for users
|
||||
export function useUsersQuery(params = {}) {
|
||||
return useSafeQuery(['users',params], () => getUsersAction(params))
|
||||
}
|
||||
|
||||
export function useUserByProfile() {
|
||||
return useSafeQuery(['users'], () => getProfileAction())
|
||||
}
|
||||
8
apps/web/feactures/inventory/hooks/use-query-users.ts
Normal file
8
apps/web/feactures/inventory/hooks/use-query-users.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
'use client'
|
||||
import { useSafeQuery } from "@/hooks/use-safe-query";
|
||||
import { getInventoryAction} from "../actions/actions";
|
||||
|
||||
// Hook for users
|
||||
export function useProductQuery(params = {}) {
|
||||
return useSafeQuery(['product',params], () => getInventoryAction(params))
|
||||
}
|
||||
Reference in New Issue
Block a user