react-email-editor icon indicating copy to clipboard operation
react-email-editor copied to clipboard

image:removed isn't triggered

Open BenPrt opened this issue 4 years ago • 5 comments

Hi there,

I'm using a custom file storage to handle image uploads and it's working fine. Now, I'd want to handle image deletion but I have a problem using the according callback. I register it this the same way I did with the upload callback :

registerUploadCallback = () => {
    // Register callback method to Email Editor (unLayer).
    this.editorRef.registerCallback("image", (file, done) => {
      
       [...]

      // Call Api to get the temporary file name.
      apiPostUploadFile(formDataToSend)
        .then((apiResponse) => {

          [...]

          done({
            progress: 100,
            url:      fileURL,
          });
        })
        .catch((error) => {
          handleError(error);
        });
    });
  }

registerImageDeletionCallback = () => {
    console.log("registering image deletion callback...");
    // Register callback method to Email Editor (unLayer).
    this.editorRef.registerCallback("image:removed", (image) => {
      console.log("DELETION", image);
    });
  }

When I upload an image, the upload callback is well triggered, but when I click on the "Delete" button, nothing happens.

Am I doing something wrong or is there a problem with the image:removed callback ?

Thank you !

BenPrt avatar Oct 21 '20 14:10 BenPrt

@BenPrt the image:removed call back is only called when you want to permanently delete the image from the "Uploads" tab. It's not called when you delete an image from your design. For that, I would recommend looking at design:updated.

adeelraza avatar Oct 26 '20 19:10 adeelraza

Ohw, okay, thanks !

I succeeded to do what I planned (delete media from my personnal file storage on layout deletion) with the design:updated callback, as you suggested !

Thank you !

BenPrt avatar Oct 26 '20 21:10 BenPrt

@adeelraza I am trying to use 'image:removed' for its intended use (deleting an image from the uploads tab). I am getting "Invalid image selected" when I click delete in the editor. Any ideas why? Screen Shot 2021-03-04 at 10 20 10 AM

bhamlefty avatar Mar 04 '21 18:03 bhamlefty

@bhamlefty I suspect this maybe happening because we expect the image id to be a number.

adeelraza avatar Mar 05 '21 08:03 adeelraza

registerCallback precisa ser chamado dentro da função onReady:

exemplo:

const onReady = () => { emailEditorRef.current.editor.registerCallback ('imagem', função (arquivo, concluído) {

let files = file.attachments[0] let reader = new FileReader(); let imageBase64; console.log("onReady=> emailEditorRef") console.log("File: ", file) console.log("FileS: ", files)

reader.onloadend = function () { imageBase64 = reader.result; console.log("64 =>", imageBase64) }

if (file) { reader.readAsDataURL(files); }
}; }

lembrando que onReady deve estar dentro do componente EmailEditor assim como os outros adereços de que você precisa.

<EmailEditor ref={emailEditorRef} onLoad={onLoad} onReady={onReady} saveDesign={saveDesign} options={{locale: 'pt-BR'}} />

JoezerSmaniotto avatar Dec 01 '21 19:12 JoezerSmaniotto