From 93d2b922ccd41b64389c72e67059d6bd5f1ae06e Mon Sep 17 00:00:00 2001 From: Vula Builder Date: Sun, 11 Oct 2026 14:20:28 +0000 Subject: [PATCH] Deploy --- .../sections/PopularDishesSection.tsx | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 src/components/sections/PopularDishesSection.tsx diff --git a/src/components/sections/PopularDishesSection.tsx b/src/components/sections/PopularDishesSection.tsx new file mode 100644 index 0000000..da3aac4 --- /dev/null +++ b/src/components/sections/PopularDishesSection.tsx @@ -0,0 +1,105 @@ +'use client' +import { useState, useEffect } from 'react' +import { useVulaCart } from '@/hooks/useVulaCart' +import type { VulaProduct } from '@/hooks/useProducts' +import Link from 'next/link' +import { Flame, Utensils } from 'lucide-react' + +const CURRENCY_SYMBOLS: Record = { zar: 'R', usd: '$', eur: '€', gbp: '£', kes: 'KSh', ngn: '₦', ghs: '₵' } +const fmt = (amount: number, code?: string) => { + const sym = CURRENCY_SYMBOLS[(code ?? '').toLowerCase()] ?? (code?.toUpperCase() ?? '') + return `${sym}${(amount / 100).toFixed(2)}` +} + +export default function PopularDishesSection() { + const [dishes, setDishes] = useState([]) + const [loading, setLoading] = useState(true) + const { addToCart } = useVulaCart() + + useEffect(() => { + fetch('/api/popular-products?limit=8') + .then(r => r.ok ? r.json() : Promise.reject(r.status)) + .then(d => { setDishes(d.products ?? []); setLoading(false) }) + .catch(() => { + fetch('/api/products?limit=8') + .then(r => r.json()) + .then(d => { setDishes(d.products ?? []); setLoading(false) }) + .catch(() => setLoading(false)) + }) + }, []) + + if (loading) { + return ( +
+
+
+ {Array.from({ length: 4 }).map((_, i) => ( +
+ ))} +
+
+
+ ) + } + + const featured = dishes.slice(0, 4) + if (!featured.length) return null + + return ( +
+
+
+
+ +
+

Most Ordered

+

Customer Favourites

+
+
+ View Menu → +
+
+ {featured.map((dish, idx) => { + const variant = dish.variants?.[0] + const price = variant?.prices?.[0] + return ( +
+ {idx < 2 && ( + + #{idx + 1} Top Pick + + )} + +
+ {dish.thumbnail ? ( + {dish.title + ) : ( +
+ +
+ )} +
+ +
+ +

{dish.title}

+ + {price && ( +

{fmt(price.amount, price.currency_code)}

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