Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

Fix(avatar): Avatar upload does not fail anymore if no change in file hasbeen done

Jonathan ARNAULTd885d0a31a0e
diff --git a/src/misc/ImageEditorField.tsx b/src/misc/ImageEditorField.tsx
index 014525c4..eb066e41 100644
--- a/src/misc/ImageEditorField.tsx
+++ b/src/misc/ImageEditorField.tsx
@@ -97,12 +97,14 @@ const ImageEditorDialog = (props: ImageEditorDialogProps) => {
const croppedImage = cropper?.getCroppedCanvas().toDataURL();
if (croppedImage) {
setImageSrc(croppedImage);
+
+ const newFile = file ?? new File([], initialValue?.src);
setValue(
props.source,
{
src: croppedImage,
- title: file?.name,
- rawFile: file,
+ title: newFile.name,
+ rawFile: newFile,
},
{ shouldDirty: true }
);
diff --git a/src/providers/supabase/dataProvider.ts b/src/providers/supabase/dataProvider.ts
index 33c3eb06..afc76436 100644
--- a/src/providers/supabase/dataProvider.ts
+++ b/src/providers/supabase/dataProvider.ts
@@ -359,13 +359,17 @@ const uploadToBucket = async (fi: RAFile) => {
}
}
+ const dataContent = fi.src
+ ? await fetch(fi.src).then(res => res.blob())
+ : fi.rawFile;
+
const file = fi.rawFile;
const fileExt = file.name.split('.').pop();
const fileName = `${Math.random()}.${fileExt}`;
const filePath = `${fileName}`;
const { error: uploadError } = await supabase.storage
.from('attachments')
- .upload(filePath, file);
+ .upload(filePath, dataContent);
if (uploadError) {
console.error('uploadError', uploadError);