|
1 | 1 | import React from "react";
|
2 | 2 | import { useDis } from "react-redux";
|
3 | 3 | import { Button } from "react-bootstrap";
|
4 |
| -import { useParams,useNavigate } from "react-router-dom"; |
| 4 | +import { useParams, useNavigate } from "react-router-dom"; |
5 | 5 | import { useSelector } from "react-redux";
|
6 | 6 | import { selectProduct } from "../../redux/productSelector";
|
7 | 7 | import { ReactComponent as AddToCart } from "../../assets/add_shopping_cart.svg";
|
8 | 8 | import { addItem } from "../../redux/cartSlice";
|
9 | 9 | import ImageGallery from "react-image-gallery";
|
10 | 10 | import "react-image-gallery/styles/css/image-gallery.css";
|
11 |
| -import { Modal } from 'antd'; |
12 |
| -import { ExclamationCircleOutlined } from '@ant-design/icons'; |
| 11 | +import { Modal } from "antd"; |
| 12 | +import { ExclamationCircleOutlined } from "@ant-design/icons"; |
| 13 | +import { selectProducts } from "../../redux/productsSlice"; |
| 14 | +import ProductCard from "../../components/card/ProductCard"; |
| 15 | + |
| 16 | +import Slider from "react-slick"; |
| 17 | +import "slick-carousel/slick/slick.css"; |
| 18 | +import "slick-carousel/slick/slick-theme.css"; |
| 19 | + |
| 20 | + |
13 | 21 |
|
14 | 22 | const Product = () => {
|
| 23 | +//related slider |
| 24 | +let slidesToShow; |
| 25 | +const width = |
| 26 | +window.innerWidth || |
| 27 | +document.documentElement.clientWidth || |
| 28 | +document.body.clientWidth; |
| 29 | +if (width > 1024) { |
| 30 | +slidesToShow = 7; |
| 31 | +} else if (width > 768) { |
| 32 | +slidesToShow = 5; |
| 33 | +} else if(width === 768) { |
| 34 | +slidesToShow = 4; |
| 35 | +} else { |
| 36 | +slidesToShow = 1; |
| 37 | +} |
| 38 | + |
| 39 | +const settings = { |
| 40 | +infinite: true, |
| 41 | +speed: 500, |
| 42 | +slidesToShow, |
| 43 | +slidesToScroll: 1, |
| 44 | +}; |
| 45 | + |
15 | 46 | const dis = useDis();
|
16 | 47 | const navigate = useNavigate();
|
17 | 48 | const { productId } = useParams();
|
@@ -27,6 +58,8 @@ const Product = () => {
|
27 | 58 | gallery,
|
28 | 59 | } = useSelector((state) => selectProduct(state, productId));
|
29 | 60 |
|
| 61 | +const products = useSelector(selectProducts); |
| 62 | + |
30 | 63 | const formatedPrice = price.toLocaleString("en-US", {
|
31 | 64 | style: "currency",
|
32 | 65 | currency: "USD",
|
@@ -43,56 +76,67 @@ const Product = () => {
|
43 | 76 | productId,
|
44 | 77 | active,
|
45 | 78 | })
|
46 |
| -) |
| 79 | +); |
47 | 80 | Modal.confirm({
|
48 |
| -title: 'Product added to your cart', |
| 81 | +title: "Product added to your cart", |
49 | 82 | icon: <ExclamationCircleOutlined />,
|
50 | 83 | content: `You've added the ${title} to your cart`,
|
51 |
| -okText: 'Continue Shopping', |
52 |
| -cancelText: 'Proceed to Checkout', |
53 |
| -onOk:()=> navigate('/shop'), |
54 |
| -onCancel:()=> navigate('/checkout') |
| 84 | +okText: "Continue Shopping", |
| 85 | +cancelText: "Proceed to Checkout", |
| 86 | +onOk: () => navigate("/shop"), |
| 87 | +onCancel: () => navigate("/checkout"), |
55 | 88 | });
|
56 |
| -} |
| 89 | +}; |
| 90 | + |
57 | 91 | return (
|
58 |
| -<div className="product"> |
59 |
| -<div className="product__gallery"> |
60 |
| -<ImageGallery |
61 |
| -items={gallery} |
62 |
| -showNav={false} |
63 |
| -thumbnailPosition={"left"} |
64 |
| -showPlayButton={false} |
65 |
| -/> |
66 |
| -</div> |
67 |
| -<div className="product__description"> |
68 |
| -<div className="product__description__title">{title}</div> |
69 |
| -<div className="product__description__brand"> |
70 |
| -<span>Brand: </span> |
71 |
| -{brand} |
| 92 | +<div> |
| 93 | +<div className="product"> |
| 94 | +<div className="product__gallery"> |
| 95 | +<ImageGallery |
| 96 | +items={gallery} |
| 97 | +showNav={false} |
| 98 | +thumbnailPosition={"left"} |
| 99 | +showPlayButton={false} |
| 100 | +/> |
72 | 101 | </div>
|
73 |
| -<div className="product__description__price"> |
74 |
| -<span>Price: </span> <span>{formatedPrice}</span> |
| 102 | +<div className="product__description"> |
| 103 | +<div className="product__description__title">{title}</div> |
| 104 | +<div className="product__description__brand"> |
| 105 | +<span>Brand: </span> |
| 106 | +{brand} |
| 107 | +</div> |
| 108 | +<div className="product__description__price"> |
| 109 | +<span>Price: </span> <span>{formatedPrice}</span> |
| 110 | +</div> |
| 111 | +<div className="product__description__line" /> |
| 112 | +<div className="product__description__content"> |
| 113 | +<ul> |
| 114 | +{descriptions.map((el, index) => ( |
| 115 | +<li key={index}>{el}</li> |
| 116 | +))} |
| 117 | +</ul> |
| 118 | +</div> |
75 | 119 | </div>
|
76 |
| -<div className="product__description__line" /> |
77 |
| -<div className="product__description__content"> |
78 |
| -<ul> |
79 |
| -{descriptions.map((el, index) => ( |
80 |
| -<li key={index}>{el}</li> |
81 |
| -))} |
82 |
| -</ul> |
| 120 | +<div className="product__cart"> |
| 121 | +<div className="product__cart__price">{formatedPrice}</div> |
| 122 | +<div className="product__cart__button"> |
| 123 | +<Button |
| 124 | +block |
| 125 | +className="checkout__subtotal__button" |
| 126 | +onClick={handleShopCart} |
| 127 | +> |
| 128 | +<AddToCart /> <span>Add to Cart</span> |
| 129 | +</Button> |
| 130 | +</div> |
83 | 131 | </div>
|
84 | 132 | </div>
|
85 |
| -<div className="product__cart"> |
86 |
| -<div className="product__cart__price">{formatedPrice}</div> |
87 |
| -<div className="product__cart__button"> |
88 |
| -<Button |
89 |
| -block |
90 |
| -className="checkout__subtotal__button" |
91 |
| -onClick={handleShopCart} |
92 |
| -> |
93 |
| -<AddToCart /> <span>Add to Cart</span> |
94 |
| -</Button> |
95 |
| -</div> |
| 133 | +<div className="product__related"> |
| 134 | +<h3>Inspired by your recent shopping trends</h3> |
| 135 | +<Slider {...settings}> |
| 136 | +{products.map(({ id, ...props }) => ( |
| 137 | +<ProductCard key={id} productId={id} {...props} /> |
| 138 | +))} |
| 139 | +</Slider> |
96 | 140 | </div>
|
97 | 141 | </div>
|
98 | 142 | );
|
|
0 commit comments