mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-03 03:55:26 +03:00
9ed5aad186
no issue - the upcoming Module Unification re-organisation in Ember will no longer support nested components - this PR pre-emptively moves our usage of nested components into a flat file structure
45 lines
1.4 KiB
JavaScript
45 lines
1.4 KiB
JavaScript
import ModalComponent from 'ghost-admin/components/modal-base';
|
|
import {A as emberA} from '@ember/array';
|
|
import {isInvalidError} from 'ember-ajax/errors';
|
|
import {task} from 'ember-concurrency';
|
|
|
|
export default ModalComponent.extend({
|
|
|
|
addSubscriber: task(function* () {
|
|
try {
|
|
yield this.get('confirm')();
|
|
this.send('closeModal');
|
|
} catch (error) {
|
|
// TODO: server-side validation errors should be serialized
|
|
// properly so that errors are added to model.errors automatically
|
|
if (error && isInvalidError(error)) {
|
|
let [firstError] = error.errors;
|
|
let {message} = firstError;
|
|
|
|
if (message && message.match(/email/i)) {
|
|
this.get('model.errors').add('email', message);
|
|
this.get('model.hasValidated').pushObject('email');
|
|
return;
|
|
}
|
|
}
|
|
|
|
// route action so it should bubble up to the global error handler
|
|
if (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
}).drop(),
|
|
|
|
actions: {
|
|
updateEmail(newEmail) {
|
|
this.set('model.email', newEmail);
|
|
this.set('model.hasValidated', emberA());
|
|
this.get('model.errors').clear();
|
|
},
|
|
|
|
confirm() {
|
|
this.get('addSubscriber').perform();
|
|
}
|
|
}
|
|
});
|