feat(admin): add full-size image preview lightbox modal on product image click in products list
E2E Playwright Tests / Run Full E2E & Security Suites (push) Failing after 6s
Deploy Canina / deploy (push) Has been cancelled

This commit is contained in:
parsa aghaei committed 2026-09-02 10:54:16 +03:30
1 parent 3cbcad7b65
commit 6fa1f2c906
12 files changed
+5271 -5192

No files matched your search

+94 -3
View File
@@ -28,6 +28,8 @@ import {
RotateCcw,
CheckCircle2,
Compass,
Maximize2,
ExternalLink,
} from 'lucide-react';
import { toast } from 'react-hot-toast';
import api, { BASE_DOMAIN } from '../services/api';
@@ -208,6 +210,7 @@ export default function Products() {
// Modal State
const [isModalOpen, setIsModalOpen] = useState(false);
const [previewImage, setPreviewImage] = useState<{ url: string; title: string; subtitle?: string; artNo?: string } | null>(null);
const [isMediaSelectorOpen, setIsMediaSelectorOpen] = useState(false);
const [mediaTargetField, setMediaTargetField] = useState<'imageUrl' | 'ogImage' | 'podcastUrl' | 'podcastCover' | 'videoUrl' | 'videoCover' | 'pdfUrl' | 'pdfCover' | 'gallery'>('imageUrl');
const [editingProduct, setEditingProduct] = useState<Product | null>(null);
@@ -1004,14 +1007,27 @@ export default function Products() {
<tr key={product.id} className="hover:bg-gray-50/50 transition-colors">
<td className="py-3 px-6">
{product.imageUrl && !imageErrors[product.id] ? (
<div className="w-12 h-12 rounded-xl bg-gray-50 border border-gray-200 p-1 flex items-center justify-center overflow-hidden">
<button
type="button"
onClick={() => setPreviewImage({
url: getProductImageUrl(product.imageUrl),
title: product.nameFa || product.name || '',
subtitle: product.nameEn,
artNo: product.artNo
})}
className="w-12 h-12 rounded-xl bg-gray-50 border border-gray-200 p-1 flex items-center justify-center overflow-hidden hover:scale-105 hover:border-purple-400 hover:shadow-md transition-all cursor-zoom-in group relative"
title="کلیک برای مشاهده تصویر در سایز بزرگ"
>
<img
src={getProductImageUrl(product.imageUrl)}
alt=""
onError={() => setImageErrors(prev => ({ ...prev, [product.id]: true }))}
className="max-w-full max-h-full object-contain object-center"
className="max-w-full max-h-full object-contain object-center transition-transform group-hover:scale-110"
/>
</div>
<div className="absolute inset-0 bg-purple-950/20 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center rounded-xl">
<Maximize2 className="w-4 h-4 text-white drop-shadow" />
</div>
</button>
) : (
<div className="w-12 h-12 rounded-xl bg-gray-100 flex items-center justify-center text-gray-400">
<ImageIcon className="w-5 h-5" />
@@ -3201,6 +3217,81 @@ export default function Products() {
onConfirm={confirmDelete}
onCancel={() => setDeleteTargetId(null)}
/>
{/* Product Image Lightbox Modal */}
{previewImage && (
<div
className="fixed inset-0 z-50 flex items-center justify-center p-4 sm:p-6 bg-black/80 backdrop-blur-sm animate-in fade-in duration-200 font-vazir"
dir="rtl"
onClick={() => setPreviewImage(null)}
>
<div
className="bg-white rounded-3xl max-w-2xl w-full overflow-hidden shadow-2xl border border-gray-100 flex flex-col animate-in zoom-in-95 duration-200"
onClick={(e) => e.stopPropagation()}
>
{/* Header */}
<div className="px-6 py-4 border-b border-gray-100 flex items-center justify-between bg-white shrink-0">
<div className="flex flex-col gap-0.5 text-right">
<div className="flex items-center gap-2">
<h3 className="text-base font-black text-gray-900">
{previewImage.title || 'تصویر محصول'}
</h3>
{previewImage.artNo && (
<span className="px-2 py-0.5 bg-purple-50 text-purple-700 rounded-lg text-xs font-mono font-bold border border-purple-100">
{previewImage.artNo}
</span>
)}
</div>
{previewImage.subtitle && (
<span className="text-xs text-gray-400 font-mono" dir="ltr">
{previewImage.subtitle}
</span>
)}
</div>
<div className="flex items-center gap-2">
<a
href={previewImage.url}
target="_blank"
rel="noreferrer"
className="px-3 py-1.5 rounded-xl bg-gray-50 text-gray-600 hover:text-purple-600 hover:bg-purple-50 border border-gray-200 text-xs font-bold transition-all flex items-center gap-1.5"
title="باز کردن در تب جدید"
>
<span>باز کردن لینک اصلی</span>
<ExternalLink className="w-3.5 h-3.5" />
</a>
<button
type="button"
onClick={() => setPreviewImage(null)}
className="w-8 h-8 rounded-xl bg-gray-100 text-gray-400 hover:text-gray-700 hover:bg-gray-200 flex items-center justify-center transition-colors cursor-pointer"
>
<X className="w-4 h-4" />
</button>
</div>
</div>
{/* Image Preview Canvas */}
<div className="p-6 sm:p-10 bg-gray-50/70 flex items-center justify-center min-h-[320px] max-h-[70vh] overflow-auto select-none">
<img
src={previewImage.url}
alt={previewImage.title}
className="max-h-[60vh] max-w-full object-contain rounded-2xl drop-shadow-xl hover:scale-105 transition-transform duration-300"
/>
</div>
{/* Footer */}
<div className="px-6 py-3 bg-gray-50 border-t border-gray-100 flex items-center justify-between text-xs text-gray-500 font-medium">
<span>کیفیت استاندارد کاتالوگ کنینا</span>
<button
type="button"
onClick={() => setPreviewImage(null)}
className="px-4 py-2 bg-gray-900 text-white rounded-xl font-bold hover:bg-purple-600 transition-colors cursor-pointer"
>
بستن پنجره
</button>
</div>
</div>
</div>
)}
</div>
);
}