Fix image upload
This commit is contained in:
@@ -17,7 +17,7 @@ export const ImageUpload = ({
|
||||
<div>
|
||||
<label className="text-sm font-medium">Product Image</label>
|
||||
<div
|
||||
className="relative border rounded-md flex items-center justify-center bg-gray-50 dark:bg-gray-800 w-full h-48"
|
||||
className="relative border rounded-md flex items-center justify-center bg-transparent w-full h-48"
|
||||
style={{ width: imageDimensions.width, height: imageDimensions.height }}
|
||||
>
|
||||
{imagePreview ? (
|
||||
|
||||
@@ -51,7 +51,7 @@ export const ProductModal: React.FC<ProductModalProps> = ({
|
||||
// If productData.image is a *URL* (string), show it as a default preview
|
||||
useEffect(() => {
|
||||
if (productData.image && typeof productData.image === "string") {
|
||||
setImagePreview(productData.image);
|
||||
setImagePreview(`${process.env.NEXT_PUBLIC_API_URL}/products/${productData._id}/image`);
|
||||
}
|
||||
}, [productData.image]);
|
||||
|
||||
@@ -72,6 +72,7 @@ export const ProductModal: React.FC<ProductModalProps> = ({
|
||||
}
|
||||
|
||||
// For preview
|
||||
console.log(file)
|
||||
const objectUrl = URL.createObjectURL(file);
|
||||
setSelectedFile(file);
|
||||
setImagePreview(objectUrl);
|
||||
@@ -96,6 +97,7 @@ export const ProductModal: React.FC<ProductModalProps> = ({
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
onSave(productData, selectedFile);
|
||||
toast.success(editing ? "Product updated!" : "Product added!");
|
||||
onClose();
|
||||
|
||||
Reference in New Issue
Block a user