Ghost/ghost/admin/app/components/modals/archive-offer.js
2021-10-22 16:19:58 +02:00

35 lines
904 B
JavaScript

import Component from '@glimmer/component';
import {inject as service} from '@ember/service';
import {task} from 'ember-concurrency-decorators';
export default class ArchiveOfferModalComponent extends Component {
@service notifications;
@service router;
get isActive() {
const {offer} = this.args.data;
return offer.status === 'active';
}
@task({drop: true})
*archiveOfferTask() {
const {offer} = this.args.data;
offer.status = 'archived';
try {
yield offer.save();
this.router.transitionTo('offers', {queryParams: {
type: 'archived'
}});
return offer;
} catch (error) {
if (error) {
this.notifications.showAPIError(error, {key: 'offer.save.failed'});
}
} finally {
this.args.close();
}
}
}