From aeaadf7cabe33367e84de7b959e6df4f1426f70a Mon Sep 17 00:00:00 2001 From: Rostislav Wolny Date: Mon, 23 Oct 2023 16:18:43 +0200 Subject: [PATCH] Add error notice when email saving fails [MAILPOET-5660] --- .../src/email-editor/engine/store/actions.ts | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/mailpoet/assets/js/src/email-editor/engine/store/actions.ts b/mailpoet/assets/js/src/email-editor/engine/store/actions.ts index 3d2942cda3..635fdd9cbd 100644 --- a/mailpoet/assets/js/src/email-editor/engine/store/actions.ts +++ b/mailpoet/assets/js/src/email-editor/engine/store/actions.ts @@ -59,17 +59,30 @@ export const closeSidebar = export function* saveEditedEmail() { const postId = select(storeName).getEmailPostId(); // This returns a promise - yield dispatch(coreDataStore).saveEditedEntityRecord( + + const result = yield dispatch(coreDataStore).saveEditedEntityRecord( 'postType', 'mailpoet_email', postId, - {}, + { throwOnError: true }, ); - return dispatch(noticesStore).createSuccessNotice( - __('Email saved!', 'mailpoet'), - { type: 'snackbar', isDismissible: true }, - ); + result.then(() => { + dispatch(noticesStore).createErrorNotice(__('Email saved!', 'mailpoet'), { + type: 'snackbar', + isDismissible: true, + }); + }); + + result.catch(() => { + dispatch(noticesStore).createErrorNotice( + __('There was an error saving email!', 'mailpoet'), + { + type: 'default', + isDismissible: true, + }, + ); + }); } export function* updateEmailProperty(name: string, subject: string) {