0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

Updated portal preview to update on price change

no refs

Portal preview on membership settings reflects the currently set monthly/yearly price directly by passing in the updated amount to portal preview URL
This commit is contained in:
Rishabh 2021-05-18 22:59:34 +05:30
parent db09b317eb
commit e22d54ba3b

View file

@ -177,13 +177,29 @@ export default class MembersAccessController extends Controller {
@action @action
updatePortalPreview() { updatePortalPreview() {
// TODO: can these be worked out from settings in membersUtils? // TODO: can these be worked out from settings in membersUtils?
const monthlyPrice = this.stripeMonthlyAmount; const monthlyPrice = this.stripeMonthlyAmount * 100;
const yearlyPrice = this.stripeYearlyAmount; const yearlyPrice = this.stripeYearlyAmount * 100;
let portalPlans = this.settings.get('portalPlans') || [];
const currentMontlyPriceId = this.settings.get('membersMonthlyPriceId');
const currentYearlyPriceId = this.settings.get('membersYearlyPriceId');
let isMonthlyChecked = false;
let isYearlyChecked = false;
if (portalPlans.includes(currentMontlyPriceId)) {
isMonthlyChecked = true;
}
if (portalPlans.includes(currentYearlyPriceId)) {
isYearlyChecked = true;
}
this.portalPreviewUrl = this.membersUtils.getPortalPreviewUrl({ this.portalPreviewUrl = this.membersUtils.getPortalPreviewUrl({
button: false, button: false,
monthlyPrice, monthlyPrice,
yearlyPrice yearlyPrice,
currency: this.currency,
isMonthlyChecked,
isYearlyChecked,
portalPlans: null
}); });
this.resizePortalPreviewTask.perform(); this.resizePortalPreviewTask.perform();
@ -291,12 +307,12 @@ export default class MembersAccessController extends Controller {
const currentMontlyPriceId = this.settings.get('membersMonthlyPriceId'); const currentMontlyPriceId = this.settings.get('membersMonthlyPriceId');
const currentYearlyPriceId = this.settings.get('membersYearlyPriceId'); const currentYearlyPriceId = this.settings.get('membersYearlyPriceId');
if (portalPlans.includes(currentMontlyPriceId)) { if (portalPlans.includes(currentMontlyPriceId)) {
portalPlans = portalPlans.filter(d => d.id !== currentMontlyPriceId); portalPlans = portalPlans.filter(priceId => priceId !== currentMontlyPriceId);
portalPlans.push(monthlyPriceId); portalPlans.push(monthlyPriceId);
} }
if (portalPlans.includes(currentYearlyPriceId)) { if (portalPlans.includes(currentYearlyPriceId)) {
portalPlans = portalPlans.filter(d => d.id !== currentYearlyPriceId); portalPlans = portalPlans.filter(priceId => priceId !== currentYearlyPriceId);
portalPlans.push(yearlyPriceId); portalPlans.push(yearlyPriceId);
} }
this.settings.set('portalPlans', portalPlans); this.settings.set('portalPlans', portalPlans);
@ -341,6 +357,7 @@ export default class MembersAccessController extends Controller {
if (yearlyPrice && yearlyPrice.amount) { if (yearlyPrice && yearlyPrice.amount) {
this.stripeYearlyAmount = (yearlyPrice.amount / 100); this.stripeYearlyAmount = (yearlyPrice.amount / 100);
} }
this.updatePortalPreview();
} }
} }