diff --git a/addons/website/static/src/client_actions/configurator/configurator.js b/addons/website/static/src/client_actions/configurator/configurator.js index 3360347f75f..70532286b73 100644 --- a/addons/website/static/src/client_actions/configurator/configurator.js +++ b/addons/website/static/src/client_actions/configurator/configurator.js @@ -238,6 +238,7 @@ class PaletteSelectionScreen extends Component { async changeLogo() { const logoSelectInput = this.logoInputRef.el; if (logoSelectInput.files.length === 1) { + const previousLogoAttachmentId = this.state.logoAttachmentId; const file = logoSelectInput.files[0]; const data = await getDataURLFromFile(file); const attachment = await this.rpc('/web_editor/attachment/add_data', { @@ -246,6 +247,9 @@ class PaletteSelectionScreen extends Component { 'is_image': true, }); if (!attachment.error) { + if (previousLogoAttachmentId) { + await this._removeAttachments([previousLogoAttachmentId]); + } this.state.changeLogo(data, attachment.id); this.updatePalettes(); } else { @@ -277,6 +281,16 @@ class PaletteSelectionScreen extends Component { this.state.selectPalette(paletteName); this.props.navigate(ROUTES.featuresSelectionScreen); } + + /** + * Removes the attachments from the DB. + * + * @private + * @param {Array} ids the attachment ids to remove + */ + async _removeAttachments(ids) { + this.rpc("/web_editor/attachment/remove", { ids: ids }); + } } Object.assign(PaletteSelectionScreen, {