Deploy
This commit is contained in:
@@ -0,0 +1,89 @@
|
|||||||
|
'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 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: '£',
|
||||||
|
kes: 'KSh', ngn: '₦', ghs: '₵',
|
||||||
|
}
|
||||||
|
const s = sym[(code ?? '').toLowerCase()] ?? (code?.toUpperCase() ?? '')
|
||||||
|
return `${s}${(amount / 100).toFixed(2)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function KasiSelectSection() {
|
||||||
|
const { products, isLoading } = useMedusaProducts(8)
|
||||||
|
const { addToCart } = useMedusaCart()
|
||||||
|
|
||||||
|
if (isLoading) return (
|
||||||
|
<div data-vula-section="kasiselect" 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.length === 0) return null
|
||||||
|
|
||||||
|
const handleAdd = (variantId: string) => {
|
||||||
|
addToCart(variantId, 1)
|
||||||
|
window.dispatchEvent(new CustomEvent('cart-drawer-open'))
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<section id="kasi-select" className="py-20 bg-white">
|
||||||
|
<div className="max-w-7xl mx-auto px-4">
|
||||||
|
<div className="text-center mb-12">
|
||||||
|
<h2 className="text-3xl md:text-5xl font-black uppercase text-[#18181b]">
|
||||||
|
Kasi Select
|
||||||
|
</h2>
|
||||||
|
<p className="mt-3 text-gray-600 max-w-xl mx-auto">
|
||||||
|
8 hand-picked limited-edition pieces — each piece iyi-story.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6">
|
||||||
|
{products.slice(0, 8).map((p) => {
|
||||||
|
const price = p.variants?.[0]?.prices?.[0]
|
||||||
|
return (
|
||||||
|
<Card key={p.id} className="group cursor-pointer hover:shadow-[6px_6px_0_0_#18181b] transition-all duration-200 ease-out border-2 border-[#18181b]">
|
||||||
|
<Link href={`/products/${p.id}`} className="block">
|
||||||
|
<div className="relative aspect-square overflow-hidden border-b-2 border-[#18181b]">
|
||||||
|
<Image
|
||||||
|
src={p.thumbnail || 'https://images.pexels.com/photos/6566502/pexels-photo-6566502.jpeg?auto=compress&cs=tinysrgb&h=350'}
|
||||||
|
alt={p.title}
|
||||||
|
fill
|
||||||
|
sizes="(max-width: 768px) 50vw, 25vw"
|
||||||
|
className="object-cover group-hover:scale-105 transition-transform duration-500 ease-out"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<CardContent className="p-3">
|
||||||
|
<h3 className="font-bold text-sm uppercase truncate text-[#18181b]">{p.title}</h3>
|
||||||
|
{price && (
|
||||||
|
<p className="text-[#dc2626] font-extrabold text-lg mt-1">
|
||||||
|
{formatPrice(price.amount, price.currency_code)}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</CardContent>
|
||||||
|
</Link>
|
||||||
|
<CardFooter className="p-3 pt-0">
|
||||||
|
<Button
|
||||||
|
variant="default"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => handleAdd(p.variants?.[0]?.id || '')}
|
||||||
|
className="w-full bg-[#18181b] hover:bg-black text-white uppercase tracking-wider"
|
||||||
|
disabled={!p.variants?.[0]?.id}
|
||||||
|
>
|
||||||
|
Gcwalisa
|
||||||
|
</Button>
|
||||||
|
</CardFooter>
|
||||||
|
</Card>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user