mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-12 06:25:51 +03:00
85d7932e45
refs https://github.com/TryGhost/Team/issues/559
refs 054a5f15f5
- with the update of `ember-promise-modals` we started to get deprecation warnings when using `modals.open('modal-component-name')`
- upcoming Ember build updates will introduce tree shaking but using run-time lookup of modal components by name works against that because it's not statically analysable
- switched to importing components and passing the component class directly, eg. `modals.open(ModalComponent)`
- standardized modal component class names with a `MyModal` style to get better behaviour in code editors when it auto generates imports
- dropped the modal defaults from the modals service because we can now use a static `modalOptions` property on the modal components themselves when we want to override the defaults
65 lines
2.0 KiB
JavaScript
65 lines
2.0 KiB
JavaScript
import Component from '@glimmer/component';
|
|
import {A} from '@ember/array';
|
|
import {action} from '@ember/object';
|
|
import {isHostLimitError} from 'ghost-admin/services/ajax';
|
|
import {isInvalidError} from 'ember-ajax/errors';
|
|
import {inject as service} from '@ember/service';
|
|
import {task} from 'ember-concurrency';
|
|
import {tracked} from '@glimmer/tracking';
|
|
|
|
export default class NewCustomIntegrationModal extends Component {
|
|
@service router;
|
|
@service store;
|
|
|
|
@tracked errorMessage;
|
|
|
|
constructor() {
|
|
super(...arguments);
|
|
this.integration = this.store.createRecord('integration');
|
|
}
|
|
|
|
willDestroy() {
|
|
super.willDestroy(...arguments);
|
|
this.integration.rollbackAttributes();
|
|
}
|
|
|
|
@action
|
|
updateName(inputEvent) {
|
|
this.integration.set('name', inputEvent.target.value);
|
|
this.integration.set('hasValidated', A());
|
|
this.integration.errors.clear();
|
|
}
|
|
|
|
@task({drop: true})
|
|
*createIntegrationTask() {
|
|
try {
|
|
const integration = yield this.integration.save();
|
|
this.router.transitionTo('settings.integration', integration);
|
|
return true;
|
|
} 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.integration.errors.add('name', message);
|
|
this.integration.hasValidated.pushObject('name');
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (isHostLimitError(error)) {
|
|
this.errorMessage = error.payload.errors[0].context;
|
|
return;
|
|
}
|
|
|
|
// bubble up to the global error handler
|
|
if (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
}
|
|
}
|