delete product
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { type FC, useState } from 'react'
|
import { type FC, useState } from 'react'
|
||||||
import { useGetProducts } from './hooks/useProductData';
|
import { useDeleteProduct, useGetProducts } from './hooks/useProductData';
|
||||||
import { type ProductListType } from './types/Types';
|
import { type ProductListType } from './types/Types';
|
||||||
import { ProductStatus } from './enum/ProductEnum';
|
import { ProductStatus } from './enum/ProductEnum';
|
||||||
import PageLoading from '../../components/PageLoading';
|
import PageLoading from '../../components/PageLoading';
|
||||||
@@ -7,19 +7,22 @@ import Error from '../../components/Error';
|
|||||||
import PaginationUi from '../../components/PaginationUi';
|
import PaginationUi from '../../components/PaginationUi';
|
||||||
import StatusWithText from '../../components/StatusWithText';
|
import StatusWithText from '../../components/StatusWithText';
|
||||||
import Td from '../../components/Td';
|
import Td from '../../components/Td';
|
||||||
|
import TrashWithConfrim from '../../components/TrashWithConfrim';
|
||||||
import PageTitle from '../../components/PageTitle';
|
import PageTitle from '../../components/PageTitle';
|
||||||
import { Edit } from 'iconsax-react';
|
import { Edit } from 'iconsax-react';
|
||||||
import Button from '@/components/Button';
|
import Button from '@/components/Button';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { Pages } from '@/config/Pages';
|
import { Pages } from '@/config/Pages';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
import { toast } from 'react-toastify';
|
||||||
|
import { extractErrorMessage } from '@/helpers/utils';
|
||||||
|
|
||||||
const List: FC = () => {
|
const List: FC = () => {
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
const { data: productsData, isLoading, error } = useGetProducts(currentPage);
|
const { data: productsData, isLoading, error, refetch } = useGetProducts(currentPage);
|
||||||
|
const deleteProductMutation = useDeleteProduct();
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
<div className="flex justify-center items-center min-h-[400px]">
|
<div className="flex justify-center items-center min-h-[400px]">
|
||||||
@@ -143,12 +146,20 @@ const List: FC = () => {
|
|||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* <TrashWithConfrim
|
<TrashWithConfrim
|
||||||
|
isLoading={deleteProductMutation.isPending}
|
||||||
onDelete={() => {
|
onDelete={() => {
|
||||||
// TODO: Implement delete product
|
deleteProductMutation.mutate(product._id, {
|
||||||
console.log('Delete product:', product._id);
|
onSuccess: () => {
|
||||||
|
toast.success('محصول با موفقیت حذف شد');
|
||||||
|
refetch();
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
toast.error(extractErrorMessage(error));
|
||||||
|
}
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
/> */}
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Td>
|
</Td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -98,3 +98,9 @@ export const useSearchProducts = (search: string, enabled: boolean = true) => {
|
|||||||
enabled: enabled,
|
enabled: enabled,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useDeleteProduct = () => {
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (id: number) => api.deleteProduct(id),
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -94,3 +94,8 @@ export const updateProduct = async (params: UpdateProductRequestType): Promise<U
|
|||||||
const { data } = await axios.patch(`/admin/products/update/save`, params);
|
const { data } = await axios.patch(`/admin/products/update/save`, params);
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const deleteProduct = async (id: number) => {
|
||||||
|
const { data } = await axios.delete(`/admin/products/${id}/delete`);
|
||||||
|
return data;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user