добавил поиск по slug исправил логику подгрузки конкретного товара
This commit is contained in:
1 parent
a585a6a823
commit
090b641906
6 files changed
+54
-31
No files matched your search
@@ -2,7 +2,7 @@ import { useEffect, useState } from "react";
|
||||
import { useParams, useNavigate } from "react-router-dom";
|
||||
import { ArrowLeftOutlined } from "@ant-design/icons";
|
||||
import { useAppDispatch, useAppSelector } from "../../app/hooks";
|
||||
import { fetchProductById } from "../../features/catalog/productsSlice";
|
||||
import { fetchProductBySlug } from "../../features/catalog/productsSlice";
|
||||
import styles from "./ItemPage.module.css";
|
||||
import Button from "../../components/Button/Button";
|
||||
import PriceLisForm from "../../components/PriceLisForm/PriceLisForm";
|
||||
@@ -11,20 +11,20 @@ import Link from "antd/es/typography/Link";
|
||||
import { setSelectedCategory } from "../../features/catalog/categoriesSlice";
|
||||
|
||||
const ItemPage = () => {
|
||||
const { id } = useParams();
|
||||
const { slug } = useParams();
|
||||
const dispatch = useAppDispatch();
|
||||
const navigate = useNavigate();
|
||||
const { items, loading } = useAppSelector((state) => state.products);
|
||||
const { loading } = useAppSelector((state) => state.products);
|
||||
const { items: cats, selectedCategoryId } = useAppSelector((s) => s.categories);
|
||||
|
||||
const [activeTab, setActiveTab] = useState<"desc" | "chars">("desc");
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (id) dispatch(fetchProductById(id));
|
||||
}, [dispatch, id]);
|
||||
if (slug) dispatch(fetchProductBySlug(slug));
|
||||
}, [dispatch, slug]);
|
||||
|
||||
const product = items.find((item) => item.id === Number(id));
|
||||
const product = useAppSelector((state) => state.products.selectedProduct);
|
||||
const category = cats.find((cat) => cat.id === Number(selectedCategoryId));
|
||||
|
||||
if (loading || !product) {
|
||||
|
||||
Reference in new issue
Block a user