Deploy
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
'use client'
|
||||
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useEmDashContent } from '@/hooks/useEmDashContent'
|
||||
import Image from 'next/image'
|
||||
import Button from '@/components/ui/Button'
|
||||
|
||||
const CURRENCY_SYMBOLS: Record<string, string> = { 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 Countdown({ availableUntil }: { availableUntil?: string }) {
|
||||
const [timeLeft, setTimeLeft] = useState('')
|
||||
|
||||
useEffect(() => {
|
||||
if (!availableUntil) return
|
||||
const target = new Date(availableUntil).getTime()
|
||||
const update = () => {
|
||||
const now = Date.now()
|
||||
const diff = target - now
|
||||
if (diff <= 0) { setTimeLeft('Expired'); return }
|
||||
const days = Math.floor(diff / (1000 * 60 * 60 * 24))
|
||||
const hours = Math.floor((diff / (1000 * 60 * 60)) % 24)
|
||||
const mins = Math.floor((diff / (1000 * 60)) % 60)
|
||||
setTimeLeft(`${days}d ${hours}h ${mins}m`)
|
||||
}
|
||||
update()
|
||||
const id = setInterval(update, 60000)
|
||||
return () => clearInterval(id)
|
||||
}, [availableUntil])
|
||||
|
||||
return <span className="text-[#dc2626] font-bold text-sm">{timeLeft}</span>
|
||||
}
|
||||
|
||||
export default function StreetSpecialsSection() {
|
||||
const { items, loading } = useEmDashContent('specials')
|
||||
|
||||
if (loading) {
|
||||
return <div className="flex justify-center py-16"><div className="w-8 h-8 rounded-full border-2 border-current border-t-transparent animate-spin" /></div>
|
||||
}
|
||||
|
||||
if (items.length === 0) return null
|
||||
|
||||
return (
|
||||
<section id="street-specials" data-vula-section="streetspecials" data-vula-cms="specials" className="py-20 bg-[#f9fafb]">
|
||||
<div className="container mx-auto px-4">
|
||||
<h2 className="text-4xl font-bold text-[#111827] mb-12 text-center uppercase tracking-tight">Street Specials</h2>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
|
||||
{items.map((item) => {
|
||||
const d = item.data as { title?: string; description?: string; price?: number; available_until?: string; image?: string }
|
||||
return (
|
||||
<div key={item.id} className="rounded-xl border border-[#e5e7eb] bg-white shadow-[var(--shadow-card)] hover:shadow-[var(--shadow-lifted)] hover:-translate-y-1 transition-all duration-200 ease-out overflow-hidden">
|
||||
{d.image && (
|
||||
<div className="aspect-[4/3] overflow-hidden">
|
||||
<Image
|
||||
src={d.image}
|
||||
alt={d.title ?? ''}
|
||||
width={600}
|
||||
height={450}
|
||||
className="object-cover w-full h-full hover:scale-105 transition-transform duration-500 ease-out"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="p-5">
|
||||
<h3 className="text-lg font-bold text-[#18181b] mb-1">{d.title}</h3>
|
||||
<p className="text-[#111827]/70 text-sm leading-relaxed mb-3 line-clamp-3">{d.description}</p>
|
||||
<div className="flex items-center justify-between mb-3">
|
||||
<span className="text-lg font-bold text-[#dc2626]">
|
||||
{formatPrice(d.price ?? 0, 'zar')}
|
||||
</span>
|
||||
<Countdown availableUntil={d.available_until} />
|
||||
</div>
|
||||
<Button variant="default" className="w-full bg-[#dc2626] hover:bg-[#b91c1c] text-white font-semibold py-2.5 rounded-lg">
|
||||
Grab Yours
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user