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

Fixed "confirm leave" modal not showing if prices are unsaved in membership screen

no issue

- added `hasChangedPrices` method to check the controller's price properties against the active product prices
- check `hasChangedPrices` alongside changed settings when deciding if the confirm leave modal needs to be shown
- call a `resetPrices` method if a leave is forced which changes controller properties back to the amounts in the active product prices
This commit is contained in:
Kevin Ansfield 2021-05-19 18:32:28 +01:00
parent 5a3c9a54b1
commit f9f925d923

View file

@ -56,6 +56,23 @@ export default class MembersAccessController extends Controller {
return envConfig.environment !== 'development' && !/^https:/.test(siteUrl); return envConfig.environment !== 'development' && !/^https:/.test(siteUrl);
} }
get hasChangedPrices() {
if (this.product) {
const activePrices = this.stripePrices.filter(price => !!price.active);
const monthlyPrice = this.getPrice(activePrices, 'monthly');
const yearlyPrice = this.getPrice(activePrices, 'yearly');
if (monthlyPrice?.amount && this.stripeMonthlyAmount !== (monthlyPrice.amount / 100)) {
return true;
}
if (yearlyPrice?.amount && this.stripeYearlyAmount !== (yearlyPrice.amount / 100)) {
return true;
}
}
return false;
}
@action @action
setup() { setup() {
this.fetchDefaultProduct.perform(); this.fetchDefaultProduct.perform();
@ -63,7 +80,7 @@ export default class MembersAccessController extends Controller {
} }
leaveRoute(transition) { leaveRoute(transition) {
if (this.settings.get('hasDirtyAttributes')) { if (this.settings.get('hasDirtyAttributes') || this.hasChangedPrices) {
transition.abort(); transition.abort();
this.leaveSettingsTransition = transition; this.leaveSettingsTransition = transition;
this.showLeaveRouteModal = true; this.showLeaveRouteModal = true;
@ -363,6 +380,15 @@ export default class MembersAccessController extends Controller {
return result; return result;
} }
resetPrices() {
const activePrices = this.stripePrices.filter(price => !!price.active);
const monthlyPrice = this.getPrice(activePrices, 'monthly');
const yearlyPrice = this.getPrice(activePrices, 'yearly');
this.stripeMonthlyAmount = (monthlyPrice.amount / 100);
this.stripeYearlyAmount = (yearlyPrice.amount / 100);
}
reset() { reset() {
this.showLeaveRouteModal = false; this.showLeaveRouteModal = false;
this.showLeavePortalModal = false; this.showLeavePortalModal = false;