From bc65495a00ee3ff5914e756e0e096212cdc44942 Mon Sep 17 00:00:00 2001 From: Vula Builder Date: Tue, 23 Jun 2026 08:38:41 +0000 Subject: [PATCH] Deploy --- src/components/shop/MostPopular.tsx | 77 +++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/components/shop/MostPopular.tsx diff --git a/src/components/shop/MostPopular.tsx b/src/components/shop/MostPopular.tsx new file mode 100644 index 0000000..9e26a33 --- /dev/null +++ b/src/components/shop/MostPopular.tsx @@ -0,0 +1,77 @@ +'use client' +import { useMedusaProducts } from '@/hooks/useMedusaProducts' +import { useMedusaCart } from '@/hooks/useMedusaCart' +import Link from 'next/link' +import Image from 'next/image' +import { ShoppingBag, TrendingUp } from 'lucide-react' + +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)}` +} + +export default function MostPopular() { + const { products, loading } = useMedusaProducts(8) + const { addToCart } = useMedusaCart() + const featured = products.slice(0, 4) + + if (loading) return ( +
+
+
+ ) + if (featured.length === 0) return null + + return ( +
+
+ +

Popular Picks

+
+
+ {featured.map((product, idx) => { + const variant = product.variants?.[0] + const price = variant?.prices?.[0] + return ( +
+ {idx < 2 && ( + + Best Seller + + )} + +
+ {product.thumbnail ? ( + {product.title + ) : ( +
+ +
+ )} +
+ +
+ +

{product.title}

+ + {price && ( +

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

+ )} + +
+
+ ) + })} +
+
+ ) +}