From 6da211dd9a44c3530b782c601718b7cc070a8ec8 Mon Sep 17 00:00:00 2001 From: Vula Builder Date: Tue, 23 Jun 2026 08:38:53 +0000 Subject: [PATCH] Deploy --- src/components/sections/FeaturedProducts.tsx | 141 +++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 src/components/sections/FeaturedProducts.tsx diff --git a/src/components/sections/FeaturedProducts.tsx b/src/components/sections/FeaturedProducts.tsx new file mode 100644 index 0000000..ee67cbb --- /dev/null +++ b/src/components/sections/FeaturedProducts.tsx @@ -0,0 +1,141 @@ +'use client' + +import { useState, useCallback } from "react" +import Image from "next/image" +import Link from "next/link" +import Button from "@/components/ui/Button" +import { Plus, ShoppingBag } from 'lucide-react' +import { useMedusaProducts } from "@/hooks/useMedusaProducts" +import { useMedusaCart } from "@/hooks/useMedusaCart" + +const CURRENCY_SYMBOLS: Record = { + zar: "R", + usd: "$", + eur: "€", + gbp: "£", + kes: "KSh", + ngn: "₦", + ghs: "₵", +} + +const formatPrice = (amount: number, code?: string) => { + const sym = CURRENCY_SYMBOLS[(code ?? "").toLowerCase()] ?? (code?.toUpperCase() ?? "") + return `${sym}${(amount / 100).toFixed(2)}` +} + +function ProductCard({ product }: { product: any }) { + const { addToCart } = useMedusaCart() + const [adding, setAdding] = useState(false) + + const handleAddToCart = useCallback( + async (e: React.MouseEvent) => { + e.preventDefault() + e.stopPropagation() + const variant = product.variants?.[0] + if (!variant) return + setAdding(true) + try { + await addToCart(variant.id, 1) + window.dispatchEvent(new CustomEvent("cart-drawer-open")) + } catch { + console.error("Failed to add to cart") + } finally { + setAdding(false) + } + }, + [product, addToCart] + ) + + const price = product.variants?.[0]?.prices?.[0] + + return ( + +
+ {product.thumbnail ? ( + {product.title} + ) : ( +
+ +
+ )} + +
+
+

+ {product.title} +

+ {price && ( +

+ {formatPrice(price.amount, price.currency_code)} +

+ )} +
+ + ) +} + +export default function FeaturedProducts() { + const { products, isLoading } = useMedusaProducts(8) + + if (isLoading) { + return ( +
+
+

+ Featured Drops +

+
+ {Array.from({ length: 4 }).map((_, i) => ( +
+ ))} +
+
+
+ ) + } + + return ( +
+
+
+

+ Featured Drops +

+ + + +
+ {products && products.length > 0 ? ( +
+ {products.slice(0, 8).map((product) => ( + + ))} +
+ ) : ( +
+ +

No products available yet. Check back soon.

+
+ )} +
+
+ ) +}