Create default responseerror notice

[MAILPOET-1856]
This commit is contained in:
Pavel Dohnal
2019-05-15 13:25:55 +02:00
committed by M. Shull
parent c6b2b610a9
commit a81c12ecc1
4 changed files with 13 additions and 12 deletions

View File

@@ -218,4 +218,14 @@ MailPoet.Notice = {
message: message, message: message,
}, options)); }, options));
}, },
showApiErrorNotice: function showApiErrorNotice(response, options) {
var errorMessage = MailPoet.I18n.t('ajaxFailedErrorMessage');
if (response && response.errors && response.errors.length > 0) {
errorMessage = response.errors.map(error => error.message);
}
this.show(jQuery.extend({}, {
type: 'error',
message: errorMessage,
}, options));
},
}; };

View File

@@ -7,11 +7,7 @@ function RevenueTrackingPermission() {
const handleApiError = (response) => { const handleApiError = (response) => {
setLoading(false); setLoading(false);
let errorMessage = MailPoet.I18n.t('unknownError'); MailPoet.Notice.showApiErrorNotice(response, { scroll: true });
if (response && response.errors && response.errors.length > 0) {
errorMessage = response.errors.map(error => error.message);
}
MailPoet.Notice.error(errorMessage, { scroll: true });
}; };
const updateSettings = data => MailPoet.Ajax.post({ const updateSettings = data => MailPoet.Ajax.post({

View File

@@ -38,11 +38,7 @@ class WooCommerceImportController extends React.Component {
handleApiError(response) { handleApiError(response) {
this.setState({ loading: false }); this.setState({ loading: false });
let errorMessage = MailPoet.I18n.t('unknownError'); MailPoet.Notice.showApiErrorNotice(response, { scroll: true });
if (response && response.errors && response.errors.length > 0) {
errorMessage = response.errors.map(error => error.message);
}
MailPoet.Notice.error(errorMessage, { scroll: true });
} }
submit(importType) { submit(importType) {

View File

@@ -16,7 +16,6 @@
'revenueTrackingInfo2': _x('This is practical for abandoned cart emails and when a customer uses several email addresses.', '“abandoned cart emails“ are emails which are sent automatically from e-commerce websites when a customer add a product to the cart and then leave the website'), 'revenueTrackingInfo2': _x('This is practical for abandoned cart emails and when a customer uses several email addresses.', '“abandoned cart emails“ are emails which are sent automatically from e-commerce websites when a customer add a product to the cart and then leave the website'),
'revenueTrackingAllow': _x('Allow MailPoet cookies. My visitors are made aware that cookies are used on my website', '“MailPoet cookies” and “cookies” are browser cookies created by MailPoet'), 'revenueTrackingAllow': _x('Allow MailPoet cookies. My visitors are made aware that cookies are used on my website', '“MailPoet cookies” and “cookies” are browser cookies created by MailPoet'),
'revenueTrackingDontAllow': _x('Dont allow MailPoet cookies and rely on basic revenue tracking', '“MailPoet cookies” are browser cookies created by MailPoet'), 'revenueTrackingDontAllow': _x('Dont allow MailPoet cookies and rely on basic revenue tracking', '“MailPoet cookies” are browser cookies created by MailPoet'),
'revenueTrackingSubmit': _x('Save', 'Submit button caption'), 'revenueTrackingSubmit': _x('Save', 'Submit button caption')
'unknownError': __('Unknown error')
}) %> }) %>
<% endblock %> <% endblock %>