Ghost/ghost/admin/app/components/modal-new-integration.js
Kevin Ansfield 5047b9f3d7 Added initial custom integrations UI (#1051)
refs https://github.com/TryGhost/Ghost/issues/9865, https://github.com/TryGhost/Ghost/issues/9942

- `integration`, `api-key`, and `webhook` models and respective mirage mocks
- moves integration routes around to match ember's concept of nested routes (nested routes reflect nested UI not nested URLs)
- adds custom integrations list to integrations screen
- adds custom integration screen
  - allow editing of integration details
  - show list of webhooks
  - webhook creation modal

NB: the `enableDeveloperExperiments` flag needs to be enabled in the `config.development.json` file for the custom integrations UI to be displayed until it's out of development.
2018-10-18 00:18:29 +01: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('settings.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()
});