Ghost/ghost/admin/app/components/modals/offers/unarchive.js

35 lines
891 B
JavaScript
Raw Normal View History

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