From 5bf157219e343412fe230e48931fbe9c8f2a8719 Mon Sep 17 00:00:00 2001 From: hosseintaromi Date: Fri, 1 Aug 2025 14:38:16 +0330 Subject: [PATCH] =?UTF-8?q?fix:=20=D8=B1=D9=81=D8=B9=20=D9=85=D8=B4=DA=A9?= =?UTF-8?q?=D9=84=D8=A7=D8=AA=20=D9=86=D9=85=D8=A7=DB=8C=D8=B4=20=D8=AC?= =?UTF-8?q?=D8=B2=D8=A6=DB=8C=D8=A7=D8=AA=20=D9=85=D8=AD=D8=B5=D9=88=D9=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - اصلاح نمایش دسته‌بندی‌ها با fallback به product_categories - رفع خطای React hooks order با جابجایی useState - حل مشکلات TypeScript و نمایش صحیح تمام اطلاعات محصول --- .../product-detail/ProductDetailPage.tsx | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/pages/products/product-detail/ProductDetailPage.tsx b/src/pages/products/product-detail/ProductDetailPage.tsx index 361fcd5..4ce1f4b 100644 --- a/src/pages/products/product-detail/ProductDetailPage.tsx +++ b/src/pages/products/product-detail/ProductDetailPage.tsx @@ -14,6 +14,9 @@ const ProductDetailPage = () => { const { data: product, isLoading, error } = useProduct(id); + // State for image preview – must be defined before any early returns to keep hook order stable + const [previewImage, setPreviewImage] = useState(null); + if (isLoading) return ; if (error) return
خطا در بارگذاری اطلاعات محصول
; if (!product) return
محصول یافت نشد
; @@ -22,8 +25,6 @@ const ProductDetailPage = () => { return new Intl.NumberFormat('fa-IR').format(price) + ' تومان'; }; - const [previewImage, setPreviewImage] = useState(null); - const formatNumber = (num: number) => { return new Intl.NumberFormat('fa-IR').format(num); }; @@ -31,8 +32,12 @@ const ProductDetailPage = () => { // تصاویر محصول (حاصل تجمیع دو فیلد مختلف از API) const images = (product.file_ids && product.file_ids.length > 0) ? product.file_ids : ((product as any).files || []); + // نسخه‌های محصول const variants = (product.variants && product.variants.length > 0) ? product.variants : ((product as any).product_variants || []); + // دسته‌بندی‌های محصول + const categoriesData = (product.categories && product.categories.length > 0) ? product.categories : ((product as any).product_categories || []); + return ( <> @@ -225,7 +230,7 @@ const ProductDetailPage = () => { نسخه‌های محصول
- {variants.map((variant, index) => ( + {variants.map((variant: any, index: number) => (

@@ -299,11 +304,11 @@ const ProductDetailPage = () => { ویژگی‌های نسخه

- {Object.entries(variant.attributes).map(([key, value]) => ( + {Object.entries(variant.attributes).map(([key, value]: [string, any]) => (
{key}: - {typeof value === 'object' ? JSON.stringify(value) : value} + {typeof value === 'object' ? JSON.stringify(value) : String(value)}
))} @@ -318,11 +323,11 @@ const ProductDetailPage = () => { اطلاعات تکمیلی
- {Object.entries(variant.meta).map(([key, value]) => ( + {Object.entries(variant.meta).map(([key, value]: [string, any]) => (
{key}: - {typeof value === 'object' ? JSON.stringify(value) : value} + {typeof value === 'object' ? JSON.stringify(value) : String(value)}
))} @@ -416,7 +421,7 @@ const ProductDetailPage = () => {
)} - {product.categories && product.categories.length > 0 && ( + {categoriesData.length > 0 && (
@@ -425,7 +430,7 @@ const ProductDetailPage = () => {
- {formatNumber(product.categories.length)} + {formatNumber(categoriesData.length)}
)} @@ -433,14 +438,14 @@ const ProductDetailPage = () => {
{/* دسته‌بندی‌ها */} - {product.categories && product.categories.length > 0 && ( + {categoriesData.length > 0 && (
دسته‌بندی‌ها
- {product.categories.map((category) => ( + {categoriesData.map((category: any) => (