Ghost/ghost/admin/app/components/settings/integrations/regenerate-key-modal.js
Kevin Ansfield f92c62b59a Switched API key regeneration modal to new modal pattern
refs https://github.com/TryGhost/Team/issues/1734
refs https://github.com/TryGhost/Team/issues/559
refs https://github.com/TryGhost/Ghost/issues/14101

- switches to newer modal patterns ready for later Ember upgrades
- migrated Zapier controller to native class syntax
- fixed regeneration confirmation text not being visible on Zapier screen
2022-11-14 09:55:34 +00:00

36 lines
1.1 KiB
JavaScript

import Component from '@glimmer/component';
import {capitalize} from '@ember/string';
import {inject as service} from '@ember/service';
import {task} from 'ember-concurrency';
import {tracked} from '@glimmer/tracking';
export default class RegenerateKeyModal extends Component {
@service ajax;
@service ghostPaths;
@service notifications;
@service store;
@tracked errorMessage;
@task({drop: true})
*regenerateKeyTask() {
const {integration, apiKey} = this.args.data;
const url = this.ghostPaths.url.api('/integrations/', integration.id, 'api_key', apiKey.id, 'refresh');
try {
const response = yield this.ajax.post(url, {
data: {
integrations: [{id: integration.id}]
}
});
this.store.pushPayload(response);
this.args.close(apiKey);
} catch (e) {
console.error(e); // eslint-disable-line
this.errorMessage = `There was an error regenerating the ${capitalize(apiKey.type)} API Key. Please try again`;
return;
}
}
}