update product
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import {
|
||||
QueryClient,
|
||||
useMutation,
|
||||
useQuery,
|
||||
useQueryClient,
|
||||
} from "@tanstack/react-query";
|
||||
import * as api from "../service/ProductService";
|
||||
import type { CreateCategoryType } from "../types/Types";
|
||||
import type { CreateCategoryType, CreateProductType } from "../types/Types";
|
||||
|
||||
export const useGetCategory = () => {
|
||||
return useQuery({
|
||||
@@ -54,3 +59,24 @@ export const useCreateProduct = () => {
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetProductDetail = (id: number) => {
|
||||
return useQuery({
|
||||
queryKey: ["product", id],
|
||||
queryFn: () => api.getProductDetail(id),
|
||||
enabled: !!id,
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateProduct = () => {
|
||||
const queryClient = new QueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ id, params }: { id: number; params: CreateProductType }) =>
|
||||
api.updateProduct(id, params),
|
||||
onSuccess: () => {
|
||||
queryClient.refetchQueries({
|
||||
queryKey: ["products"],
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user