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:
parent
5a3c9a54b1
commit
f9f925d923
1 changed files with 27 additions and 1 deletions
|
@ -56,6 +56,23 @@ export default class MembersAccessController extends Controller {
|
|||
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
|
||||
setup() {
|
||||
this.fetchDefaultProduct.perform();
|
||||
|
@ -63,7 +80,7 @@ export default class MembersAccessController extends Controller {
|
|||
}
|
||||
|
||||
leaveRoute(transition) {
|
||||
if (this.settings.get('hasDirtyAttributes')) {
|
||||
if (this.settings.get('hasDirtyAttributes') || this.hasChangedPrices) {
|
||||
transition.abort();
|
||||
this.leaveSettingsTransition = transition;
|
||||
this.showLeaveRouteModal = true;
|
||||
|
@ -363,6 +380,15 @@ export default class MembersAccessController extends Controller {
|
|||
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() {
|
||||
this.showLeaveRouteModal = false;
|
||||
this.showLeavePortalModal = false;
|
||||
|
|
Loading…
Add table
Reference in a new issue