2019-11-07 11:37:26 +03:00
|
|
|
import ModalComponent from 'ghost-admin/components/modal-base';
|
2020-02-24 10:52:39 +03:00
|
|
|
import {computed} from '@ember/object';
|
|
|
|
import {pluralize} from 'ember-inflector';
|
2019-11-26 15:38:43 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2019-11-07 11:37:26 +03:00
|
|
|
import {task} from 'ember-concurrency';
|
|
|
|
|
|
|
|
export default ModalComponent.extend({
|
2019-11-26 15:38:43 +03:00
|
|
|
session: service(),
|
|
|
|
|
2019-11-21 02:23:23 +03:00
|
|
|
errorMessage: null,
|
|
|
|
|
2019-11-07 11:37:26 +03:00
|
|
|
// Allowed actions
|
|
|
|
confirm: () => {},
|
|
|
|
|
2020-02-24 10:52:39 +03:00
|
|
|
deliveredToMessage: computed('model.{paidOnly,memberCount}', function () {
|
|
|
|
const isEditor = this.get('session.user.isEditor');
|
|
|
|
if (this.get('model.paidOnly')) {
|
|
|
|
return 'all paid members';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isEditor) {
|
|
|
|
return 'all members';
|
|
|
|
}
|
|
|
|
|
|
|
|
return pluralize(this.get('model.memberCount'), 'member');
|
|
|
|
}),
|
|
|
|
|
2019-11-21 02:23:23 +03:00
|
|
|
confirmAndCheckError: task(function* () {
|
|
|
|
try {
|
|
|
|
yield this.confirm();
|
|
|
|
this.closeModal();
|
|
|
|
return true;
|
|
|
|
} catch (e) {
|
|
|
|
// switch to "failed" state if email fails
|
|
|
|
if (e && e.name === 'EmailFailedError') {
|
|
|
|
this.set('errorMessage', e.message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// close modal and continue with normal error handling if it was
|
|
|
|
// a non-email-related error
|
|
|
|
this.closeModal();
|
|
|
|
if (e) {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
2019-11-22 18:09:48 +03:00
|
|
|
}),
|
|
|
|
|
|
|
|
retryEmailTask: task(function* () {
|
|
|
|
try {
|
|
|
|
yield this.model.retryEmailSend();
|
|
|
|
this.closeModal();
|
|
|
|
return true;
|
|
|
|
} catch (e) {
|
|
|
|
// update "failed" state if email fails again
|
|
|
|
if (e && e.name === 'EmailFailedError') {
|
|
|
|
this.set('errorMessage', e.message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: test a non-email failure - maybe this needs to go through
|
|
|
|
// the notifications service
|
|
|
|
if (e) {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
2019-11-07 11:37:26 +03:00
|
|
|
})
|
|
|
|
});
|