mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 19:52:01 +03:00
85d7932e45
refs https://github.com/TryGhost/Team/issues/559
refs 054a5f15f5
- with the update of `ember-promise-modals` we started to get deprecation warnings when using `modals.open('modal-component-name')`
- upcoming Ember build updates will introduce tree shaking but using run-time lookup of modal components by name works against that because it's not statically analysable
- switched to importing components and passing the component class directly, eg. `modals.open(ModalComponent)`
- standardized modal component class names with a `MyModal` style to get better behaviour in code editors when it auto generates imports
- dropped the modal defaults from the modals service because we can now use a static `modalOptions` property on the modal components themselves when we want to override the defaults
83 lines
2.3 KiB
JavaScript
83 lines
2.3 KiB
JavaScript
import Controller from '@ember/controller';
|
|
import LinkOfferModal from '../components/modals/offers/link';
|
|
import {action} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
import {task} from 'ember-concurrency';
|
|
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 products = [];
|
|
@tracked type = 'active';
|
|
|
|
queryParams = [
|
|
'type'
|
|
];
|
|
|
|
constructor() {
|
|
super(...arguments);
|
|
this.availableTypes = TYPES;
|
|
}
|
|
|
|
get filteredOffers() {
|
|
return this.offers.filter((offer) => {
|
|
const product = this.products.find((p) => {
|
|
return p.id === offer.tier.id;
|
|
});
|
|
const price = offer.cadence === 'month' ? product.monthlyPrice : product.yearlyPrice;
|
|
return offer.status === this.type && !!price;
|
|
}).map((offer) => {
|
|
const product = this.products.find((p) => {
|
|
return p.id === offer.tier.id;
|
|
});
|
|
const price = offer.cadence === 'month' ? product.monthlyPrice : product.yearlyPrice;
|
|
offer.finalCurrency = offer.currency || price.currency;
|
|
offer.originalPrice = price.amount;
|
|
offer.updatedPrice = offer.type === 'fixed' ? (price.amount - offer.amount) : (price.amount - ((price.amount * offer.amount) / 100));
|
|
return offer;
|
|
});
|
|
}
|
|
|
|
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(LinkOfferModal, {
|
|
offer: offer
|
|
});
|
|
}
|
|
|
|
@task({restartable: true})
|
|
*fetchOffersTask() {
|
|
this.products = yield this.store.query('product', {
|
|
filter: 'type:paid', include: 'monthly_price,yearly_price'
|
|
});
|
|
this.offers = yield this.store.query('offer', {limit: 'all'});
|
|
return this.offers;
|
|
}
|
|
}
|