Ghost/ghost/admin/app/components/modals/delete-post.js
Kevin Ansfield a122711043 Converted delete-post modal to EPM based modal
refs https://github.com/TryGhost/Team/issues/559

- moved the modal component class and template into a `components/modals/` directory to keep the top-level dir cleaner
- migrated component class to glimmer syntax
- moved route transition behaviour directly into the class to avoid weird route-action indirection
2021-09-13 13:01:12 +01:00

27 lines
846 B
JavaScript

import Component from '@glimmer/component';
import {inject as service} from '@ember/service';
import {task} from 'ember-concurrency-decorators';
export default class DeletePostModalComponent extends Component {
@service notifications;
@service router;
@task
*deletePostTask() {
try {
const {post} = this.args.data;
// clear the data store and post of any unsaved client-generated tags before deleting
post.updateTags();
yield post.destroyRecord();
this.notifications.closeAlerts('post.delete');
this.router.transitionTo(post.displayName === 'page' ? 'pages' : 'posts');
} catch (error) {
this.notifications.showAPIError(error, {key: 'post.delete.failed'});
} finally {
this.args.close();
}
}
}