feat(media): implement omnichannel media gallery with drag-and-drop, video support, and quick access podcast/video hub
Deploy Canina / deploy (push) Successful in 1m35s
E2E Playwright Tests / Run Full E2E & Security Suites (push) Failing after 6s

This commit is contained in:
parsa aghaei committed 2026-08-29 11:46:04 +03:30
1 parent 32e40a820c
commit d9c693c41b
13 files changed
+9449 -8874

No files matched your search

+326 -72
View File
@@ -32,7 +32,10 @@ import {
Share2,
Phone,
Download,
Play
Play,
Film,
Headphones,
Volume2
} from "lucide-react";
const ICON_MAP: Record<string, React.ComponentType<{ className?: string }>> = {
@@ -80,6 +83,46 @@ const ProductImageZoomModal = dynamic(() => import("./ProductImageZoomModal"), {
import { useRouter } from 'next/navigation';
interface GalleryMediaItem {
id: string;
type: 'image' | 'video' | 'podcast';
url: string;
thumbnail: string;
title: string;
badge?: string;
videoData?: {
title?: string;
doctor?: string;
description?: string;
videoUrl?: string;
thumbnail?: string;
};
podcastData?: {
audioUrl?: string;
title?: string;
description?: string;
cover?: string;
};
}
function isVideoUrl(url?: string): boolean {
if (!url) return false;
const clean = url.toLowerCase().trim();
return (
clean.endsWith('.mp4') ||
clean.endsWith('.webm') ||
clean.endsWith('.mov') ||
clean.endsWith('.mkv') ||
clean.endsWith('.m4v') ||
clean.includes('aparat.com') ||
clean.includes('youtube.com') ||
clean.includes('youtu.be') ||
clean.includes('vimeo.com') ||
clean.includes('/video/') ||
clean.startsWith('data:video')
);
}
export default function ProductPage({ productSlug }: { productSlug: string }) {
const router = useRouter();
const [product, setProduct] = useState<Product | null>(null);
@@ -91,10 +134,18 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
const [dosageConfig, setDosageConfig] = useState<DosageConfig | null>(null);
const [isFullDescriptionOpen, setIsFullDescriptionOpen] = useState(false);
const [activeMediaIndex, setActiveMediaIndex] = useState(0);
const [activeImage, setActiveImage] = useState<string | null>(null);
const [isImageZoomOpen, setIsImageZoomOpen] = useState(false);
const [isVideoModalOpen, setIsVideoModalOpen] = useState(false);
const [isFullVideoDescOpen, setIsFullVideoDescOpen] = useState(false);
const [activeMediaForVideoModal, setActiveMediaForVideoModal] = useState<{
title?: string;
doctor?: string;
videoUrl?: string;
thumbnail?: string;
description?: string;
} | null>(null);
useEffect(() => {
Promise.resolve().then(() => setIsMounted(true));
@@ -229,6 +280,99 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
Promise.resolve().then(() => setItemQuantity(suggestedQty));
}, [calculation?.duration]);
// Omnichannel Product Media Gallery (Featured Image + Gallery Images/Videos + Dedicated Video + Podcast)
const galleryMedia = useMemo<GalleryMediaItem[]>(() => {
if (!product) return [];
const items: GalleryMediaItem[] = [];
// 1. Featured Image (Always first)
if (product.image) {
items.push({
id: 'featured-image',
type: 'image',
url: product.image,
thumbnail: product.image,
title: product.nameFa || product.name || 'تصویر شاخص محصول',
badge: 'تصویر اصلی'
});
}
// 2. Additional Gallery Media from product.images in custom configured order
if (product.images && Array.isArray(product.images)) {
product.images.forEach((mUrl, idx) => {
if (!mUrl || mUrl === product.image) return;
const isVid = isVideoUrl(mUrl);
if (isVid) {
items.push({
id: `gallery-vid-${idx}`,
type: 'video',
url: mUrl,
thumbnail: product.videoCover || product.image,
title: `ویدیو معرفی ${idx + 1}`,
badge: 'ویدیو',
videoData: {
title: `ویدیو محصول ${product.nameFa || product.name}`,
doctor: 'کادر علمی و تخصصی کنینا',
videoUrl: mUrl,
thumbnail: product.videoCover || product.image,
description: product.videoDescription || product.description,
}
});
} else {
items.push({
id: `gallery-img-${idx}`,
type: 'image',
url: mUrl,
thumbnail: mUrl,
title: `تصویر گالری ${idx + 1}`,
badge: 'تصویر'
});
}
});
}
// 3. Dedicated Video (product.videoUrl) if present and not duplicated
if (product.videoUrl && !items.some(it => it.url === product.videoUrl)) {
items.push({
id: 'dedicated-video',
type: 'video',
url: product.videoUrl,
thumbnail: product.videoCover || product.image,
title: product.videoTitle || 'ویدیو راهنمای مصرف و معرفی',
badge: 'ویدیوکست',
videoData: {
title: product.videoTitle || `ویدیو راهنمای ${product.nameFa || product.name}`,
doctor: 'کادر علمی و تخصصی کنینا',
videoUrl: product.videoUrl,
thumbnail: product.videoCover || product.image,
description: product.videoDescription || product.description,
}
});
}
// 4. Dedicated Podcast (product.podcastUrl) if present and not duplicated
if (product.podcastUrl && !items.some(it => it.url === product.podcastUrl)) {
items.push({
id: 'dedicated-podcast',
type: 'podcast',
url: product.podcastUrl,
thumbnail: product.podcastCover || product.image,
title: product.podcastTitle || 'پادکست و بررسی صوتی بالینی',
badge: 'پادکست',
podcastData: {
audioUrl: product.podcastUrl,
title: product.podcastTitle || 'پادکست و بررسی صوتی بالینی مکمل',
description: product.podcastDescription || product.description,
cover: product.podcastCover || product.image,
}
});
}
return items;
}, [product]);
const activeMedia = galleryMedia[activeMediaIndex] || galleryMedia[0];
if (isLoading) return (
<div className="min-h-screen bg-medical-gray-50 p-6 max-w-7xl mx-auto font-vazir" dir="rtl">
<div className="animate-pulse space-y-6">
@@ -292,16 +436,17 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
{/* Above the Fold Grid */}
<div className="grid grid-cols-1 md:grid-cols-12 gap-4 sm: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 & Gallery (md:col-span-5) */}
{/* Right Column: Omnichannel Product Media Hub & Gallery (md:col-span-5) */}
<div className="md:col-span-5 w-full mx-auto max-w-sm md:max-w-none space-y-3 sm:space-y-4">
<motion.div
initial={{ opacity: 0, scale: 0.95 }}
key={activeMedia?.id || 'media-box'}
initial={{ opacity: 0, scale: 0.96 }}
animate={{ opacity: 1, scale: 1 }}
onClick={() => setIsImageZoomOpen(true)}
className="bg-white rounded-2xl sm:rounded-[2.5rem] border border-medical-gray-200 shadow-xl relative group overflow-hidden h-[260px] sm:h-[380px] flex items-center justify-center p-2 sm:p-4 cursor-zoom-in"
title="کلیک برای مشاهده تصویر بزرگتر"
transition={{ duration: 0.2 }}
className="bg-white rounded-2xl sm:rounded-[2.5rem] border border-medical-gray-200 shadow-xl relative group overflow-hidden h-[280px] sm:h-[390px] flex items-center justify-center p-2 sm:p-4 select-none"
>
<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">
{/* Top Floating Badges */}
<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 pointer-events-none">
{product.specialBadge && (
<div className="px-2.5 py-1 bg-medical-gray-900 text-white rounded-full text-[9px] sm:text-[10px] font-black uppercase tracking-widest font-vazir whitespace-nowrap shadow-sm">
{product.specialBadge}
@@ -323,7 +468,7 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
</div>
{/* Species Suitable Badges (Dog / Cat) */}
<div className="absolute bottom-4 left-4 flex gap-1.5 z-10">
<div className="absolute bottom-4 left-4 flex gap-1.5 z-10 pointer-events-none">
{(product.suitableFor === "سگ" || product.suitableFor === "هر دو") && (
<div className="w-7 h-7 bg-white/90 backdrop-blur-sm rounded-lg flex items-center justify-center text-medical-gray-600 border border-medical-gray-200 shadow-sm" title="مناسب برای سگ">
<Dog className="w-4 h-4 text-canina-blue" />
@@ -335,55 +480,159 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
</div>
)}
</div>
<SafeImage
src={activeImage || product.image}
alt={product.name}
priority={true}
sizes="(max-width: 768px) 100vw, 400px"
className="w-full h-full"
imgClassName="w-full h-full 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>
{/* 1. Image Viewer */}
{(!activeMedia || activeMedia.type === 'image') && (
<div
onClick={() => setIsImageZoomOpen(true)}
className="w-full h-full flex items-center justify-center cursor-zoom-in relative"
title="کلیک برای مشاهده تصویر بزرگتر"
>
<SafeImage
src={activeMedia?.url || product.image}
alt={product.name}
priority={true}
sizes="(max-width: 768px) 100vw, 400px"
className="w-full h-full"
imgClassName="w-full h-full 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>
</div>
)}
{/* 2. Video Player Frame */}
{activeMedia?.type === 'video' && (
<div
onClick={() => {
setActiveMediaForVideoModal(activeMedia.videoData || {
title: activeMedia.title || product.name,
videoUrl: activeMedia.url,
thumbnail: activeMedia.thumbnail,
description: product.description,
});
setIsVideoModalOpen(true);
}}
className="w-full h-full relative cursor-pointer overflow-hidden rounded-2xl bg-neutral-950 flex items-center justify-center group/vid"
title="برای پخش ویدیو کلیک کنید"
>
<SafeImage
src={activeMedia.thumbnail || product.image}
alt={activeMedia.title || product.name}
className="w-full h-full opacity-60 group-hover/vid:opacity-40 transition-opacity"
imgClassName="w-full h-full object-cover group-hover/vid:scale-105 transition-transform duration-700"
/>
<div className="absolute inset-0 bg-gradient-to-t from-black/85 via-black/30 to-black/50 flex flex-col items-center justify-center gap-3 p-4 text-center">
<div className="w-16 h-16 sm:w-20 sm:h-20 rounded-full bg-canina-blue text-white flex items-center justify-center shadow-2xl shadow-canina-blue/60 group-hover/vid:scale-110 transition-transform">
<Play className="w-8 h-8 sm:w-10 sm:h-10 fill-white ml-1" />
</div>
<div className="space-y-1.5 max-w-xs">
<span className="inline-flex items-center gap-1.5 px-3 py-1 bg-canina-blue text-white text-[11px] font-black rounded-full shadow-md font-vazir">
<Film className="w-3.5 h-3.5" />
<span>پخش ویدیو معرفی محصول</span>
</span>
<p className="text-xs font-bold text-white/90 truncate font-vazir">
{activeMedia.title || product.nameFa || product.name}
</p>
</div>
</div>
</div>
)}
{/* 3. Podcast Player Frame */}
{activeMedia?.type === 'podcast' && (
<div
onClick={() => {
const el = document.getElementById('podcast-player-section');
if (el) {
el.scrollIntoView({ behavior: 'smooth' });
}
}}
className="w-full h-full relative cursor-pointer overflow-hidden rounded-2xl bg-gradient-to-br from-purple-950 via-slate-900 to-indigo-950 flex flex-col items-center justify-center p-6 text-white text-center group/pod"
title="مشاهده و پخش پادکست بالینی"
>
<div className="w-16 h-16 sm:w-20 sm:h-20 rounded-2xl bg-purple-600/30 border border-purple-400/30 flex items-center justify-center mb-3 shadow-xl group-hover/pod:scale-105 transition-transform">
<Headphones className="w-8 h-8 sm:w-10 sm:h-10 text-purple-300 animate-pulse" />
</div>
{/* Animated Audio Bars */}
<div className="flex items-center gap-1 mb-3">
<span className="w-1 h-3 bg-purple-400 rounded-full animate-bounce" style={{ animationDelay: '0ms' }} />
<span className="w-1 h-6 bg-purple-300 rounded-full animate-bounce" style={{ animationDelay: '150ms' }} />
<span className="w-1 h-8 bg-purple-400 rounded-full animate-bounce" style={{ animationDelay: '300ms' }} />
<span className="w-1 h-4 bg-purple-300 rounded-full animate-bounce" style={{ animationDelay: '75ms' }} />
<span className="w-1 h-6 bg-purple-400 rounded-full animate-bounce" style={{ animationDelay: '225ms' }} />
</div>
<span className="inline-flex items-center gap-1.5 px-3 py-1 bg-purple-600 text-white text-[11px] font-black rounded-full shadow-md font-vazir mb-1">
<Headphones className="w-3.5 h-3.5" />
<span>پادکست و بررسی صوتی بالینی</span>
</span>
<p className="text-xs font-bold text-white/90 line-clamp-2 max-w-xs font-vazir mt-1">
{activeMedia.title || "بررسی تخصصی اثر مکمل توسط تیم علمی"}
</p>
</div>
)}
</motion.div>
{/* Multiple Gallery Thumbnails Strip */}
{(() => {
const allGalleryImages = [
product.image,
...(product.images || []).filter(img => img && img !== product.image)
].filter(Boolean);
{/* Multiple Gallery Media Thumbnails Strip */}
{galleryMedia.length > 1 && (
<div className="flex items-center gap-2 overflow-x-auto py-2 px-1 sleek-hscroll">
{galleryMedia.map((item, idx) => {
const isSelected = activeMediaIndex === idx;
if (allGalleryImages.length <= 1) return null;
return (
<button
key={item.id || idx}
type="button"
onClick={() => {
setActiveMediaIndex(idx);
if (item.type === 'image') {
setActiveImage(item.url);
}
}}
className={`relative w-16 h-16 sm:w-18 sm:h-18 rounded-2xl overflow-hidden bg-white border-2 transition-all shrink-0 p-1 cursor-pointer flex items-center justify-center ${
isSelected
? 'border-canina-blue shadow-lg scale-105 ring-2 ring-canina-blue/30'
: 'border-medical-gray-200 hover:border-canina-blue/50 opacity-75 hover:opacity-100'
}`}
>
<SafeImage
src={item.thumbnail || item.url || product.image}
alt={`${product.name} - ${idx + 1}`}
className="w-full h-full"
imgClassName="w-full h-full object-contain"
/>
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'
}`}
>
<SafeImage
src={imgUrl}
alt={`${product.name} - ${idx + 1}`}
className="w-full h-full"
imgClassName="w-full h-full object-contain"
/>
</button>
);
})}
</div>
);
})()}
{/* Video Overlay Badge on thumbnail */}
{item.type === 'video' && (
<div className="absolute inset-0 bg-black/40 flex items-center justify-center">
<div className="w-6 h-6 rounded-full bg-canina-blue text-white flex items-center justify-center shadow-md">
<Play className="w-3 h-3 fill-white ml-0.5" />
</div>
<span className="absolute bottom-0.5 right-0.5 bg-blue-600 text-white text-[7px] font-bold px-1 rounded font-vazir">
ویدیو
</span>
</div>
)}
{/* Podcast Overlay Badge on thumbnail */}
{item.type === 'podcast' && (
<div className="absolute inset-0 bg-purple-950/60 flex items-center justify-center">
<div className="w-6 h-6 rounded-full bg-purple-600 text-white flex items-center justify-center shadow-md">
<Headphones className="w-3.5 h-3.5 text-white" />
</div>
<span className="absolute bottom-0.5 right-0.5 bg-purple-600 text-white text-[7px] font-bold px-1 rounded font-vazir">
صوت
</span>
</div>
)}
</button>
);
})}
</div>
)}
</div>
{/* Left Column: Product Title & Description (md:col-span-7) */}
@@ -882,16 +1131,18 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
{/* Podcast Player Row (Inline Direct Player with Soundcloud Waveform) */}
{product.podcastUrl && (
<PodcastInlinePlayer
podcast={{
audioUrl: product.podcastUrl,
title: product.podcastTitle || "پادکست و بررسی صوتی بالینی مکمل",
description: product.podcastDescription || product.description,
cover: product.podcastCover,
productName: product.name,
fallbackCover: product.image,
}}
/>
<div id="podcast-player-section" className="scroll-mt-24">
<PodcastInlinePlayer
podcast={{
audioUrl: product.podcastUrl,
title: product.podcastTitle || "پادکست و بررسی صوتی بالینی مکمل",
description: product.podcastDescription || product.description,
cover: product.podcastCover,
productName: product.name,
fallbackCover: product.image,
}}
/>
</div>
)}
{/* PDF Catalog Download Row */}
@@ -1251,26 +1502,29 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
<ProductImageZoomModal
isOpen={isImageZoomOpen}
onClose={() => setIsImageZoomOpen(false)}
images={[
product.image,
...(product.images || []).filter(img => img && img !== product.image)
].filter(Boolean) as string[]}
activeImage={activeImage || product.image || ""}
onSelectImage={(img) => setActiveImage(img)}
images={galleryMedia.filter(m => m.type === 'image').map(m => m.url)}
activeImage={activeMedia?.type === 'image' ? activeMedia.url : (galleryMedia.find(m => m.type === 'image')?.url || product.image || "")}
onSelectImage={(img) => {
const foundIdx = galleryMedia.findIndex(m => m.url === img);
if (foundIdx !== -1) setActiveMediaIndex(foundIdx);
}}
productName={product.nameFa || product.name}
/>
{/* Dedicated Video Modal Player */}
<VideoModalPlayer
isOpen={isVideoModalOpen}
onClose={() => setIsVideoModalOpen(false)}
video={product.videoUrl ? {
onClose={() => {
setIsVideoModalOpen(false);
setActiveMediaForVideoModal(null);
}}
video={activeMediaForVideoModal || (product.videoUrl ? {
title: product.videoTitle || product.name,
doctor: "کادر علمی و تخصصی کنینا",
videoUrl: product.videoUrl,
thumbnail: product.videoCover || product.image,
description: product.videoDescription || product.description,
} : null}
} : null)}
/>
</div>
);