fix(admin/ui): resolve tooltip overlaps by opening downwards, fix layout shifts with fixed modal content height, and add getProductImageUrl helper to dynamically resolve hardcoded dev base image URLs
This commit is contained in:
1 parent
4860a0e2e3
commit
72650dba36
1 file changed
+30
-11
@@ -12,6 +12,15 @@ export default function Products() {
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
// URL and String Helper Functions
|
||||
const getProductImageUrl = (url: string) => {
|
||||
if (!url) return '';
|
||||
if (url.startsWith('http')) {
|
||||
const path = url.replace(/^https?:\/\/[^\/]+/, '');
|
||||
return `${BASE_DOMAIN}${path}`;
|
||||
}
|
||||
return url.startsWith('/') ? `${BASE_DOMAIN}${url}` : `${BASE_DOMAIN}/${url}`;
|
||||
};
|
||||
|
||||
const getStoreProductUrl = (slug: string) => {
|
||||
const isDev = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1';
|
||||
if (isDev) {
|
||||
@@ -38,6 +47,7 @@ export default function Products() {
|
||||
const [page, setPage] = useState(1);
|
||||
const [totalPages, setTotalPages] = useState(1);
|
||||
const [imageErrors, setImageErrors] = useState<Record<string, boolean>>({});
|
||||
const [mediaImageError, setMediaImageError] = useState(false);
|
||||
const limit = 10;
|
||||
|
||||
// Modal State
|
||||
@@ -106,6 +116,7 @@ export default function Products() {
|
||||
}, [search, categoryFilter, page]);
|
||||
|
||||
const openModal = (product: any = null) => {
|
||||
setMediaImageError(false);
|
||||
if (product) {
|
||||
setEditingProduct(product);
|
||||
setFormData({
|
||||
@@ -251,7 +262,7 @@ export default function Products() {
|
||||
<td className="py-3 px-6">
|
||||
{product.imageUrl && !imageErrors[product.id] ? (
|
||||
<img
|
||||
src={product.imageUrl.startsWith('http') ? product.imageUrl : `${BASE_DOMAIN}${product.imageUrl}`}
|
||||
src={getProductImageUrl(product.imageUrl)}
|
||||
alt=""
|
||||
onError={() => setImageErrors(prev => ({ ...prev, [product.id]: true }))}
|
||||
className="w-12 h-12 rounded-xl object-cover border border-gray-200"
|
||||
@@ -341,7 +352,7 @@ export default function Products() {
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="p-6 overflow-y-auto flex-1 bg-gray-50/30">
|
||||
<div className="p-6 overflow-y-auto h-[550px] min-h-[550px] max-h-[550px] bg-gray-50/30">
|
||||
<form id="productForm" onSubmit={handleSave} className="space-y-6">
|
||||
|
||||
{/* General Tab */}
|
||||
@@ -352,7 +363,7 @@ export default function Products() {
|
||||
<span>کد محصول (Art No) *</span>
|
||||
<div className="group relative inline-block">
|
||||
<HelpCircle className="w-3.5 h-3.5 text-gray-400 hover:text-purple-600 cursor-help" />
|
||||
<div className="absolute bottom-full right-1/2 translate-x-1/2 mb-2 hidden group-hover:block w-52 p-2.5 bg-gray-900 text-white text-[10px] rounded-lg shadow-xl text-center z-30 font-vazir leading-relaxed">
|
||||
<div className="absolute top-full right-1/2 translate-x-1/2 mt-2 hidden group-hover:block w-52 p-2.5 bg-gray-900 text-white text-[10px] rounded-lg shadow-xl text-center z-50 font-vazir leading-relaxed">
|
||||
کد کاتالوگ انحصاری کارخانه Canina آلمان (مانند 123490).
|
||||
</div>
|
||||
</div>
|
||||
@@ -364,7 +375,7 @@ export default function Products() {
|
||||
<span>نام فارسی محصول *</span>
|
||||
<div className="group relative inline-block">
|
||||
<HelpCircle className="w-3.5 h-3.5 text-gray-400 hover:text-purple-600 cursor-help" />
|
||||
<div className="absolute bottom-full right-1/2 translate-x-1/2 mb-2 hidden group-hover:block w-52 p-2.5 bg-gray-900 text-white text-[10px] rounded-lg shadow-xl text-center z-30 font-vazir leading-relaxed">
|
||||
<div className="absolute top-full right-1/2 translate-x-1/2 mt-2 hidden group-hover:block w-52 p-2.5 bg-gray-900 text-white text-[10px] rounded-lg shadow-xl text-center z-50 font-vazir leading-relaxed">
|
||||
عنوان فارسی محصول که در صفحات و کاتالوگ فروشگاه نمایش داده میشود.
|
||||
</div>
|
||||
</div>
|
||||
@@ -376,7 +387,7 @@ export default function Products() {
|
||||
<span>نام انگلیسی / آلمانی (nameEn) *</span>
|
||||
<div className="group relative inline-block">
|
||||
<HelpCircle className="w-3.5 h-3.5 text-gray-400 hover:text-purple-600 cursor-help" />
|
||||
<div className="absolute bottom-full right-1/2 translate-x-1/2 mb-2 hidden group-hover:block w-52 p-2.5 bg-gray-900 text-white text-[10px] rounded-lg shadow-xl text-center z-30 font-vazir leading-relaxed">
|
||||
<div className="absolute top-full right-1/2 translate-x-1/2 mt-2 hidden group-hover:block w-52 p-2.5 bg-gray-900 text-white text-[10px] rounded-lg shadow-xl text-center z-50 font-vazir leading-relaxed">
|
||||
نام برند و وزن کالا به انگلیسی جهت استفاده در آدرس، فاکتورها و سئو.
|
||||
</div>
|
||||
</div>
|
||||
@@ -388,7 +399,7 @@ export default function Products() {
|
||||
<span>شعار علمی (Tagline)</span>
|
||||
<div className="group relative inline-block">
|
||||
<HelpCircle className="w-3.5 h-3.5 text-gray-400 hover:text-purple-600 cursor-help" />
|
||||
<div className="absolute bottom-full right-1/2 translate-x-1/2 mb-2 hidden group-hover:block w-52 p-2.5 bg-gray-900 text-white text-[10px] rounded-lg shadow-xl text-center z-30 font-vazir leading-relaxed">
|
||||
<div className="absolute top-full right-1/2 translate-x-1/2 mt-2 hidden group-hover:block w-52 p-2.5 bg-gray-900 text-white text-[10px] rounded-lg shadow-xl text-center z-50 font-vazir leading-relaxed">
|
||||
شعار کلیدی یا علمی کالا که در بالای صفحه محصول نمایش داده میشود.
|
||||
</div>
|
||||
</div>
|
||||
@@ -552,7 +563,7 @@ export default function Products() {
|
||||
<span>نامک (Slug) محصول</span>
|
||||
<div className="group relative inline-block">
|
||||
<HelpCircle className="w-3.5 h-3.5 text-gray-400 hover:text-purple-600 cursor-help" />
|
||||
<div className="absolute bottom-full right-1/2 translate-x-1/2 mb-2 hidden group-hover:block w-52 p-2.5 bg-gray-900 text-white text-[10px] rounded-lg shadow-xl text-center z-30 font-vazir leading-relaxed">
|
||||
<div className="absolute top-full right-1/2 translate-x-1/2 mt-2 hidden group-hover:block w-52 p-2.5 bg-gray-900 text-white text-[10px] rounded-lg shadow-xl text-center z-50 font-vazir leading-relaxed">
|
||||
آدرس مستقیم محصول در سایت. در صورت خالی بودن، به طور خودکار از روی نام انگلیسی ساخته میشود.
|
||||
</div>
|
||||
</div>
|
||||
@@ -679,10 +690,15 @@ export default function Products() {
|
||||
{/* Media Tab */}
|
||||
<div className={activeTab === 'media' ? 'block space-y-4' : 'hidden'}>
|
||||
<div className="flex flex-col items-center justify-center p-8 border-2 border-dashed border-gray-200 rounded-2xl bg-white">
|
||||
{formData.imageUrl ? (
|
||||
{formData.imageUrl && !mediaImageError ? (
|
||||
<div className="w-full flex flex-col items-center">
|
||||
<div className="relative group">
|
||||
<img src={formData.imageUrl.startsWith('http') ? formData.imageUrl : `${BASE_DOMAIN}${formData.imageUrl}`} alt="product" className="max-w-xs h-48 object-cover rounded-xl shadow-md" />
|
||||
<img
|
||||
src={getProductImageUrl(formData.imageUrl)}
|
||||
alt=""
|
||||
onError={() => setMediaImageError(true)}
|
||||
className="max-w-xs h-48 object-contain rounded-xl shadow-md border border-gray-100"
|
||||
/>
|
||||
<div className="absolute inset-0 bg-black/50 opacity-0 group-hover:opacity-100 transition-opacity rounded-xl flex items-center justify-center gap-3">
|
||||
<button type="button" onClick={() => setIsMediaSelectorOpen(true)} className="bg-white text-gray-800 px-4 py-2 rounded-lg font-bold text-sm">تغییر عکس</button>
|
||||
</div>
|
||||
@@ -702,7 +718,7 @@ export default function Products() {
|
||||
<div className="w-16 h-16 bg-gray-100 rounded-full flex items-center justify-center text-gray-400 mb-4">
|
||||
<ImageIcon className="w-8 h-8" />
|
||||
</div>
|
||||
<p className="text-gray-500 font-medium mb-4">هیچ تصویری انتخاب نشده است</p>
|
||||
<p className="text-gray-500 font-medium mb-4">تصویر محصول یافت نشد یا انتخاب نشده است</p>
|
||||
<p className="text-xs text-gray-400 mb-4">از گالری رسانه تصویر انتخاب کنید یا با Ctrl+V از کلیپبورد بچسبانید</p>
|
||||
<button type="button" onClick={() => setIsMediaSelectorOpen(true)} className="bg-purple-100 text-purple-700 hover:bg-purple-200 px-6 py-2 rounded-xl font-bold transition-colors">
|
||||
انتخاب از گالری رسانه
|
||||
@@ -731,7 +747,10 @@ export default function Products() {
|
||||
<MediaSelector
|
||||
isOpen={isMediaSelectorOpen}
|
||||
onClose={() => setIsMediaSelectorOpen(false)}
|
||||
onSelect={(url) => setFormData({...formData, imageUrl: url})}
|
||||
onSelect={(url) => {
|
||||
setFormData({...formData, imageUrl: url});
|
||||
setMediaImageError(false);
|
||||
}}
|
||||
selectedUrl={formData.imageUrl.startsWith('http') ? formData.imageUrl : formData.imageUrl ? `${BASE_DOMAIN}${formData.imageUrl}` : undefined}
|
||||
/>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user