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) => (