diff --git a/src/components/sections/JustDroppedSection.tsx b/src/components/sections/JustDroppedSection.tsx new file mode 100644 index 0000000..9df1371 --- /dev/null +++ b/src/components/sections/JustDroppedSection.tsx @@ -0,0 +1,107 @@ +'use client' + +import { useProducts } from "@/hooks/useProducts" +import { useVulaCart } from "@/hooks/useVulaCart" +import Image from "next/image" +import Link from "next/link" +import Button from "@/components/ui/Button" +import { ShoppingBag, Star } from 'lucide-react' + +export default function JustDroppedSection() { + const { products, isLoading, error } = useProducts(8) + const { addToCart } = useVulaCart() + + const formatPrice = (amount: number) => `R${amount.toFixed(2)}` + + const handleAddToCart = (product: any) => { + if (!product.variants?.length) return + const variant = product.variants?.[0] + addToCart({ + variantId: variant.id, + productId: product.id, + title: product.title, + variant_title: variant.title, + unit_price: variant.price_amount, + quantity: 1, + thumbnail: product.thumbnail ?? null, + }) + window.dispatchEvent(new CustomEvent("cart-drawer-open")) + } + + if (isLoading) { + return ( + + + + Just Dropped + + + + + + + ) + } + + if (error) { + return ( + + + {error} + + + ) + } + + return ( + + + + Just Dropped + + + {products?.map((product: any) => ( + + + {product.thumbnail ? ( + + ) : ( + + + + )} + + + + + {product.title} + + + + {product.price_amount != null ? formatPrice(product.price_amount) : "R0.00"} + + handleAddToCart(product)} + > + + Quick Add + + + + ))} + + + + ) +} \ No newline at end of file
{error}
+ {product.price_amount != null ? formatPrice(product.price_amount) : "R0.00"} +