105 lines
3.4 KiB
TypeScript
105 lines
3.4 KiB
TypeScript
'use client';
|
|
|
|
import React from 'react';
|
|
import { useParams } from 'next/navigation';
|
|
import { useCollectionProducts } from '@/hooks/use-shopify-collections';
|
|
import ProductCard from './product-card';
|
|
|
|
const CollectionDetail: React.FC = () => {
|
|
const params = useParams();
|
|
const handle = params?.handle as string;
|
|
|
|
const { collection, loading, error, refetch } = useCollectionProducts(handle);
|
|
|
|
// Format title from handle
|
|
const formattedTitle = handle
|
|
? handle.replace(/-/g, ' ').replace(/\b\w/g, l => l.toUpperCase())
|
|
: 'Collection';
|
|
|
|
if (loading) {
|
|
return (
|
|
<div className="pt-4 pb-16">
|
|
<div className="container mx-auto px-4">
|
|
<h2 className="text-4xl font-medium tracking-tight text-center mb-12 text-gray-900 font-heading">
|
|
{formattedTitle}
|
|
</h2>
|
|
|
|
{/* Loading Skeleton */}
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-8">
|
|
{Array.from({ length: 6 }).map((_, index) => (
|
|
<div key={index} className="animate-pulse">
|
|
<div className="aspect-square bg-gray-200"></div>
|
|
<div className="mt-3 h-4 w-2/3 bg-gray-200 rounded"></div>
|
|
<div className="mt-2 h-4 w-1/4 bg-gray-200 rounded"></div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (error) {
|
|
return (
|
|
<div className="pt-4 pb-16">
|
|
<div className="container mx-auto px-4 text-center">
|
|
<h2 className="text-4xl font-medium tracking-tight mb-8 text-gray-900 font-heading">
|
|
{formattedTitle}
|
|
</h2>
|
|
|
|
<div className="bg-red-50 border border-red-200 rounded-md p-8 max-w-md mx-auto">
|
|
<i className="ri-error-warning-line text-4xl text-red-500 mb-4"></i>
|
|
<h3 className="text-lg font-medium text-red-800 mb-2">
|
|
Failed to Load Collection
|
|
</h3>
|
|
<p className="text-red-600 mb-4">
|
|
{error}
|
|
</p>
|
|
<button
|
|
onClick={() => refetch()}
|
|
className="bg-red-600 text-white px-6 py-2 rounded-md hover:bg-red-700 transition-colors"
|
|
>
|
|
Try Again
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const products = collection?.products || [];
|
|
const title = collection?.title || formattedTitle;
|
|
|
|
return (
|
|
<div className="pt-4 pb-16">
|
|
<div className="container mx-auto px-4">
|
|
<h2 className="text-4xl font-medium tracking-tight text-center mb-12 text-gray-900 font-heading">
|
|
{title}
|
|
</h2>
|
|
|
|
{products.length === 0 ? (
|
|
<div className="text-center py-12">
|
|
<div className="bg-gray-50 border border-gray-200 rounded-md p-8 max-w-md mx-auto">
|
|
<i className="ri-shopping-bag-line text-4xl text-gray-400 mb-4"></i>
|
|
<h3 className="text-lg font-medium text-gray-600 mb-2">
|
|
No Products in Collection
|
|
</h3>
|
|
<p className="text-gray-500">
|
|
This collection doesn't have any products yet.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
) : (
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-8">
|
|
{products.map((product) => (
|
|
<ProductCard key={product.id} product={product} />
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default CollectionDetail;
|