Deploy
This commit is contained in:
@@ -0,0 +1,82 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { useMedusaProducts } from '@/hooks/useMedusaProducts'
|
||||||
|
import { useMedusaCart } from '@/hooks/useMedusaCart'
|
||||||
|
import { Card, CardContent } from '@/components/ui/Card'
|
||||||
|
import Button from '@/components/ui/Button'
|
||||||
|
import Badge from '@/components/ui/Badge'
|
||||||
|
import { Eye, ShoppingBag } from 'lucide-react'
|
||||||
|
import Image from 'next/image'
|
||||||
|
import Link from 'next/link'
|
||||||
|
|
||||||
|
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)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function FreshThreadsSection() {
|
||||||
|
const { products, isLoading } = 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-[#dc2626] border-t-transparent animate-spin" /></div>
|
||||||
|
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="freshthreads" id="new-arrivals" className="py-20 bg-white text-[#101418]">
|
||||||
|
<div className="max-w-7xl mx-auto px-4">
|
||||||
|
<h2 className="text-4xl md:text-5xl font-black uppercase tracking-tight text-center mb-12">
|
||||||
|
Fresh Threads
|
||||||
|
</h2>
|
||||||
|
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6">
|
||||||
|
{products.map((product) => {
|
||||||
|
const variant = product.variants?.[0]
|
||||||
|
const price = variant?.prices?.[0]
|
||||||
|
return (
|
||||||
|
<Card key={product.id} className="border-2 border-[#18181b] shadow-[6px_6px_0_0_#18181b] rounded-none group">
|
||||||
|
<Link href={`/products/${product.id}`} className="block relative h-56 w-full overflow-hidden">
|
||||||
|
{product.thumbnail ? (
|
||||||
|
<Image src={product.thumbnail} alt={product.title} fill className="object-cover group-hover:scale-105 transition-transform duration-500 ease-out" sizes="(max-width: 768px) 100vw, 25vw" />
|
||||||
|
) : (
|
||||||
|
<div className="w-full h-full bg-gray-100 flex items-center justify-center">
|
||||||
|
<ShoppingBag className="w-10 h-10 text-gray-400" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<Badge variant="accent" size="sm" className="absolute top-3 left-3 uppercase tracking-wider shadow-[2px_2px_0_0_#18181b]">
|
||||||
|
Just Dropped
|
||||||
|
</Badge>
|
||||||
|
</Link>
|
||||||
|
<CardContent className="p-4 space-y-2">
|
||||||
|
<h3 className="text-base font-black uppercase truncate">{product.title}</h3>
|
||||||
|
<p className="text-lg font-black text-[#dc2626]">
|
||||||
|
{price ? formatPrice(price.amount, price.currency_code) : '—'}
|
||||||
|
</p>
|
||||||
|
<div className="flex gap-2 pt-2">
|
||||||
|
<Button
|
||||||
|
variant="default"
|
||||||
|
size="sm"
|
||||||
|
className="flex-1 uppercase text-xs tracking-widest bg-[#18181b] hover:bg-black shadow-[3px_3px_0_0_#d4af37]"
|
||||||
|
onClick={() => variant && handleQuickAdd(variant.id)}
|
||||||
|
>
|
||||||
|
<ShoppingBag className="w-4 h-4 mr-1" /> Add
|
||||||
|
</Button>
|
||||||
|
<Link href={`/products/${product.id}`}>
|
||||||
|
<Button variant="outline" size="sm" className="uppercase text-xs tracking-wider border-2 border-[#18181b] shadow-[3px_3px_0_0_#18181b]">
|
||||||
|
<Eye className="w-4 h-4" />
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user