mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 22:43:30 +03:00
909bd60db3
no issue - enter key when a modal is displayed will always trigger the `confirm` action, if it's not provided then the base modal will throw a `You must override the "confirm" action ...` error
45 lines
1.4 KiB
JavaScript
45 lines
1.4 KiB
JavaScript
import ModalComponent from 'ghost-admin/components/modal-base';
|
|
import {alias} from '@ember/object/computed';
|
|
import {capitalize} from '@ember/string';
|
|
import {inject as service} from '@ember/service';
|
|
import {task} from 'ember-concurrency';
|
|
|
|
export default ModalComponent.extend({
|
|
ajax: service(),
|
|
store: service(),
|
|
ghostPaths: service(),
|
|
|
|
errorMessage: null,
|
|
|
|
// Allowed actions
|
|
confirm: () => {},
|
|
|
|
apiKey: alias('model.apiKey'),
|
|
integration: alias('model.integration'),
|
|
internalIntegration: alias('model.internalIntegration'),
|
|
|
|
actions: {
|
|
confirm() {
|
|
this.regenerateApiKey.perform();
|
|
}
|
|
},
|
|
|
|
regenerateKey: task(function* () {
|
|
let url = this.get('ghostPaths.url').api('/integrations/', this.integration.id, 'api_key', this.apiKey.id, 'refresh');
|
|
try {
|
|
const response = yield this.ajax.post(url, {
|
|
data: {
|
|
integrations: [{id: this.integration.id}]
|
|
}
|
|
});
|
|
this.store.pushPayload(response);
|
|
yield this.confirm();
|
|
this.send('closeModal');
|
|
} catch (e) {
|
|
let errMessage = `There was an error regenerating the ${capitalize(this.apiKey.type)} API Key. Please try again`;
|
|
this.set('errorMessage', errMessage);
|
|
return;
|
|
}
|
|
}).drop()
|
|
});
|