diff --git a/src/components/sections/FeaturedProductsSection.tsx b/src/components/sections/FeaturedProductsSection.tsx new file mode 100644 index 0000000..bafc2d9 --- /dev/null +++ b/src/components/sections/FeaturedProductsSection.tsx @@ -0,0 +1,104 @@ +'use client' + +import { useMedusaProducts } from '@/hooks/useMedusaProducts' +import { useMedusaCart } from '@/hooks/useMedusaCart' +import Button from '@/components/ui/Button' +import Link from 'next/link' +import Image from 'next/image' + +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 FeaturedProductsSection() { + const { products, isLoading } = useMedusaProducts(8) + const { addToCart } = useMedusaCart() + + if (isLoading) { + return ( +
+
+
+ ) + } + + if (!products || products.length === 0) return null + + const handleAdd = (variantId: string) => { + addToCart(variantId, 1) + window.dispatchEvent(new CustomEvent('cart-drawer-open')) + } + + return ( + + ) +}