source: frontend/src/components/Product.js

Last change on this file was a2e5735, checked in by Nace Gjorgjievski <nace.gorgievski123@…>, 19 months ago

Final Version

  • Property mode set to 100644
File size: 2.7 KB
Line 
1import React, { useContext } from "react";
2import "../styles/Product.css";
3import ShoppingBasketIcon from "@mui/icons-material/ShoppingCart";
4import { Link } from "react-router-dom";
5import { Store } from "../Store";
6import CheckIcon from "@mui/icons-material/Check";
7import ClearIcon from "@mui/icons-material/Clear";
8
9function 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 (
18 <div
19 className="product__container"
20 style={{ marginLeft: "5px", marginRight: "5px", marginTop: "10px" }}
21 >
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>
29 </div>
30 </Link>
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 >
44 <div className="product__name">
45 <h3>{product.name}</h3>
46 </div>
47 </Link>
48 <div className="product__price">
49 <h3 style={{ textDecoration: "none", color: "black" }}>
50 {product.price}ден
51 </h3>
52 </div>
53 </div>
54 <div
55 style={{
56 display: "flex",
57 justifyContent: "space-around",
58 alignItems: "center",
59 }}
60 >
61 <h5>H: {product.height}</h5>
62 <h5>W: {product.width}</h5>
63 <h5>L: {product.length}</h5>
64 </div>
65 <div
66 className="product__addToCart"
67 style={{ marginTop: "15px", display: "flex", justifyContent: "center" }}
68 >
69 <button onClick={addToCartHandler}>
70 <ShoppingBasketIcon />
71 </button>
72 <div
73 style={{
74 //width: "100%",
75 display: "flex",
76 justifyContent: "center",
77 alignItems: "center",
78 marginLeft: "10px",
79 }}
80 >
81 {product.countInStock > 0 ? (
82 <span style={{ color: "green" }}>
83 <CheckIcon></CheckIcon>Залиха
84 </span>
85 ) : (
86 <span style={{ color: "red" }}>
87 <ClearIcon></ClearIcon>Залиха
88 </span>
89 )}
90 </div>
91 </div>
92 </div>
93 );
94}
95
96export default Product;
Note: See TracBrowser for help on using the repository browser.