mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-18 16:01:40 +03:00
28e4eb60ae
refs https://github.com/TryGhost/Team/issues/2233 **Problem** When a user clicks an offer link that has an archived tier, the site blocks and you are no longer able to scroll. This is because the product for that offer can't be found. This has been fixed by updating the `isActiveOffer` helper to also check for the existence of the corresponding tier. **Solution** - You no longer are able to create new offers if there are no active tiers - A custom message is shown that instructs the user to create a new tier if there are not active tiers on the offers page - Improved detection of changes in tiers by correctly reloading the members utils service after tier changes - Portal redirects to the homepage for offers with an archived tier (same behaviour as invalid offers) - Offers of an archived tier are no longer visible in the dashboard
88 lines
2.4 KiB
JavaScript
88 lines
2.4 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;
|
|
@service membersUtils;
|
|
|
|
@tracked offers = [];
|
|
@tracked tiers = [];
|
|
@tracked type = 'active';
|
|
|
|
queryParams = [
|
|
'type'
|
|
];
|
|
|
|
constructor() {
|
|
super(...arguments);
|
|
this.availableTypes = TYPES;
|
|
}
|
|
|
|
get filteredOffers() {
|
|
return this.offers.filter((offer) => {
|
|
const tier = this.tiers.find((p) => {
|
|
return p.id === offer.tier.id;
|
|
});
|
|
const price = offer.cadence === 'month' ? tier.monthlyPrice : tier.yearlyPrice;
|
|
return !!tier && tier.active && offer.status === this.type && !!price;
|
|
}).map((offer) => {
|
|
const tier = this.tiers.find((p) => {
|
|
return p.id === offer.tier.id;
|
|
});
|
|
const price = offer.cadence === 'month' ? tier.monthlyPrice : tier.yearlyPrice;
|
|
offer.finalCurrency = offer.currency || tier.currency;
|
|
offer.originalPrice = price;
|
|
if (offer.type !== 'trial') {
|
|
offer.updatedPrice = offer.type === 'fixed' ? (price - offer.amount) : (price - ((price * offer.amount) / 100));
|
|
} else {
|
|
offer.updatedPrice = offer.originalPrice;
|
|
}
|
|
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.tiers = yield this.store.query('tier', {
|
|
filter: 'type:paid', include: 'monthly_price,yearly_price'
|
|
});
|
|
this.offers = yield this.store.query('offer', {limit: 'all'});
|
|
return this.offers;
|
|
}
|
|
}
|