This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
import { ActionIcon, Group, Loader, ScrollArea, Stack, Table, Title, Tooltip } from "@mantine/core";
|
||||
import { t } from "@/config/i18n";
|
||||
import { useCreateProduct, useEditProduct, useGetProduct, useGetProducts } from "@/services/api";
|
||||
import {
|
||||
useCreateProduct,
|
||||
useDeleteProduct,
|
||||
useEditProduct,
|
||||
useGetProduct,
|
||||
useGetProducts,
|
||||
} from "@/services/api";
|
||||
import { IconPlus } from "@tabler/icons-react";
|
||||
import ProductRow from "@/components/Products/Row";
|
||||
import { useLocation, useNavigate, useSearchParams } from "react-router";
|
||||
@@ -12,6 +18,7 @@ import {
|
||||
type ProductInputs,
|
||||
} from "@/services/resources/products";
|
||||
import ProductsFilters from "@/components/Products/Filter";
|
||||
import { DeleteModal } from "@/components/DeleteModal";
|
||||
|
||||
export default function Products() {
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
@@ -19,9 +26,10 @@ export default function Products() {
|
||||
const navigate = useNavigate();
|
||||
const isCreate = location.pathname === "/dashboard/products/create";
|
||||
const isEdit = location.pathname.includes("/edit");
|
||||
const isDelete = location.pathname.includes("/delete");
|
||||
|
||||
const editId = useMemo(() => {
|
||||
if (isEdit) {
|
||||
if (isEdit || isDelete) {
|
||||
return location.pathname.split("/")[3];
|
||||
}
|
||||
return null;
|
||||
@@ -38,16 +46,14 @@ export default function Products() {
|
||||
const { data: allProducts } = useGetProducts();
|
||||
|
||||
const names = useMemo(() => {
|
||||
if (!allProducts)
|
||||
return [];
|
||||
if (!allProducts) return [];
|
||||
return allProducts
|
||||
?.map((product: Product) => product.name)
|
||||
.filter((season, index, array) => array.indexOf(season) === index);
|
||||
}, [allProducts]);
|
||||
|
||||
const productors = useMemo(() => {
|
||||
if (!allProducts)
|
||||
return [];
|
||||
if (!allProducts) return [];
|
||||
return allProducts
|
||||
?.map((product: Product) => product.productor.name)
|
||||
.filter((productor, index, array) => array.indexOf(productor) === index);
|
||||
@@ -55,6 +61,7 @@ export default function Products() {
|
||||
|
||||
const createProductMutation = useCreateProduct();
|
||||
const editProductMutation = useEditProduct();
|
||||
const deleteProductMutation = useDeleteProduct();
|
||||
|
||||
const handleCreateProduct = useCallback(
|
||||
async (product: ProductInputs) => {
|
||||
@@ -134,6 +141,15 @@ export default function Products() {
|
||||
currentProduct={currentProduct}
|
||||
handleSubmit={handleEditProduct}
|
||||
/>
|
||||
<DeleteModal
|
||||
opened={isDelete}
|
||||
onClose={closeModal}
|
||||
handleSubmit={(id: number) => {
|
||||
deleteProductMutation.mutate(id);
|
||||
}}
|
||||
entityType={"product"}
|
||||
entity={currentProduct}
|
||||
/>
|
||||
<ScrollArea type="auto">
|
||||
<Table striped>
|
||||
<Table.Thead>
|
||||
|
||||
Reference in New Issue
Block a user