style: optimize PDP sticky buy box layout, unify card paddings, center product image and add isMounted to fix hydration warning

This commit is contained in:
parsa aghaei committed 2026-07-14 20:04:57 +03:30
1 parent 4d14885feb
commit f2f507723c
1 file changed
+83 -79
+83 -79
View File
@@ -77,8 +77,10 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
const [showRefillModal, setShowRefillModal] = useState(false);
const [itemQuantity, setItemQuantity] = useState(1);
const [allProducts, setAllProducts] = useState<Product[]>([]);
const [isMounted, setIsMounted] = useState(false);
useEffect(() => {
setIsMounted(true);
productService.getProducts({ limit: 999 })
.then((res) => {
const products = res.data;
@@ -176,97 +178,99 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
</div>
{/* Breadcrumbs */}
<nav className="hidden md:flex items-center gap-2 text-xs font-bold text-medical-gray-400 mb-8 overflow-x-auto whitespace-nowrap py-2">
<nav className="hidden md:flex items-center gap-2 text-sm font-semibold text-medical-gray-600 mb-10 overflow-x-auto whitespace-nowrap py-3 border-b border-medical-gray-100">
<button
onClick={() => router.push('/')}
className="hover:text-canina-blue transition-colors font-vazir cursor-pointer"
>
خانه
</button>
<ChevronLeft className="w-3 h-3 flex-shrink-0" />
<ChevronLeft className="w-3.5 h-3.5 flex-shrink-0 text-medical-gray-300" />
<button
onClick={() => router.push(`/shop?category=${product.categorySlug}`)}
className="hover:text-canina-blue cursor-pointer font-vazir"
>
{product.category}
</button>
<ChevronLeft className="w-3 h-3 flex-shrink-0" />
<span className="text-canina-blue font-vazir whitespace-nowrap">{product.name}</span>
<ChevronLeft className="w-3.5 h-3.5 flex-shrink-0 text-medical-gray-300" />
<span className="text-canina-blue font-vazir whitespace-nowrap font-bold">{product.name}</span>
</nav>
{/* Above the Fold Grid */}
<div className="grid md:grid-cols-12 gap-12 items-start mb-12">
{/* Right Column: Product Image Frame (md:col-span-5) */}
<div className="md:col-span-5 w-full">
<motion.div
initial={{ opacity: 0, scale: 0.95 }}
animate={{ opacity: 1, scale: 1 }}
className="bg-white rounded-[2.5rem] border border-medical-gray-200 shadow-xl relative group overflow-hidden h-[380px] flex items-center justify-center p-8"
>
<div className="absolute top-6 left-6 flex flex-col gap-2 z-10">
<div className="px-3 py-1 bg-green-500 text-white rounded-full text-[10px] font-black uppercase tracking-widest flex items-center gap-1 font-vazir shadow-sm">
<CheckCircle2 className="w-3 h-3" />
موجود در انبار
</div>
<div className="px-3 py-1 bg-canina-blue text-white rounded-full text-[10px] font-black uppercase tracking-widest font-vazir whitespace-nowrap shadow-sm">
گرید دارویی اختصاصی
</div>
</div>
<SafeImage
src={product.image}
alt={product.name}
className="max-h-[300px] w-auto object-contain drop-shadow-2xl group-hover:scale-105 transition-transform duration-700"
/>
</motion.div>
</div>
{/* Left Column: Product Title & Description (md:col-span-7) */}
<div className="md:col-span-7 space-y-6">
<div>
<div className="flex flex-wrap items-center gap-3 mb-4">
<div className="px-3 py-1 bg-canina-blue text-white rounded-full text-[10px] font-black uppercase tracking-widest font-vazir whitespace-nowrap shadow-sm">
استاندارد صنعتی آلمان
</div>
{product.specialBadge && (
<div className="px-3 py-1 bg-medical-gray-900 text-white rounded-full text-[10px] font-black uppercase tracking-widest font-vazir whitespace-nowrap shadow-sm">
{product.specialBadge}
</div>
)}
</div>
<h1 dir="ltr" className="text-2xl md:text-3xl lg:text-4xl font-black text-medical-gray-900 leading-tight mb-4 italic font-sans text-left">
{product.name}
</h1>
<p className="text-xl text-canina-blue font-bold italic opacity-70 leading-relaxed max-w-2xl font-vazir mb-6 text-right" dir="rtl">
{pets.length > 0 ? (
product.optimisticTemplate?.replace("[PetName]", activePet?.name || "").replace("[OnSet]", product.onSetOfAction || "به زودی")
) : (
product.scientificTagline
)}
</p>
{fullProduct.shortDescription && (
<p className="text-lg text-medical-gray-600 font-bold leading-relaxed max-w-3xl font-vazir border-r-4 border-canina-blue pr-6 py-2 bg-canina-blue/5 rounded-l-2xl">
{fullProduct.shortDescription}
</p>
)}
{fullProduct.description && (
<div className="text-base text-medical-gray-500 font-medium leading-loose max-w-3xl font-vazir mt-6 space-y-4">
{fullProduct.description.split('\n').filter(Boolean).map((para, pIdx) => (
<p key={pIdx}>{para.trim()}</p>
))}
</div>
)}
</div>
</div>
</div>
{/* Technical & Commerce Sections */}
<div className="grid lg:grid-cols-12 gap-12 items-start border-t border-medical-gray-200 pt-12">
{/* Main Content Area */}
{/* Global Single Grid Layout - Aligns Sticky Buy Box at the Top */}
<div className="grid lg:grid-cols-12 gap-12 items-start">
{/* Right/Main Content Column (lg:col-span-8) */}
<div className="lg:col-span-8 space-y-12">
{/* Above the Fold Grid */}
<div className="grid md:grid-cols-12 gap-12 items-start">
{/* Right Column: Product Image Frame (md:col-span-5) */}
<div className="md:col-span-5 w-full">
<motion.div
initial={{ opacity: 0, scale: 0.95 }}
animate={{ opacity: 1, scale: 1 }}
className="bg-white rounded-[2.5rem] border border-medical-gray-200 shadow-xl relative group overflow-hidden h-[380px] flex items-center justify-center p-8"
>
<div className="absolute top-6 left-6 flex flex-col gap-2 z-10">
<div className="px-3 py-1 bg-green-500 text-white rounded-full text-[10px] font-black uppercase tracking-widest flex items-center gap-1 font-vazir shadow-sm">
<CheckCircle2 className="w-3 h-3" />
موجود در انبار
</div>
<div className="px-3 py-1 bg-canina-blue text-white rounded-full text-[10px] font-black uppercase tracking-widest font-vazir whitespace-nowrap shadow-sm">
گرید دارویی اختصاصی
</div>
</div>
<SafeImage
src={product.image}
alt={product.name}
className="w-full h-full"
imgClassName="max-h-[300px] w-auto object-contain drop-shadow-2xl group-hover:scale-105 transition-transform duration-700 mx-auto my-auto"
/>
</motion.div>
</div>
{/* Left Column: Product Title & Description (md:col-span-7) */}
<div className="md:col-span-7 space-y-6">
<div>
<div className="flex flex-wrap items-center gap-3 mb-4">
<div className="px-3 py-1 bg-canina-blue text-white rounded-full text-[10px] font-black uppercase tracking-widest font-vazir whitespace-nowrap shadow-sm">
استاندارد صنعتی آلمان
</div>
{product.specialBadge && (
<div className="px-3 py-1 bg-medical-gray-900 text-white rounded-full text-[10px] font-black uppercase tracking-widest font-vazir whitespace-nowrap shadow-sm">
{product.specialBadge}
</div>
)}
</div>
<h1 dir="ltr" className="text-2xl md:text-3xl lg:text-4xl font-black text-medical-gray-900 leading-tight mb-4 italic font-sans text-left">
{product.name}
</h1>
<p className="text-xl text-canina-blue font-bold italic opacity-70 leading-relaxed max-w-2xl font-vazir mb-6 text-right" dir="rtl">
{isMounted && pets.length > 0 ? (
product.optimisticTemplate?.replace("[PetName]", activePet?.name || "").replace("[OnSet]", product.onSetOfAction || "به زودی")
) : (
product.scientificTagline
)}
</p>
{fullProduct.shortDescription && (
<p className="text-lg text-medical-gray-600 font-bold leading-relaxed max-w-3xl font-vazir border-r-4 border-canina-blue pr-6 py-2 bg-canina-blue/5 rounded-l-2xl">
{fullProduct.shortDescription}
</p>
)}
{fullProduct.description && (
<div className="text-base text-medical-gray-500 font-medium leading-loose max-w-3xl font-vazir mt-6 space-y-4">
{fullProduct.description.split('\n').filter(Boolean).map((para, pIdx) => (
<p key={pIdx}>{para.trim()}</p>
))}
</div>
)}
</div>
</div>
</div>
{/* Key Benefits Section */}
{fullProduct.keyBenefits && fullProduct.keyBenefits.length > 0 && (
<section className="space-y-8">
<section className="space-y-8 pt-6 border-t border-medical-gray-100">
<div className="flex items-center gap-4">
<div className="w-12 h-12 bg-canina-blue text-white rounded-2xl flex items-center justify-center shadow-lg">
<Star className="w-6 h-6" />
@@ -292,7 +296,7 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
)}
{/* Smart Dosage Calculator Utility Section */}
<section className="bg-white rounded-[2.5rem] border border-medical-gray-200 p-8 shadow-md space-y-8">
<section className="bg-white rounded-[2.5rem] border border-medical-gray-200 p-8 md:p-10 shadow-md space-y-8">
<div className="flex items-center gap-4">
<div className="w-12 h-12 bg-canina-blue text-white rounded-2xl flex items-center justify-center shadow-lg">
<Clock className="w-6 h-6" />
@@ -361,7 +365,7 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
<div className="space-y-10">
{/* Ingredients Cards */}
<div className="bg-white rounded-[2.5rem] p-8 border border-medical-gray-200 shadow-md">
<div className="bg-white rounded-[2.5rem] p-8 md:p-10 border border-medical-gray-200 shadow-md">
<h4 className="text-xs font-black text-medical-gray-400 uppercase tracking-widest mb-6 font-vazir">مواد تشکیل‌دهنده برتر</h4>
<div className="flex flex-wrap gap-3">
{product.main_ingredients.map((ing, idx) => {
@@ -400,7 +404,7 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
</section>
{/* Feeding / Usage Instructions Section (Dynamic Header based on product category) */}
<section className="bg-white border border-medical-gray-200 rounded-[2.5rem] p-10 shadow-md">
<section className="bg-white border border-medical-gray-200 rounded-[2.5rem] p-8 md:p-10 shadow-md">
<div className="flex items-center gap-4 mb-8">
<div className="w-12 h-12 bg-canina-blue text-white rounded-2xl flex items-center justify-center shadow-lg">
<CalendarDays className="w-6 h-6" />
@@ -418,7 +422,7 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
{/* Specialist Note */}
{product.specialist && (
<section className="bg-white rounded-[2.5rem] p-10 border border-medical-gray-200 shadow-md">
<section className="bg-white rounded-[2.5rem] p-8 md:p-10 border border-medical-gray-200 shadow-md">
<div className="flex flex-col md:flex-row gap-10 items-start">
<img
src={product.specialist.image}
@@ -490,8 +494,8 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
)}
</div>
{/* Sticky Sidebar (Clean Buy Box) */}
<div className="lg:col-span-4 lg:sticky lg:top-24 space-y-8">
{/* Sticky Sidebar (Clean Buy Box) - Sticky starts at the top, level with the title */}
<div className="lg:col-span-4 lg:sticky lg:top-10 space-y-8">
<div className="bg-white rounded-[2.5rem] border-2 border-medical-gray-100 p-8 shadow-2xl relative overflow-hidden">
<div className="absolute top-0 right-0 w-24 h-24 bg-canina-blue/5 rounded-full -mr-12 -mt-12" />