This commit is contained in:
Vula Builder
2026-07-28 07:32:30 +00:00
parent 63dfce2b48
commit ac3b128179
@@ -0,0 +1,86 @@
'use client'
import { useMedusaProducts } from '@/hooks/useMedusaProducts'
import { useMedusaCart } from '@/hooks/useMedusaCart'
import { Card, CardContent, CardFooter } from '@/components/ui/Card'
import Button from '@/components/ui/Button'
import Badge from '@/components/ui/Badge'
import Image from 'next/image'
import Link from 'next/link'
const formatPrice = (amount: number, code?: string) => {
const sym: Record<string, string> = { zar: 'R', usd: '$', eur: '€', gbp: '£' }
const s = sym[(code || '').toLowerCase()] || (code || '').toUpperCase()
return `${s}${(amount / 100).toFixed(2)}`
}
export default function BestsellingBotanicalsGridSection() {
const { products, isLoading, error } = useMedusaProducts(6)
const { addToCart } = useMedusaCart()
if (isLoading) 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 (error) return null
if (!products || products.length === 0) return null
const handleAddToCart = (variantId: string) => {
addToCart(variantId, 1)
window.dispatchEvent(new CustomEvent('cart-drawer-open'))
}
return (
<section data-vula-section="bestsellingbotanicalsgrid" id="bestselling-botanicals" className="py-24 bg-[#f9f5f4]">
<div className="container mx-auto px-4">
<div className="text-center mb-14">
<h2 className="text-4xl font-bold text-[#21140d]">Bestselling Botanicals</h2>
<p className="text-lg text-[#8b5a3c] font-serif italic mt-3">South Africa's favourite natural skincare picks restocked weekly.</p>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
{products.slice(0, 6).map((product, index) => {
const variant = product.variants?.[0]
const price = variant?.prices?.[0]
const isTopSeller = index < 2
return (
<Card key={product.id} className="group cursor-pointer overflow-hidden rounded-xl border-0 shadow-md hover:shadow-xl transition-all duration-200 relative">
<Link href={`/products/${product.id}`}>
<div className="relative aspect-[4/3] overflow-hidden bg-[#e2dad4]">
{product.thumbnail ? (
<Image src={product.thumbnail} alt={product.title} fill sizes="(max-width: 768px) 100vw, 33vw" className="object-cover group-hover:scale-105 transition-transform duration-500" />
) : (
<div className="flex items-center justify-center h-full text-[#8b5a3c]">
<svg className="w-12 h-12" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M15.75 10.5V6a3.75 3.75 0 10-7.5 0v4.5m11.356-1.993l1.263 12c.07.665-.45 1.243-1.119 1.243H4.25a1.125 1.125 0 01-1.12-1.243l1.264-12A1.125 1.125 0 015.513 7.5h12.974c.576 0 1.059.435 1.119 1.007zM8.625 10.5a.375.375 0 11-.75 0 .375.375 0 01.75 0zm7.5 0a.375.375 0 11-.75 0 .375.375 0 01.75 0z" /></svg>
</div>
)}
{isTopSeller && (
<Badge variant="accent" className="absolute top-3 left-3 bg-[#ea580c] text-white">
#{index + 1} Best Seller
</Badge>
)}
</div>
</Link>
<CardContent className="p-4">
<h3 className="font-semibold text-[#21140d] truncate">{product.title}</h3>
{price && (
<p className="text-[#ea580c] font-bold mt-1">{formatPrice(price.amount, price.currency_code)}</p>
)}
</CardContent>
<CardFooter className="px-4 pb-4 pt-0">
<Button
variant="default"
size="sm"
className="w-full bg-[#8b5a3c] hover:bg-[#6a442e] text-white"
onClick={(e) => {
e.preventDefault()
if (variant) handleAddToCart(variant.id)
}}
>
Add to Cart
</Button>
</CardFooter>
</Card>
)
})}
</div>
</div>
</section>
)
}