fix crud product

This commit is contained in:
hamid zarghami
2026-02-25 14:07:12 +03:30
parent f3f7e9c3ec
commit 0c736f19a0
6 changed files with 12 additions and 14 deletions
+1 -2
View File
@@ -25,7 +25,6 @@ const CreateProduct: FC = () => {
const { mutate: createProduct, isPending } = useCreateProduct()
const handleSave = (values: CreateProductType) => {
values.categoryId = Number(values.categoryId)
createProduct(values, {
onSuccess: () => {
toast.success('عملیات با موفقیت انجام شد')
@@ -40,7 +39,7 @@ const CreateProduct: FC = () => {
const formik = useFormik<CreateProductType>({
initialValues: {
categoryId: undefined,
categoryId: '',
desc: '',
images: [],
isActive: true,
+2 -3
View File
@@ -22,13 +22,12 @@ const UpdateProduct: FC = () => {
const navigate = useNavigate()
const { id } = useParams()
const [files, setFiles] = useState<File[]>([])
const { data: product, refetch } = useGetProductDetail(Number(id))
const { data: product, refetch } = useGetProductDetail(id!)
const { mutate: upload, isPending: isUploading } = useMultiUpload()
const { mutate: updateProduct, isPending } = useUpdateProduct()
const handleSave = (values: CreateProductType) => {
values.categoryId = Number(values.categoryId)
updateProduct({ id: Number(id), params: values }, {
updateProduct({ id: id!, params: values }, {
onSuccess: () => {
toast.success('عملیات با موفقیت انجام شد')
refetch()
+2 -2
View File
@@ -65,7 +65,7 @@ export const useCreateProduct = () => {
});
};
export const useGetProductDetail = (id: number) => {
export const useGetProductDetail = (id: string) => {
return useQuery({
queryKey: ["product", id],
queryFn: () => api.getProductDetail(id),
@@ -76,7 +76,7 @@ export const useGetProductDetail = (id: number) => {
export const useUpdateProduct = () => {
const queryClient = new QueryClient();
return useMutation({
mutationFn: ({ id, params }: { id: number; params: CreateProductType }) =>
mutationFn: ({ id, params }: { id: string; params: CreateProductType }) =>
api.updateProduct(id, params),
onSuccess: () => {
queryClient.refetchQueries({
+2 -2
View File
@@ -31,7 +31,7 @@ export const getProducts = async () => {
return data;
};
export const getProductDetail = async (id:number) => {
export const getProductDetail = async (id:string) => {
const { data } = await axios.get<ProductDetailResponeType>(`/admin/products/${id}`);
return data;
};
@@ -41,7 +41,7 @@ export const createProduct = async (params:CreateProductType) => {
return data;
};
export const updateProduct = async (id: number, params:CreateProductType) => {
export const updateProduct = async (id: string, params:CreateProductType) => {
const { data } = await axios.patch(`/admin/products/${id}`, params);
return data;
};
+3 -3
View File
@@ -8,7 +8,7 @@ export interface CategoryType extends RowDataType {
children: CategoryType[];
createdAt: string;
deletedAt: string | null;
id: number;
id: string;
isActive: boolean;
order: number | null;
parent: CategoryType | null;
@@ -27,7 +27,7 @@ export type CreateCategoryType = {
}
export type CreateProductType = {
categoryId?: number,
categoryId?: string,
title: string,
desc: string,
linkUrl: string,
@@ -41,7 +41,7 @@ export type ProductType = {
category: CategoryType,
createdAt: string,
desc: string,
id: number,
id: string,
images: string[],
isActive: boolean,
linkUrl: string,