diff --git a/kente-krafters/src/components/ProductCard.jsx b/kente-krafters/src/components/ProductCard.jsx
index 70f4375..69f609e 100644
--- a/kente-krafters/src/components/ProductCard.jsx
+++ b/kente-krafters/src/components/ProductCard.jsx
@@ -5,7 +5,7 @@
* content of the product card.
*/
export function ProductCard({
- id,
+ product_id,
product_name,
description,
price,
@@ -14,7 +14,10 @@ export function ProductCard({
seller_email,
}) {
return (
-
+
{product_name} by {seller_email}
-
- {description}
-
+
{description}
${price}
diff --git a/kente-krafters/src/pages/cart.jsx b/kente-krafters/src/pages/cart.jsx
new file mode 100644
index 0000000..ead0444
--- /dev/null
+++ b/kente-krafters/src/pages/cart.jsx
@@ -0,0 +1,148 @@
+import { useState } from "react";
+
+const Cart = () => {
+ const [quantity, setQuantity] = useState(1);
+ const [selectedSize, setSelectedSize] = useState("2-Yards"); // Default size
+ const [cart, setCart] = useState([]);
+
+ const handleSizeChange = (size) => {
+ setSelectedSize(size);
+ };
+
+ const handleQuantityChange = (amount) => {
+ setQuantity((prevQuantity) => Math.max(1, prevQuantity + amount));
+ };
+
+ const handleDeleteFromCart = (productId) => {
+ console.log("Deleting product with ID:", productId);
+
+ const updatedCart = cart.filter((product) => product.id !== productId);
+ console.log("Updated Cart:", updatedCart);
+
+ setCart(updatedCart);
+ };
+
+ const handleAddToCart = (product) => {
+ const updatedCart = [
+ ...cart,
+ {
+ id: product.id,
+ name: product.name,
+ price: product.price,
+ quantity,
+ size: selectedSize,
+ },
+ ];
+ setCart(updatedCart);
+ // Clear quantity for the next product
+ setQuantity(1);
+ };
+
+ const calculateTotal = () => {
+ return cart.reduce(
+ (total, product) => total + product.price * product.quantity,
+ 0
+ );
+ };
+
+ const products = [
+ {
+ id: 1,
+ name: "Woven Kente Graduation Stole",
+ price: 300,
+ imageSrc: "heroImage1", // Replace with your actual image source
+ },
+ {
+ id: 2,
+ name: "Product 2",
+ price: 150,
+ imageSrc: "heroImage2", // Replace with your actual image source
+ },
+ {
+ id: 3,
+ name: "Product 3",
+ price: 200,
+ imageSrc: "heroImage3", // Replace with your actual image source
+ },
+ ];
+
+ return (
+
+ {products.map((product) => (
+
+
+
+
+
+
+
+ {product.name}
+
+
+ Size: {selectedSize}
+
+
+
+
Quantity
+
+
+
+
+
+
+
+
+
+ ${product.price}
+
+
+
+
+ ))}
+ {/* Total Display */}
+
+
Total:
+
${calculateTotal()}
+
+ {/* Single "Pay Now" Button */}
+
+
+
+
+ );
+};
+
+export default Cart;
diff --git a/kente-krafters/src/pages/checkout.jsx b/kente-krafters/src/pages/checkout.jsx
index 53360a2..0cf1af0 100644
--- a/kente-krafters/src/pages/checkout.jsx
+++ b/kente-krafters/src/pages/checkout.jsx
@@ -9,13 +9,33 @@ import { baseEndPoint } from "../../expressAPI/data";
const CheckOut = () => {
// get the product id from the header parameters from the url
- const productId = window.location.pathname.split("/")[-1];
+ const productId = window.location.pathname.split("/")[2];
+
// get the product data from the backend
const [product, setProduct] = useState({});
+ // useEffect(() => {
+ // // fetch the product data from the backend
+ // const fetchProduct = async () => {
+ // try {
+ // const response = await axios.get(
+ // `${baseEndPoint}product/${productId}`
+ // );
+ // const responseData =
+ // typeof response.data === "string"
+ // ? JSON.parse(response.data)
+ // : response.data;
+ // setProduct(responseData);
+ // } catch (error) {
+ // console.error("Error fetching product:", error);
+ // }
+ // };
+
+ // fetchProduct();
+ // },
useEffect(() => {
- // fetch the product data from the backend
const fetchProduct = async () => {
try {
+ console.log("Fetching product with ID:", productId);
const response = await axios.get(
`${baseEndPoint}product/${productId}`
);
@@ -28,13 +48,14 @@ const CheckOut = () => {
console.error("Error fetching product:", error);
}
};
+
fetchProduct();
- }, [productId]);
+ }, [productId]); // Only include productId in the dependency array, not product
return (
- {product && (
+ {product && product[0] && (
{
- {product && product[0].product_name}
+ {product && product[0] && product[0].product_name}
Graduation Stoles, Gifts, and Decoration
@@ -53,10 +74,10 @@ const CheckOut = () => {
- $ {product && product[0].price}
+ $ {product && product[0] && product[0].price}
- {product && product[0].description}
+ {product && product[0] && product[0].description}
size
diff --git a/kente-krafters/src/pages/kente.jsx b/kente-krafters/src/pages/kente.jsx
index daa7e4d..ec9734b 100644
--- a/kente-krafters/src/pages/kente.jsx
+++ b/kente-krafters/src/pages/kente.jsx
@@ -28,8 +28,11 @@ export default function KenteShopping() {
<>
{products.map((product) => (
-
-
+
+
))}