File size: 7,126 Bytes
f5071ca |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
import React, { useState, useEffect, useContext } from "react";
import "./ProductPaga.css";
import StarIcon from '@mui/icons-material/Star';
import { ProductDetail, WatchDetail, LaptopDetail, headphonesDetail } from "../Details/ProductDetail";
import { shippingDetail, ColorDetail } from '../Details/ProductPageDetail'
import { Link, useParams } from "react-router-dom";
import CartContext from "../ContextApi/CartContext";
const ProductPaga = () => {
const { productList, addtoCart} = useContext(CartContext);
const { id } = useParams();
const [product, setProduct] = useState([])
useEffect(()=> {
let item = [...ProductDetail, ...WatchDetail, ...LaptopDetail, ...headphonesDetail]
let productItem = item.filter(item => {
if(item.id == id)
return item
})
// console.log(productItem);
setProduct(productItem[0])
},[])
return (
<div style={{ backgroundColor: "white" }}>
<main id="container">
<div className="pagination top-bottom-padding">
<p>Sponsored Electronics › Wearable Technology › Smart Watches</p>
</div>
<div className="ProductPaga-container top-bottom-padding left-right-padding">
{/* ---------- */}
<div className="product-showcase" style={{ padding: "1rem" }}>
<SmallProduct Product={ColorDetail} />
</div>
{/* ---------- */}
<div className="product-img-video">
<img
src={`../image/ProductImage/${product.image}`}
alt=""
/>
</div>
{/* ---------- */}
<div className="product-detail" style={{ padding: "1rem" }}>
<div className="product-detail-name">
<p className="bold">
{product.name}
</p>
<span className="product-link">Visit the Noise Store</span>
<div className="flexBox" style={{ justifyContent: "start" }}>
<span>
<StarIcon className="start"/>
<StarIcon className="start"/>
<StarIcon className="start"/>
<StarIcon />
<StarIcon />
</span>
<div className="product-link" style={{ padding: "1rem" }}>
{product.rating} ratings
</div>
<div className="saprete"></div>
<div className="product-link" style={{ padding: "1rem" }}>
587 answered questions
</div>
</div>
</div>
<div className="product-detail-name top-bottom-padding">
<p className="dealBadgeSupportingText">Ends in 03h 28m 15s</p>
<p className="product-price top-bottom-padding">
<sup>₹</sup>{product.price}<sup>00</sup>
</p>
<div className="top-bottom-padding">
Inclusive of all taxes
</div>
<div>
<span className="bold">EMI</span> starts at ₹{product.emi}. No Cost EMI available <span className="product-link">EMI options</span>
</div>
</div>
<div className="product-detail-name top-bottom-padding">
<div className="flexBox">
<EmiSection />
<EmiSection />
<EmiSection />
<EmiSection />
</div>
</div>
<div className="product-detail-name top-bottom-padding">
<div className="flexBox">
<ShippingIcon Product={shippingDetail}/>
</div>
</div>
<ColorSelector Product={ColorDetail} />
<div className="product-detail-name top-bottom-padding">
<h3 className="top-bottom-padding">About this item</h3>
<ul>
<li>{product.about}</li>
</ul>
</div>
</div>
{/* ---------- */}
<div className="product-buying-detail" style={{ padding: "1rem" }}>
<p className="product-price">
<sup>₹</sup>{product.price}<sup>00</sup>
</p>
<p className="bold top-bottom-padding">
<span className="product-link">FREE delivery</span> {product.delivery} <span className="product-link">Details</span>
</p>
<p className="bold top-bottom-padding">
Or fastest delivery Tomorrow, May 2. Order within 8 hrs 17 mins. <span className="product-link">Details</span>
</p>
<span className="product-stock">{product.status}</span>
<Link to='/CartPage'><CartButton name="Add to Cart" color={""} onClick={() => addtoCart(product.id, product.name, product.price, product.status, product.image)}/></Link>
<CartButton name="Buy Now" color={"#FFA41C"} />
</div>
</div>
</main>
</div>
);
};
export default ProductPaga;
export const CartButton = ({ name, color, onClick }) => {
return (
<button
className="cartBtn"
style={{ backgroundColor: `${color || "#FFD814"}` }}
onClick={onClick}
>
{name}
</button>
);
};
export const EmiSection = () => {
return(
<div className="emi-section">
<p className="bold">
No Cost EMI
</p>
<p>
Upto ₹85.51 EMI interest savings on Amazon Pay ICICI…
</p>
<span className="product-link">2 offers</span>
</div>
)
}
export const ShippingIcon = ({Product}) => {
return(
<>
{
Product.map((item)=>(
<div className="shipping-Icon" key={item.id}>
<img src={`../image/ProductImage/${item.image}.png`} alt="" />
<p className="product-link">{item.name}</p>
</div>
))
}
</>
)
}
export const ColorSelector = ({Product}) => {
const [color, setColor] = useState('yello')
function changeColor(item){
setColor(item.color)
console.log(item.color);
}
return(
<div className="product-detail-name top-bottom-padding">
<p>Colour: <span className="bold">{color}</span></p>
<div className="flexBox top-bottom-padding" style={{justifyContent: 'start'}}>
{
Product.map((item)=>(
<div className="color-selector" key={item.id}>
<img onClick={()=> changeColor(item)} src={`../image/ProductImage/${item.image}.jpg`} alt="" />
<p>₹ {item.price}</p>
</div>
))
}
</div>
</div>
)
}
export const SmallProduct = ({Product}) => {
return(
<>
{
Product.map((item)=>(
<div className="small-product" key={item.id}>
<img src={`../image/ProductImage/${item.image}.jpg`} alt="" />
</div>
))
}
</>
)
}
|