@@ -7,6 +7,7 @@ import { Card, CardContent, CardHeader, CardTitle } from "../../../components/pr
77import UnitConversionSection from "./UnitConversionSection" ;
88import { useFetchUnits } from "../../../hooks/product_variants" ;
99import api from "../../../config/axiosConfig" ;
10+ import { resolveImageUrl , getApiOrigin } from "../../../utils/inventory" ;
1011
1112// Modal Component hiển thị thông tin và cho phép Chỉnh sửa một Variant (Loại sản phẩm)
1213// Cho phép update SKU, Barcode, PLU Code, giá bán, hình ảnh...
@@ -51,13 +52,7 @@ export function EditVariantModal({ variant, parentProduct, isOpen, onClose, onSa
5152 : ( variant . is_active ?? true ) ,
5253 } ) ;
5354 setImageFile ( null ) ;
54- setImagePreview (
55- variant . image_url
56- ? variant . image_url . startsWith ( "http" )
57- ? variant . image_url
58- : `http://localhost:8081${ variant . image_url . startsWith ( "/" ) ? "" : "/" } ${ variant . image_url } `
59- : null ,
60- ) ;
55+ setImagePreview ( resolveImageUrl ( variant . image_url ) || null ) ;
6156 setErrorMsg ( "" ) ;
6257
6358 const attrsObj = variant . attributes || { } ;
@@ -232,8 +227,8 @@ export function EditVariantModal({ variant, parentProduct, isOpen, onClose, onSa
232227 let imageUrl = null ;
233228 if ( imageFile ) {
234229 imageUrl = await uploadImage ( ) ;
235- // Return full path without localhost URL to save on DB
236- if ( imageUrl ) imageUrl = imageUrl . replace ( "http://localhost:8081" , "" ) ;
230+ // Return full path without server origin to save on DB
231+ if ( imageUrl ) imageUrl = imageUrl . replace ( getApiOrigin ( ) , "" ) ;
237232 } else if ( imagePreview ) {
238233 // Keep the old image
239234 imageUrl = variant . image_url ;
0 commit comments