Ghost/ghost/admin/app/controllers/offers.js
Rishabh 88049f1692 Updated offers list to filter on archived offers
refs https://github.com/TryGhost/Team/issues/1136

- adds dropdown for active/archived offers selection
- wires active/archived offers on list screen to API
- filters offers list on archived/active based on selection
2021-10-13 21:23:30 +05:30

66 lines
1.4 KiB
JavaScript

import Controller from '@ember/controller';
import {action} from '@ember/object';
import {inject as service} from '@ember/service';
import {task} from 'ember-concurrency-decorators';
import {tracked} from '@glimmer/tracking';
const TYPES = [{
name: 'Active',
value: 'active'
},{
name: 'Archived',
value: 'archived'
}];
export default class MembersController extends Controller {
@service modals;
@service router;
@tracked offers = [];
@tracked type = 'active';
queryParams = [
'type'
];
constructor() {
super(...arguments);
this.availableTypes = TYPES;
}
get filteredOffers() {
return this.offers.filter((offer) => {
return offer.status === this.type;
});
}
get offersExist() {
return this.offers.length > 0;
}
get selectedType() {
return this.type ? TYPES.find((d) => {
return this.type === d.value;
}) : TYPES[0];
}
@action
onTypeChange(type) {
this.type = type.value;
}
@action
openLinkDialog(offer) {
this.advancedModal = this.modals.open('modals/offers/link', {
offer: offer
}, {
className: 'fullscreen-modal-action fullscreen-modal-wide'
});
}
@task({restartable: true})
*fetchOffersTask() {
this.offers = yield this.store.query('offer', {limit: 'all'});
}
}