Refactor fail callbacks in list import controller

[MAILPOET-1732]
This commit is contained in:
Rostislav Wolny
2019-04-01 11:27:57 +02:00
committed by M. Shull
parent fdef926682
commit b94a358f59
2 changed files with 12 additions and 18 deletions

View File

@@ -25,15 +25,7 @@ class WooCommerceImportController extends React.Component {
endpoint: 'settings', endpoint: 'settings',
action: 'set', action: 'set',
data, data,
}).fail((response) => { }).fail(this.handleApiError);
this.setState({ loading: false });
if (response.errors.length > 0) {
MailPoet.Notice.error(
response.errors.map(error => error.message),
{ scroll: true }
);
}
});
} }
scheduleImport() { scheduleImport() {
@@ -41,15 +33,16 @@ class WooCommerceImportController extends React.Component {
api_version: window.mailpoet_api_version, api_version: window.mailpoet_api_version,
endpoint: 'importExport', endpoint: 'importExport',
action: 'setupWooCommerceInitialImport', action: 'setupWooCommerceInitialImport',
}).then(() => this.setState({ loading: false })).fail((response) => { }).then(() => this.setState({ loading: false })).fail(this.handleApiError);
this.setState({ loading: false }); }
if (response.errors.length > 0) {
MailPoet.Notice.error( handleApiError(response) {
response.errors.map(error => error.message), this.setState({ loading: false });
{ scroll: true } let errorMessage = MailPoet.I18n.t('unknownError');
); 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

@@ -20,5 +20,6 @@
'wooCommerceListImportCheckboxUnsubscribed': __('<b>add</b> all my customers to the list, but <b>as unsubscribed</b>. They can join this list next time they check out'), 'wooCommerceListImportCheckboxUnsubscribed': __('<b>add</b> all my customers to the list, but <b>as unsubscribed</b>. They can join this list next time they check out'),
'wooCommerceListImportInfo4': __('Their subscription preference on other lists wont be changed.'), 'wooCommerceListImportInfo4': __('Their subscription preference on other lists wont be changed.'),
'wooCommerceListImportSubmit': _x('Create my WooCommerce Customers list now!', 'Submit button caption'), 'wooCommerceListImportSubmit': _x('Create my WooCommerce Customers list now!', 'Submit button caption'),
'unknownError': __('Unknown error'),
}) %> }) %>
<% endblock %> <% endblock %>