From b417d5aca9172b263e64affbb47928cb8965713f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Adamczyk?= Date: Fri, 5 Oct 2018 14:26:32 +0200 Subject: [PATCH] EZP-29700: Syntax error after logging out --- .../config/bazinga_js_translation.yml | 1 + .../js/scripts/admin.notifications.modal.js | 28 ++++++++++++++++--- .../translations/notifications.en.xliff | 5 ++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/bundle/Resources/config/bazinga_js_translation.yml b/src/bundle/Resources/config/bazinga_js_translation.yml index 9abf2d5118..b82fe31122 100644 --- a/src/bundle/Resources/config/bazinga_js_translation.yml +++ b/src/bundle/Resources/config/bazinga_js_translation.yml @@ -2,3 +2,4 @@ active_domains: - 'universal_discovery_widget' - 'alloy_editor' - 'fieldtypes_edit' + - 'notifications' diff --git a/src/bundle/Resources/public/js/scripts/admin.notifications.modal.js b/src/bundle/Resources/public/js/scripts/admin.notifications.modal.js index 11803812e9..235f33baf9 100644 --- a/src/bundle/Resources/public/js/scripts/admin.notifications.modal.js +++ b/src/bundle/Resources/public/js/scripts/admin.notifications.modal.js @@ -1,5 +1,6 @@ (function(global, doc, eZ, React, ReactDOM, Translator) { let currentPageLink = null; + let getNotificationsStatusErrorShowed = false; const SELECTOR_MODAL_ITEM = '.ez-notifications-modal__item'; const SELECTOR_MODAL_RESULTS = '.ez-notifications-modal__results'; const SELECTOR_MODAL_TITLE = '.modal-title'; @@ -10,9 +11,8 @@ const CLASS_MODAL_LOADING = 'ez-notifications-modal--loading'; const INTERVAL = 30000; const modal = doc.querySelector('.ez-notifications-modal'); - const showErrorNotification = eZ.helpers.notification.showErrorNotification; - const getJsonFromResponse = eZ.helpers.request.getJsonFromResponse; - const getTextFromResponse = eZ.helpers.request.getTextFromResponse; + const { showErrorNotification, showWarningNotification } = eZ.helpers.notification; + const { getJsonFromResponse, getTextFromResponse } = eZ.helpers.request; const markAsRead = (notification, response) => { if (response.status === 'success') { notification.classList.add('ez-notifications-modal__item--read'); @@ -65,8 +65,28 @@ .then((notificationsInfo) => { setPendingNotificationCount(notificationsInfo); updateModalTitleTotalInfo(notificationsInfo.total); + getNotificationsStatusErrorShowed = false; }) - .catch(console.error); + .catch(onGetNotificationsStatusFailure); + }; + + /** + * Handle a failure while getting notifications status + * + * @method onGetNotificationsStatusFailure + */ + const onGetNotificationsStatusFailure = (error) => { + const message = Translator.trans( + /* @Desc("Cannot update notifications count") */ 'notifications.modal.message.error', + { error: error.message }, + 'notifications' + ); + + if (!getNotificationsStatusErrorShowed) { + showWarningNotification(message); + } + + getNotificationsStatusErrorShowed = true; }; const updateModalTitleTotalInfo = (notificationsCount) => { const modalTitle = modal.querySelector(SELECTOR_MODAL_TITLE); diff --git a/src/bundle/Resources/translations/notifications.en.xliff b/src/bundle/Resources/translations/notifications.en.xliff index 2c6b2aa17a..7bbed77bf2 100644 --- a/src/bundle/Resources/translations/notifications.en.xliff +++ b/src/bundle/Resources/translations/notifications.en.xliff @@ -56,6 +56,11 @@ Notifications key: notifications + + Cannot update notifications count + Cannot update notifications count + key: notifications.modal.message.error +