Deploy
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
'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 BotanicalTreasuresSection() {
|
||||
const { products, isLoading, error } = useMedusaProducts(8)
|
||||
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 handleQuickAdd = (variantId: string) => {
|
||||
addToCart(variantId, 1)
|
||||
window.dispatchEvent(new CustomEvent('cart-drawer-open'))
|
||||
}
|
||||
|
||||
return (
|
||||
<section data-vula-section="botanicaltreasures" id="botanical-treasures" className="py-20 bg-[#f9f5f4]">
|
||||
<div className="container mx-auto px-4">
|
||||
<div className="text-center mb-14">
|
||||
<h2 className="text-4xl font-bold text-[#21140d]">Botanical Treasures</h2>
|
||||
<p className="text-lg text-[#8b5a3c] font-serif italic mt-3 max-w-xl mx-auto">Eight small-batch essentials cold-pressed with ancestral care</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]
|
||||
return (
|
||||
<Card key={product.id} className="group cursor-pointer overflow-hidden rounded-xl border-0 shadow-md hover:shadow-xl transition-all duration-200">
|
||||
<Link href={`/products/${product.id}`}>
|
||||
<div className="relative aspect-square overflow-hidden bg-[#e2dad4]">
|
||||
{product.thumbnail ? (
|
||||
<Image src={product.thumbnail} alt={product.title} fill sizes="(max-width: 768px) 100vw, 25vw" 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>
|
||||
)}
|
||||
{product.tags?.includes('best-seller') && (
|
||||
<Badge variant="accent" className="absolute top-3 left-3 bg-[#ea580c] text-white">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) handleQuickAdd(variant.id)
|
||||
}}
|
||||
>
|
||||
Quick Add
|
||||
</Button>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user