[b612ab1] | 1 | import React, { useContext } from "react";
|
---|
| 2 | import "../styles/Product.css";
|
---|
| 3 | import ShoppingBasketIcon from "@mui/icons-material/ShoppingCart";
|
---|
| 4 | import { Link } from "react-router-dom";
|
---|
| 5 | import { Store } from "../Store";
|
---|
[113029b] | 6 | import CheckIcon from "@mui/icons-material/Check";
|
---|
| 7 | import ClearIcon from "@mui/icons-material/Clear";
|
---|
[b612ab1] | 8 |
|
---|
| 9 | function Product({ product }) {
|
---|
| 10 | const { state, dispatch: ctxDispatch } = useContext(Store);
|
---|
| 11 | const addToCartHandler = () => {
|
---|
| 12 | ctxDispatch({
|
---|
| 13 | type: "CART_ADD_ITEM",
|
---|
| 14 | payload: { ...product, quantity: 1 },
|
---|
| 15 | });
|
---|
| 16 | };
|
---|
| 17 | return (
|
---|
[113029b] | 18 | <div
|
---|
| 19 | className="product__container"
|
---|
| 20 | style={{ marginLeft: "5px", marginRight: "5px", marginTop: "10px" }}
|
---|
| 21 | >
|
---|
[55ed171] | 22 | <Link to={`/product/${product.slug}`} style={{ height: "165.91px" }}>
|
---|
| 23 | <div className="product__img" style={{ height: "100%" }}>
|
---|
| 24 | <img
|
---|
| 25 | src={product.image}
|
---|
| 26 | alt="product"
|
---|
| 27 | style={{ height: "100%" }}
|
---|
| 28 | ></img>
|
---|
[b612ab1] | 29 | </div>
|
---|
| 30 | </Link>
|
---|
[113029b] | 31 | <div
|
---|
| 32 | className="product__textContainer"
|
---|
| 33 | style={{
|
---|
| 34 | display: "flex",
|
---|
| 35 | justifyContent: "space-evenly",
|
---|
| 36 | alignItems: "center",
|
---|
| 37 | marginLeft: "25px",
|
---|
| 38 | }}
|
---|
| 39 | >
|
---|
| 40 | <Link
|
---|
| 41 | to={`/product/${product.slug}`}
|
---|
| 42 | style={{ textDecoration: "none", color: "black" }}
|
---|
| 43 | >
|
---|
[b612ab1] | 44 | <div className="product__name">
|
---|
| 45 | <h3>{product.name}</h3>
|
---|
| 46 | </div>
|
---|
| 47 | </Link>
|
---|
| 48 | <div className="product__price">
|
---|
[113029b] | 49 | <h3 style={{ textDecoration: "none", color: "black" }}>
|
---|
| 50 | {product.price}ден
|
---|
| 51 | </h3>
|
---|
[b612ab1] | 52 | </div>
|
---|
| 53 | </div>
|
---|
[113029b] | 54 | <div
|
---|
| 55 | style={{
|
---|
| 56 | width: "100%",
|
---|
| 57 | display: "flex",
|
---|
| 58 | justifyContent: "center",
|
---|
| 59 | alignItems: "center",
|
---|
| 60 | }}
|
---|
| 61 | >
|
---|
| 62 | {product.countInStock > 0 ? (
|
---|
| 63 | <span style={{ color: "green" }}>
|
---|
| 64 | <CheckIcon></CheckIcon>Залиха
|
---|
| 65 | </span>
|
---|
| 66 | ) : (
|
---|
| 67 | <span style={{ color: "red" }}>
|
---|
| 68 | <ClearIcon></ClearIcon>Залиха
|
---|
| 69 | </span>
|
---|
| 70 | )}
|
---|
| 71 | </div>
|
---|
| 72 | <div className="product__addToCart" style={{ marginTop: "15px" }}>
|
---|
[b612ab1] | 73 | <button onClick={addToCartHandler}>
|
---|
| 74 | <ShoppingBasketIcon />
|
---|
| 75 | </button>
|
---|
| 76 | </div>
|
---|
| 77 | </div>
|
---|
| 78 | );
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | export default Product;
|
---|