Ghost/ghost/admin/app/components/modal-new-subscriber.js
Kevin Ansfield 9ed5aad186 Flatten nested components (#854)
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
2017-09-11 14:41:17 +07:00

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();
}
}
});