update product

This commit is contained in:
hamid zarghami
2026-01-24 16:27:54 +03:30
parent 480fc056f9
commit 1691be2664
5 changed files with 304 additions and 4 deletions
+28 -2
View File
@@ -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"],
});
},
});
};