feat(products): add product gallery, image zoom lightbox, clean duplicate analysis/usage sections and style catalog button
Deploy Canina / deploy (push) Successful in 1m47s

This commit is contained in:
parsa aghaei committed 2026-08-17 17:16:56 +03:30
1 parent 43f59813b6
commit 4cbde63b89
6 files changed
+343 -200

No files matched your search

+7 -7
View File
@@ -110,13 +110,13 @@ export default function Footer({
</Link>
</li>
<li>
<Link
href="/catalog"
className="inline-flex items-center gap-3 px-6 py-3 bg-canina-blue/10 border border-canina-blue/20 rounded-2xl text-canina-blue text-xs font-black hover:bg-canina-blue hover:text-white transition-all shadow-sm group"
>
<Download className="w-4 h-4 group-hover:-translate-y-0.5 transition-transform" />
<span>مشاهده و دانلود کاتالوگ آنلاین محصولات</span>
</Link>
<Link
href="/catalog"
className="inline-flex items-center justify-center gap-2.5 px-5 py-3 bg-canina-blue hover:bg-blue-600 text-white rounded-2xl text-xs font-black transition-all shadow-lg shadow-canina-blue/30 hover:scale-[1.02] border border-blue-400/30 group cursor-pointer"
>
<Download className="w-4 h-4 text-amber-300 group-hover:-translate-y-0.5 transition-transform" />
<span>مشاهده و دانلود کاتالوگ آنلاین محصولات</span>
</Link>
</li>
{isB2BEnabled && (
<li onClick={onB2BOpen} className="hover:text-canina-blue hover:translate-x-[-4px] transition-all cursor-pointer flex items-center gap-2 group text-blue-200">
+213 -137
View File
@@ -80,6 +80,9 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
const [isMounted, setIsMounted] = useState(false);
const [dosageConfig, setDosageConfig] = useState<DosageConfig | null>(null);
const [activeImage, setActiveImage] = useState<string | null>(null);
const [isImageZoomOpen, setIsImageZoomOpen] = useState(false);
useEffect(() => {
Promise.resolve().then(() => setIsMounted(true));
}, []);
@@ -88,6 +91,7 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
productService.getProductBySlug(productSlug)
.then(p => {
setProduct(p);
if (p?.image) setActiveImage(p.image);
return productService.getProducts({ limit: 50 });
})
.then(res => {
@@ -256,12 +260,14 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
{/* Above the Fold Grid */}
<div className="grid grid-cols-1 md:grid-cols-12 gap-8 md:gap-12 items-center md:items-start text-center md:text-right font-vazir w-full" dir="rtl">
{/* Right Column: Product Image Frame (md:col-span-5) */}
<div className="md:col-span-5 w-full mx-auto max-w-sm md:max-w-none">
{/* Right Column: Product Image Frame & Gallery (md:col-span-5) */}
<div className="md:col-span-5 w-full mx-auto max-w-sm md:max-w-none space-y-4">
<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-[300px] sm:h-[380px] flex items-center justify-center p-6 sm:p-8"
onClick={() => setIsImageZoomOpen(true)}
className="bg-white rounded-[2.5rem] border border-medical-gray-200 shadow-xl relative group overflow-hidden h-[300px] sm:h-[380px] flex items-center justify-center p-6 sm:p-8 cursor-zoom-in"
title="کلیک برای مشاهده تصویر بزرگتر"
>
<div className="absolute top-4 left-4 sm:top-6 sm:left-6 flex flex-col gap-1.5 sm:gap-2 z-10 items-start">
<div className="px-2.5 py-1 bg-green-500 text-white rounded-full text-[9px] sm:text-[10px] font-black uppercase tracking-widest flex items-center gap-1 font-vazir shadow-sm">
@@ -273,12 +279,51 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
</div>
</div>
<SafeImage
src={product.image}
src={activeImage || product.image}
alt={product.name}
className="w-full h-full"
imgClassName="max-h-[240px] sm:max-h-[300px] w-auto object-contain drop-shadow-2xl group-hover:scale-105 transition-transform duration-700 mx-auto my-auto"
/>
<div className="absolute bottom-4 right-4 bg-black/60 backdrop-blur-md text-white px-3 py-1 rounded-full text-[10px] font-black flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity">
<span>بزرگ‌نمایی</span>
</div>
</motion.div>
{/* Multiple Gallery Thumbnails Strip */}
{(() => {
const allGalleryImages = [
product.image,
...(product.images || []).filter(img => img && img !== product.image)
].filter(Boolean);
if (allGalleryImages.length <= 1) return null;
return (
<div className="flex items-center gap-2 overflow-x-auto py-2 px-1 sleek-hscroll">
{allGalleryImages.map((imgUrl, idx) => {
const isSelected = (activeImage || product.image) === imgUrl;
return (
<button
key={idx}
type="button"
onClick={() => setActiveImage(imgUrl)}
className={`relative w-16 h-16 rounded-2xl overflow-hidden bg-white border-2 transition-all shrink-0 p-1 cursor-pointer ${
isSelected
? 'border-canina-blue shadow-md scale-105 ring-2 ring-canina-blue/20'
: 'border-medical-gray-200 hover:border-canina-blue/50 opacity-70 hover:opacity-100'
}`}
>
<img
src={imgUrl}
alt={`${product.name} - ${idx + 1}`}
className="w-full h-full object-contain"
/>
</button>
);
})}
</div>
);
})()}
</div>
{/* Left Column: Product Title & Description (md:col-span-7) */}
@@ -394,39 +439,15 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
</section>
)}
{/* Smart Dosage Calculator Utility Section / Topical Usage Notice */}
{fullProduct.categorySlug === 'special-care' ||
fullProduct.name.toLowerCase().includes('pfotenpflege') ||
fullProduct.name.toLowerCase().includes('augenpflege') ||
fullProduct.unit?.includes('ml Lotion') ||
fullProduct.unit?.includes('Balsam') ||
fullProduct.nameFa?.includes('کرم') ||
fullProduct.nameFa?.includes('قطره تمیزکننده') ||
fullProduct.nameFa?.includes('اسپری') ? (
<section className="bg-white rounded-[2.5rem] border border-medical-gray-200 p-8 md:p-10 shadow-md space-y-6">
<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">
<Sparkles className="w-6 h-6" />
</div>
<div>
<h3 className="text-2xl font-black text-medical-gray-900 italic font-vazir">نحوه استفاده موضعی و کاربرد</h3>
<p className="text-xs text-medical-gray-400 font-bold font-vazir mt-1">محصولات بهداشتی و بهداشت موضعی نیاز به دوزبندی بر اساس وزن ندارند</p>
</div>
</div>
<div className="bg-medical-gray-50 rounded-[2rem] p-6 border border-medical-gray-100 flex items-start gap-4">
<div className="w-10 h-10 rounded-xl bg-canina-blue/10 text-canina-blue flex items-center justify-center font-black flex-shrink-0">
ℹ️
</div>
<div>
<h4 className="text-sm font-black text-medical-gray-900 mb-1 font-vazir">راهنمای مصرف موضعی</h4>
<p className="text-xs text-medical-gray-600 font-bold font-vazir leading-relaxed">
این محصول یک فرآورده موضعی/بهداشتی است و مقدار مصرف آن به صورت موضعی (روی پوست، چشم یا پنجه) اعمال می‌شود و وابسته به وزن بدن حیوان نمی‌باشد. ماندگاری بسته بسته به میزان و تکرار مصرف روزانه شما متفاوت خواهد بود.
</p>
</div>
</div>
</section>
) : (
{/* Smart Dosage Calculator Utility Section (Only for oral/dosed products, not topical products) */}
{!(fullProduct.categorySlug === 'special-care' ||
fullProduct.name.toLowerCase().includes('pfotenpflege') ||
fullProduct.name.toLowerCase().includes('augenpflege') ||
fullProduct.unit?.includes('ml Lotion') ||
fullProduct.unit?.includes('Balsam') ||
fullProduct.nameFa?.includes('کرم') ||
fullProduct.nameFa?.includes('قطره تمیزکننده') ||
fullProduct.nameFa?.includes('اسپری')) && (
<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">
@@ -511,69 +532,108 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
<div className="space-y-8">
{/* Ingredients Cards */}
<div>
<h4 className="text-xs font-black text-medical-gray-400 uppercase tracking-widest mb-4 font-vazir">مواد تشکیل‌دهنده برتر</h4>
<div className="flex flex-wrap gap-3">
{product.main_ingredients.map((ing, idx) => {
const termKey = termKeys.find(key => {
const termObj = scientificTerms[key] || SCIENTIFIC_TERMS[key];
const termName = termObj?.term || key;
const ingClean = ing.toLowerCase();
const keyClean = key.toLowerCase();
const termNameClean = termName.toLowerCase();
return ingClean.includes(keyClean) ||
keyClean.includes(ingClean) ||
ingClean.includes(termNameClean) ||
termNameClean.includes(ingClean);
});
return (
<div key={idx} className="bg-medical-gray-50 border border-medical-gray-100 px-5 py-3 rounded-2xl flex items-center gap-3 group hover:border-canina-blue/30 transition-all">
<span className="text-sm font-bold text-medical-gray-700 font-vazir">
{termKey ? (
<Tooltip termKey={termKey} onWikiNavigate={(id) => router.push(`/wiki?term=${id}`)}>
{ing}
</Tooltip>
) : ing}
</span>
<Sparkles className="w-3 h-3 text-canina-blue opacity-40 group-hover:opacity-100 transition-opacity" />
</div>
);
})}
</div>
</div>
{/* Analysis Cards Grid */}
{Object.keys(product.analysis).length > 0 && (
<div className="space-y-6">
<div className="text-[10px] font-black text-medical-gray-400 uppercase tracking-widest mb-4 font-vazir">تخمین اتمام بسته (هوش مصنوعی)</div>
<div className="grid grid-cols-2 gap-4">
{Object.entries(product.analysis).map(([key, value]) => (
<div key={key} className="bg-canina-blue text-white p-8 rounded-[2.5rem] border-b-2 border-white/20 shadow-xl group hover:scale-[1.02] transition-all duration-300">
<div className="text-[10px] font-black text-white/80 uppercase tracking-widest mb-3 font-vazir whitespace-nowrap">{key}</div>
<div className="text-3xl font-black font-vazir tracking-tighter text-white">{toPersian(value)}</div>
</div>
))}
{product.main_ingredients && product.main_ingredients.length > 0 && (
<div>
<h4 className="text-xs font-black text-medical-gray-400 uppercase tracking-widest mb-4 font-vazir">مواد تشکیل‌دهنده برتر</h4>
<div className="flex flex-wrap gap-3">
{product.main_ingredients.map((ing, idx) => {
const termKey = termKeys.find(key => {
const termObj = scientificTerms[key] || SCIENTIFIC_TERMS[key];
const termName = termObj?.term || key;
const ingClean = ing.toLowerCase();
const keyClean = key.toLowerCase();
const termNameClean = termName.toLowerCase();
return ingClean.includes(keyClean) ||
keyClean.includes(ingClean) ||
ingClean.includes(termNameClean) ||
termNameClean.includes(ingClean);
});
return (
<div key={idx} className="bg-medical-gray-50 border border-medical-gray-100 px-5 py-3 rounded-2xl flex items-center gap-3 group hover:border-canina-blue/30 transition-all">
<span className="text-sm font-bold text-medical-gray-700 font-vazir">
{termKey ? (
<Tooltip termKey={termKey} onWikiNavigate={(id) => router.push(`/wiki?term=${id}`)}>
{ing}
</Tooltip>
) : ing}
</span>
<Sparkles className="w-3 h-3 text-canina-blue opacity-40 group-hover:opacity-100 transition-opacity" />
</div>
);
})}
</div>
</div>
)}
{/* Quantitative Analysis Cards Grid (Strict chemical percentages, not duplicate ingredients) */}
{(() => {
const filteredAnalysis = Object.entries(product.analysis || {}).filter(([key, val]) => {
const cleanKey = key.toLowerCase();
// Don't show duplicate ingredients here if already listed above
if (cleanKey.includes('مواد') || cleanKey.includes('ترکیبات') || cleanKey.includes('ingredient')) return false;
return Boolean(val);
});
if (filteredAnalysis.length === 0) return null;
return (
<div className="space-y-4 pt-4 border-t border-medical-gray-100">
<div className="text-xs font-black text-medical-gray-500 uppercase tracking-widest font-vazir">جدول آنالیز و آنالیتیکال ترکیبات</div>
<div className="grid grid-cols-2 sm:grid-cols-3 gap-4">
{filteredAnalysis.map(([key, value]) => (
<div key={key} className="bg-medical-gray-50 border border-medical-gray-200 p-5 rounded-2xl shadow-xs group hover:border-canina-blue/30 transition-all">
<div className="text-[11px] font-bold text-medical-gray-400 mb-1 font-vazir truncate">{key}</div>
<div className="text-xl font-black font-vazir tracking-tight text-canina-blue">{toPersian(value)}</div>
</div>
))}
</div>
</div>
);
})()}
</div>
</section>
{/* Feeding / Usage Instructions Section (Dynamic Header based on product category) */}
{/* Feeding / Usage Instructions Section (Merged and enriched) */}
<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="flex items-center gap-4 mb-6">
<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" />
</div>
<h3 className="text-2xl font-black text-medical-gray-900 italic font-vazir">
{product.categorySlug === 'special-care' || product.name.toLowerCase().includes('pfotenpflege') || product.name.toLowerCase().includes('augenpflege')
? 'دستورالعمل و نحوه استفاده موضعی'
: 'توصیه غذایی و نحوه مصرف'}
</h3>
<div>
<h3 className="text-2xl font-black text-medical-gray-900 italic font-vazir">
{fullProduct.categorySlug === 'special-care' || fullProduct.name.toLowerCase().includes('pfotenpflege') || fullProduct.name.toLowerCase().includes('augenpflege')
? 'دستورالعمل و نحوه استفاده موضعی'
: 'توصیه غذایی و نحوه مصرف'}
</h3>
<p className="text-xs text-medical-gray-400 font-bold font-vazir mt-0.5">
{fullProduct.categorySlug === 'special-care' || fullProduct.name.toLowerCase().includes('pfotenpflege') || fullProduct.name.toLowerCase().includes('augenpflege')
? 'فرآورده بهداشتی / موضعی (اعمال روی موضع بدون وابستگی به وزن بدن)'
: 'راهنمای استاندارد تغذیه بر اساس کاتالوگ دارویی آلمان'}
</p>
</div>
</div>
<p className="text-medical-gray-700 leading-relaxed text-sm md:text-base font-medium font-vazir mb-6">
{product.feedingAdvice}
</p>
{fullProduct.categorySlug === 'special-care' ||
fullProduct.name.toLowerCase().includes('pfotenpflege') ||
fullProduct.name.toLowerCase().includes('augenpflege') ||
fullProduct.unit?.includes('ml Lotion') ||
fullProduct.unit?.includes('Balsam') ||
fullProduct.nameFa?.includes('کرم') ||
fullProduct.nameFa?.includes('قطره تمیزکننده') ||
fullProduct.nameFa?.includes('اسپری') ? (
<div className="bg-canina-blue/5 border border-canina-blue/20 rounded-2xl p-5 mb-6 text-sm text-medical-gray-700 font-bold leading-relaxed">
<p className="mb-2">
{product.feedingAdvice || "چندین بار در روز روی نواحی آسیب‌دیده مالیده و به آرامی ماساژ داده شود."}
</p>
<p className="text-xs text-medical-gray-500 font-medium pt-2 border-t border-canina-blue/10">
ℹ️ این محصول یک فرآورده موضعی/بهداشتی است و مقدار مصرف آن به صورت موضعی (روی پوست، چشم یا پنجه) اعمال می‌شود و وابسته به وزن بدن حیوان نمی‌باشد. ماندگاری بسته بسته به میزان و تکرار مصرف روزانه شما متفاوت خواهد بود.
</p>
</div>
) : (
<p className="text-medical-gray-700 leading-relaxed text-sm md:text-base font-medium font-vazir mb-6">
{product.feedingAdvice}
</p>
)}
{/* Storage & Precautions Bar */}
<div className="grid md:grid-cols-2 gap-4 pt-6 border-t border-medical-gray-100">
@@ -599,54 +659,6 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
</div>
</section>
{/* Specialist Note */}
{product.specialist && (
<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}
alt={product.specialist.name}
className="w-32 h-32 rounded-[2rem] object-cover border-4 border-medical-gray-50 shadow-xl"
/>
<div className="flex-1">
<div className="inline-flex items-center gap-2 px-3 py-1 bg-medical-gray-900 text-white rounded-full text-[10px] font-black uppercase tracking-widest mb-4 font-vazir whitespace-nowrap">
<Stethoscope className="w-3 h-3" />
مورد تأیید دامپزشکان
</div>
<h4 className="text-2xl font-black text-medical-gray-900 mb-1 font-vazir">{product.specialist.name}</h4>
<p className="text-sm font-bold text-canina-blue mb-6 font-vazir">{product.specialist.title}</p>
<p className="text-base text-medical-gray-600 leading-relaxed italic font-vazir">
&quot;{product.specialist.message}&quot;
</p>
</div>
</div>
</section>
)}
{/* Specialized Landing Banner */}
<section>
<div
className="relative bg-canina-blue rounded-[2.5rem] p-12 overflow-hidden group cursor-pointer border border-medical-gray-200 shadow-md"
onClick={() => toast.info("بزودی: صفحه فرود تخصصی این محصول در حال آماده‌سازی است")}
>
<div className="absolute top-0 right-0 w-full h-full bg-[url('https://www.transparenttextures.com/patterns/cubes.png')] opacity-10" />
<div className="absolute -bottom-20 -left-20 w-80 h-80 bg-white/10 rounded-full blur-3xl group-hover:bg-white/20 transition-all duration-700" />
<div className="relative z-10 flex flex-col md:flex-row items-center justify-between gap-8">
<div className="text-center md:text-right">
<h3 className="text-3xl lg:text-4xl font-black text-white mb-4 italic">مشاهده بررسی تخصصی و نتایج درمانی</h3>
<p className="text-white/80 font-bold font-vazir max-w-lg">
گزارش‌های علمی، ویدیوهای آموزشی و تجربیات واقعی دیگر صاحبان پت در لندینگ‌پیج اختصاصی این محصول.
</p>
</div>
<div className="bg-white text-canina-blue px-8 py-4 rounded-2xl font-black shadow-2xl hover:scale-105 transition-transform flex items-center gap-3">
ورود به آزمایشگاه علمی
<ArrowRight className="w-5 h-5 rotate-180" />
</div>
</div>
</div>
</section>
{/* FAQ Section */}
{product.faqs && product.faqs.length > 0 && (
<section className="pt-10">
@@ -956,6 +968,70 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
)}
</div>
</div>
{/* Fullscreen High-Resolution Image Zoom / Lightbox Modal */}
<AnimatePresence>
{isImageZoomOpen && (
<div
className="fixed inset-0 z-50 flex items-center justify-center p-4 sm:p-8 bg-black/85 backdrop-blur-md"
onClick={() => setIsImageZoomOpen(false)}
>
<motion.div
initial={{ opacity: 0, scale: 0.9 }}
animate={{ opacity: 1, scale: 1 }}
exit={{ opacity: 0, scale: 0.9 }}
className="relative max-w-4xl max-h-[90vh] w-full flex flex-col items-center justify-center"
onClick={(e) => e.stopPropagation()}
>
{/* Close Button */}
<button
onClick={() => setIsImageZoomOpen(false)}
className="absolute -top-12 left-0 sm:left-auto sm:-right-12 w-10 h-10 rounded-full bg-white/20 hover:bg-white/30 text-white flex items-center justify-center transition-colors cursor-pointer"
title="بستن"
>
<X className="w-6 h-6" />
</button>
{/* Main Zoomed Image Container */}
<div className="bg-white rounded-3xl p-6 sm:p-10 shadow-2xl border border-white/20 max-h-[75vh] flex items-center justify-center overflow-hidden w-full">
<img
src={activeImage || product.image}
alt={product.name}
className="max-h-[60vh] max-w-full w-auto object-contain drop-shadow-2xl"
/>
</div>
{/* Lightbox Thumbnails Navigation */}
{(() => {
const allImgs = [
product.image,
...(product.images || []).filter(img => img && img !== product.image)
].filter(Boolean);
if (allImgs.length <= 1) return null;
return (
<div className="flex items-center gap-3 mt-4 overflow-x-auto py-2 px-4 max-w-full">
{allImgs.map((img, idx) => (
<button
key={idx}
onClick={() => setActiveImage(img)}
className={`w-14 h-14 rounded-xl overflow-hidden bg-white/10 border-2 transition-all p-1 shrink-0 ${
(activeImage || product.image) === img
? 'border-white scale-110 shadow-lg'
: 'border-transparent opacity-60 hover:opacity-100'
}`}
>
<img src={img} alt="Thumbnail" className="w-full h-full object-contain" />
</button>
))}
</div>
);
})()}
</motion.div>
</div>
)}
</AnimatePresence>
</div>
);
}