Deploy
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
'use client'
|
||||
import { useMedusaProducts } from '@/hooks/useMedusaProducts'
|
||||
import { useMedusaCart } from '@/hooks/useMedusaCart'
|
||||
import { Card, CardContent, CardFooter, CardHeader, CardTitle } from '@/components/ui/Card'
|
||||
import Button from '@/components/ui/Button'
|
||||
import Image from 'next/image'
|
||||
import Link from 'next/link'
|
||||
import { ShoppingBag } from 'lucide-react'
|
||||
|
||||
export default function IndigenousBotanicalsFeaturedSection() {
|
||||
const { products, isLoading } = useMedusaProducts(8)
|
||||
const { addToCart } = useMedusaCart()
|
||||
|
||||
const formatPrice = (amount: number, code?: string) => {
|
||||
const symbols: Record<string, string> = { zar: 'R', usd: '$', eur: '€', gbp: '£', kes: 'KSh', ngn: '₦', ghs: '₵' }
|
||||
const sym = symbols[(code ?? '').toLowerCase()] ?? (code?.toUpperCase() ?? '')
|
||||
return `${sym}${(amount / 100).toFixed(2)}`
|
||||
}
|
||||
|
||||
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 (!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="indigenousbotanicalsfeatured" id="indigenous-botanicals" className="py-20 bg-[#f4f5f2]">
|
||||
<div className="container mx-auto px-4">
|
||||
<div className="text-center mb-12">
|
||||
<p className="text-sm uppercase tracking-widest text-[#8b5a3c] mb-2">Ubuhle Bendalo</p>
|
||||
<h2 className="text-3xl md:text-4xl font-bold text-[#2c331f]">Indigenous Botanicals</h2>
|
||||
<p className="text-[#8b5a3c] mt-3 max-w-xl mx-auto">Handpicked from the wild – marula, rooibos, buchu – each jar tells a story of African earth.</p>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6">
|
||||
{products.slice(0, 8).map((product) => {
|
||||
const variant = product.variants?.[0]
|
||||
const price = variant?.prices?.[0]
|
||||
const imgSrc = product.thumbnail || '/placeholder-product.svg'
|
||||
return (
|
||||
<Card key={product.id} className="rounded-2xl border-none shadow-lg hover:shadow-xl transition-shadow duration-300 overflow-hidden bg-white">
|
||||
<Link href={`/products/${product.id}`} className="block relative aspect-square overflow-hidden">
|
||||
<Image src={imgSrc} alt={product.title} fill className="object-cover hover:scale-105 transition-transform duration-500" sizes="(max-width: 768px) 100vw, 300px" />
|
||||
</Link>
|
||||
<CardContent className="p-4 pb-2">
|
||||
<Link href={`/products/${product.id}`} className="hover:underline">
|
||||
<h3 className="font-semibold text-[#2c331f] text-lg truncate">{product.title}</h3>
|
||||
</Link>
|
||||
{price && (
|
||||
<p className="text-[#ea580c] font-bold mt-1">{formatPrice(price.amount, price.currency_code)}</p>
|
||||
)}
|
||||
</CardContent>
|
||||
<CardFooter className="p-4 pt-0">
|
||||
{variant && (
|
||||
<Button variant="default" size="sm" className="w-full bg-[#6b8e23] hover:bg-[#5a7a1e] text-white" onClick={() => handleAddToCart(variant.id)}>
|
||||
<ShoppingBag className="w-4 h-4 mr-2" /> Add to Cart
|
||||
</Button>
|
||||
)}
|
||||
</CardFooter>
|
||||
</Card>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user