Template
- Cart drawer: single-column layout matching the site — no bag icon, no dividers, square images, tighter type, discount code form, estimated total, and a Go to Checkout button - Cart: per-line loading state so one row's update no longer disables every other row or the checkout button - Discounts: cartDiscountCodesUpdate mutation plus discountCodes on the cart fragment, wired to an applyDiscountCode store action - Products: fix "load more" returning the same first page — the query now takes an `after` cursor and getProductsPage exposes pageInfo - Collections: cards match the product cards (no border, radius, blurb, or CTA row) at 4-up on desktop and 2-up on mobile; section headers match the products section - Shop Pay: cart permalink with payment=shop_pay instead of the hosted shop-js element - Buttons converted to the shadcn Button component throughout - PDP: swipeable image carousel with dots on mobile, sticky info column, colour swatches never fall back to variant photos - Rename the store from Stride to Shop; larger header wordmark Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016jWbNNJLksC1QG8z8845FX
117 lines
3.0 KiB
TypeScript
117 lines
3.0 KiB
TypeScript
import React from 'react';
|
|
import Link from 'next/link';
|
|
import { truncate } from '@/lib/utils';
|
|
|
|
interface ProductImage {
|
|
url: string;
|
|
altText?: string;
|
|
}
|
|
|
|
interface ProductPrice {
|
|
amount: string;
|
|
currencyCode: string;
|
|
}
|
|
|
|
interface ProductVariant {
|
|
id: string;
|
|
title: string;
|
|
price: ProductPrice;
|
|
availableForSale: boolean;
|
|
}
|
|
|
|
interface Product {
|
|
id: string;
|
|
title: string;
|
|
description?: string;
|
|
handle: string;
|
|
images: {
|
|
edges: Array<{
|
|
node: ProductImage;
|
|
}>;
|
|
};
|
|
priceRange: {
|
|
minVariantPrice: ProductPrice;
|
|
};
|
|
compareAtPriceRange?: {
|
|
minVariantPrice: ProductPrice;
|
|
};
|
|
variants: {
|
|
edges: Array<{
|
|
node: ProductVariant;
|
|
}>;
|
|
};
|
|
}
|
|
|
|
interface ProductCardProps {
|
|
product: Product;
|
|
}
|
|
|
|
const ProductCard: React.FC<ProductCardProps> = ({ product }) => {
|
|
const firstImage = product.images.edges[0]?.node;
|
|
const price = product.priceRange.minVariantPrice;
|
|
const compareAtPrice = product.compareAtPriceRange?.minVariantPrice;
|
|
const hasDiscount =
|
|
compareAtPrice &&
|
|
parseFloat(compareAtPrice.amount) > parseFloat(price.amount);
|
|
const firstVariant = product.variants.edges[0]?.node;
|
|
const isAvailable = firstVariant?.availableForSale || false;
|
|
|
|
const formatPrice = (amount: string) => {
|
|
return `$${parseFloat(amount).toFixed(2)}`;
|
|
};
|
|
|
|
return (
|
|
<Link
|
|
href={`/products/${product.handle}`}
|
|
className="group block h-full"
|
|
>
|
|
{/* Product Image */}
|
|
<div className="relative aspect-square overflow-hidden bg-white">
|
|
{firstImage ? (
|
|
<img
|
|
src={firstImage.url}
|
|
alt={firstImage.altText || product.title}
|
|
className="w-full h-full object-contain transition-transform duration-500 group-hover:scale-[1.04]"
|
|
/>
|
|
) : (
|
|
<div className="absolute inset-0 flex items-center justify-center text-zinc-300">
|
|
<i className="ri-image-line text-8xl"></i>
|
|
</div>
|
|
)}
|
|
|
|
{hasDiscount && compareAtPrice && (
|
|
<span className="absolute top-3 left-3 text-[11px] font-mono tracking-widest text-rose-600">
|
|
SALE
|
|
</span>
|
|
)}
|
|
|
|
{!isAvailable && (
|
|
<span className="absolute top-3 right-3 text-[11px] font-mono tracking-widest text-muted-foreground">
|
|
SOLD OUT
|
|
</span>
|
|
)}
|
|
</div>
|
|
|
|
{/* Product Info */}
|
|
<div className="flex flex-col flex-1 py-2.5">
|
|
<h3 className="text-sm font-medium text-foreground line-clamp-1">
|
|
{truncate(product.title, 65)}
|
|
</h3>
|
|
|
|
<div className="flex flex-wrap items-center gap-x-2 gap-y-1">
|
|
<span className="font-mono tabular-nums tracking-tight text-sm text-foreground">
|
|
{formatPrice(price.amount)}
|
|
</span>
|
|
{hasDiscount && compareAtPrice && (
|
|
<span className="font-mono tabular-nums tracking-tight text-sm line-through text-muted-foreground">
|
|
{formatPrice(compareAtPrice.amount)}
|
|
</span>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</Link>
|
|
);
|
|
};
|
|
|
|
export default ProductCard;
|