Advertisement
maghrabyy

Product Card

Mar 3rd, 2025
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from "react";
  2. import { useNavigate } from "react-router-dom";
  3.  
  4. const ProductCard = ({
  5.   product,
  6.   enabledSelection,
  7.   selected,
  8.   onProductSelected,
  9.   onProductDeselect,
  10. }) => {
  11.   const navigate = useNavigate();
  12.   const selectProductHandler = () => {
  13.     if (enabledSelection) {
  14.       if (selected) {
  15.         onProductDeselect(product);
  16.       } else {
  17.         onProductSelected(product);
  18.       }
  19.     } else {
  20.       navigate(`/products/edit/${product.product_id}`);
  21.     }
  22.   };
  23.   const priceRange = `${product.min_price} EGP - ${product.max_price} EGP`;
  24.   return (
  25.     <div
  26.       onClick={selectProductHandler}
  27.       style={{
  28.         backgroundColor: "lightgrey",
  29.         padding: "20px",
  30.         margin: "10px",
  31.         borderRadius: "10px",
  32.         display: "flex",
  33.         gap: "20px",
  34.         userSelect: selected ? "none" : "auto",
  35.         position: "relative",
  36.       }}
  37.     >
  38.       <div
  39.         style={{
  40.           position: "absolute",
  41.           height: "8px",
  42.           width: "8px",
  43.           borderRadius: "50%",
  44.           backgroundColor: product.is_visible ? "green" : "red",
  45.         }}
  46.       ></div>
  47.       <img
  48.         src="/logo512.png"
  49.         alt="Logo"
  50.         style={{ width: "10rem", height: "10rem" }}
  51.       />
  52.       {/* Content Div --------------------------------------- */}
  53.       <div style={{ width: "100%" }}>
  54.         <div
  55.           style={{
  56.             display: "flex",
  57.             justifyContent: "space-between",
  58.           }}
  59.         >
  60.           <h1>{product.name}</h1>
  61.           {enabledSelection && (
  62.             <input
  63.               type="checkbox"
  64.               checked={selected}
  65.               onChange={() => {}}
  66.               style={{
  67.                 width: "20px",
  68.                 height: "20px",
  69.                 marginRight: "8px",
  70.                 cursor: "pointer",
  71.               }}
  72.             />
  73.           )}
  74.         </div>
  75.         <span>
  76.           {" "}
  77.           {product.variants > 0 ? priceRange : `${product.base_price} EGP`}
  78.         </span>
  79.         <div
  80.           style={{
  81.             display: "flex",
  82.             gap: "1rem",
  83.             justifyContent: "space-between",
  84.           }}
  85.         >
  86.           <div>
  87.             <p style={{ marginBottom: 0 }}>Variants</p>
  88.             <h4 style={{ margin: 0 }}>{product.variants}</h4>
  89.           </div>
  90.           <div>
  91.             <p style={{ marginBottom: 0 }}>Availability</p>
  92.             <h4 style={{ margin: 0 }}>{product.availability || 0}</h4>
  93.           </div>
  94.           <div>
  95.             <p style={{ marginBottom: 0 }}>Ordered</p>
  96.             <h4 style={{ margin: 0 }}>{product.orders || 0}</h4>
  97.           </div>
  98.         </div>
  99.       </div>
  100.     </div>
  101.   );
  102. };
  103.  
  104. export default ProductCard;
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement