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