diff --git a/src/app/product/[id].tsx b/src/app/product/[id].tsx new file mode 100644 index 0000000..85af16f --- /dev/null +++ b/src/app/product/[id].tsx @@ -0,0 +1,128 @@ +import { NextPage } from "next"; +import { useRouter } from "next/router"; +import { useEffect, useState } from "react"; + +// Define a type for the product data +type Product = { + id: string; + name: string; + image: string; + description: string; + specifications: { + manufacturer: string; + model: string; + weight: string; + dimensions: string; + material: string; + warranty: string; + }; + vendors: Array<{ + name: string; + price: string; + stock: string; + }>; +}; + +export default function ProductPage() { + const router = useRouter(); + const { id } = router.query; + const [product, setProduct] = useState(null); + + useEffect(() => { + if (id) { + // Fetch product data based on the id + fetch(`/api/products/${id}`) + .then((response) => response.json()) + .then((data) => setProduct(data)) + .catch((error) => console.error("Error fetching product data:", error)); + } + }, [id]); + + if (!product) { + return
Loading...
; + } + + return ( +
+
+ {/* Product Image */} +
+ {product.name} +
+ + {/* Product Info */} +
+

{product.name}

+ + {/* Vendor Pricing Table */} +
+

Available From

+
+ + + + + + + + + + + {product.vendors.map((vendor, index) => ( + + + + + + + ))} + +
VendorPriceStockAction
{vendor.name}{vendor.price}{vendor.stock} + +
+
+
+
+
+ + {/* Product Description */} +
+

Product Description

+

+ {product.description} +

+
+ + {/* Product Specifications */} +
+

Specifications

+
+
+ Manufacturer: {product.specifications.manufacturer} +
+
+ Model: {product.specifications.model} +
+
+ Weight: {product.specifications.weight} +
+
+ Dimensions: {product.specifications.dimensions} +
+
+ Material: {product.specifications.material} +
+
+ Warranty: {product.specifications.warranty} +
+
+
+
+ ); +}