Refactor fail callbacks in list import controller
[MAILPOET-1732]
This commit is contained in:
committed by
M. Shull
parent
fdef926682
commit
b94a358f59
@@ -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(
|
|
||||||
response.errors.map(error => error.message),
|
|
||||||
{ scroll: true }
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
handleApiError(response) {
|
||||||
|
this.setState({ loading: false });
|
||||||
|
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) {
|
||||||
|
@@ -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 won’t be changed.'),
|
'wooCommerceListImportInfo4': __('Their subscription preference on other lists won’t 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 %>
|
||||||
|
Reference in New Issue
Block a user