Ghost/ghost/admin/app/components/modal-new-integration.js
Peter Zimon 04d9caefed Updated navigation (#1832)
no issue

Updated settings navigation to a completely redesigned flow for Ghost 4.0 🎉

Co-authored-by: Kevin Ansfield <kevin@lookingsideways.co.uk>
Co-authored-by: Fabien O'Carroll <fabien@allou.is>
Co-authored-by: Rish <zrishabhgarg@gmail.com>
2021-02-02 16:08:06 +00:00

52 lines
1.6 KiB
JavaScript

import ModalComponent from 'ghost-admin/components/modal-base';
import {alias} from '@ember/object/computed';
import {A as emberA} from '@ember/array';
import {isInvalidError} from 'ember-ajax/errors';
import {inject as service} from '@ember/service';
import {task} from 'ember-concurrency';
export default ModalComponent.extend({
router: service(),
confirm() {},
integration: alias('model'),
actions: {
updateName(name) {
this.integration.set('name', name);
this.integration.set('hasValidated', emberA());
this.integration.errors.clear();
},
confirm() {
return this.createIntegration.perform();
}
},
createIntegration: task(function* () {
try {
let integration = yield this.confirm();
this.router.transitionTo('integration', integration);
} 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.payload.errors;
let {message} = firstError;
if (message && message.match(/name/i)) {
this.get('integration.errors').add('name', message);
this.get('integration.hasValidated').pushObject('name');
return;
}
}
// bubble up to the global error handler
if (error) {
throw error;
}
}
}).drop()
});