-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from acm-uic/ProductDescription
Product description
- Loading branch information
Showing
12 changed files
with
233 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { useCartProducts } from "../Domain/cartContext"; | ||
import { useRouter } from "next/navigation"; | ||
|
||
export default function ProductDescription({product ,title, description, quantity, price,setShowNotification,setSelectedQuantity,selectedQuantity }) { | ||
const { addToCart } = useCartProducts(); | ||
const router = useRouter(); | ||
|
||
const quantityOptions = []; | ||
for (let i = 1; i <= quantity; i++) { | ||
{console.log(i)} | ||
quantityOptions.push( | ||
<option key={i} value={i}> | ||
Qty: {i} | ||
</option> | ||
); | ||
} | ||
|
||
function handleAddToCart() { | ||
addToCart(product,selectedQuantity) | ||
setShowNotification(true) | ||
} | ||
|
||
|
||
function handleBuy(){ | ||
addToCart(product,selectedQuantity) | ||
router.push('/Cart') | ||
} | ||
|
||
return ( | ||
<div className="flex w-[55%] h-[65%] flex-col items-center justify-evenly "> | ||
<div className="w-7/12 h-4/6 bg-white flex flex-col items-center justify-center rounded-lg "> | ||
<div className="w-11/12 h-10"> | ||
<h1 className="text-2xl font-bold">{title}</h1> | ||
</div> | ||
<div className="w-11/12 h-0 border border-black"></div> | ||
<div className="w-11/12 h-8"> | ||
<h2 className="text-xl font-bold">${price}</h2> | ||
</div> | ||
<p className="w-11/12 h-56 max-h-56 overflow-hidden py-2">{description}</p> | ||
</div> | ||
<div className="w-7/12 flex flex-row items-center justify-between text-lg font-semibold "> | ||
<button | ||
onClick={handleAddToCart} | ||
className="w-3/5 bg-white h-10 rounded-xl border-[1.5px] border-black hover:scale-110 transition-all duration-300 ease-out" | ||
> | ||
Add to Cart | ||
</button> | ||
<select | ||
name="Qty: " | ||
className="w-1/3 h-10 rounded-lg bg-ACMDARK text-white border-none px-2 cursor-pointer" | ||
onChange={(e) => setSelectedQuantity(parseInt(e.target.value))} | ||
> | ||
{console.log(quantityOptions)} | ||
{quantityOptions} | ||
</select> | ||
</div> | ||
<button onClick={()=>handleBuy()} className="w-7/12 h-10 text-xl font-semibold rounded-xl bg-ACMDARK text-white hover:scale-110 transition-all duration-300 ease-out "> | ||
Buy Now | ||
</button> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React, { useState, useEffect } from "react"; | ||
|
||
export default function Notification({selectedQuantity, setShowNotification,title}) { | ||
const [progress, setProgress] = useState(100); | ||
|
||
useEffect(() => { | ||
const interval = setInterval(() => { | ||
setProgress((prevProgress) => (prevProgress - 1)); | ||
}, 60); | ||
|
||
}, []); | ||
|
||
useEffect(() => { | ||
if (progress <= 0) { | ||
setShowNotification(false); | ||
} | ||
}, [progress, setShowNotification]); | ||
|
||
return ( | ||
<div className="animate-notification absolute w-1/4 h-[80px] translate-y-[-30vh] flex items-center justify-center flex-col bg-ACMDARK text-white rounded-lg"> | ||
<div className="w-11/12 text-xl font-semibold"> | ||
<h1 className="cursor-pointer" onClick={() => setShowNotification(false)}>X</h1> | ||
</div> | ||
<h1 className="text-lg font-semibold mb-2">{title} x{selectedQuantity} add to the cart</h1> | ||
<div className="w-[95%] h-10 bg-black mb-2 "> | ||
<div | ||
className={`h-full bg-white `} | ||
style={{ width: `${progress}%` }} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,35 @@ | ||
export default function product(){ | ||
return( | ||
<div> | ||
<h1>Product Page</h1> | ||
</div> | ||
) | ||
} | ||
"use client" | ||
import { useEffect, useState } from "react"; | ||
import { useTheme } from "../../Domain/ThemeContext"; | ||
import { useProducts } from "@/app/Domain/ProductContext"; | ||
import Image from "next/image"; | ||
import ProductDescription from "@/app/components/ProductDescription"; | ||
import Notification from "@/app/components/notification"; | ||
|
||
export default function Product({ params }) { | ||
const { isDarkMode } = useTheme(); | ||
const { products, getURL } = useProducts(); | ||
const [product, setProduct] = useState({}) | ||
const [showNotification,setShowNotification] = useState(false) | ||
const [selectedQuantity, setSelectedQuantity] = useState(1); | ||
|
||
|
||
useEffect(() => { | ||
const newProduct = products.filter((p) => p.id == params.id); | ||
setProduct(newProduct[0]); | ||
}, [products, params.id]); | ||
|
||
|
||
return ( | ||
<> | ||
<div className={`${isDarkMode ? 'bg-ACMPrimary' : 'bg-ACMBLUE'} flex flex-row items-center justify-center text-ACMDARK h-screen bg-cover bg-center w-full`}> | ||
{showNotification && <Notification title={product?.title} selectedQuantity={selectedQuantity} setShowNotification={setShowNotification}/>} | ||
<div className="w-full h-full flex flex-row items-center justify-center mt-28"> | ||
<Image src={getURL(product)} width={400} height={400} alt={`${product?.title} Image`} /> | ||
<ProductDescription selectedQuantity={selectedQuantity} setSelectedQuantity={setSelectedQuantity} setShowNotification={setShowNotification} product={product} title={product?.title} price={product?.price} quantity={product?.quantity} description={product?.description} /> | ||
</div> | ||
</div> | ||
|
||
</> | ||
); | ||
} |
Oops, something went wrong.