mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Updated portal plans on monthly/yearly price change
no refs Portal plans setting contains list of prices that are allowed by site owner to use in Portal UI. Since we now switch monthly/yearly prices dynamically, we need to update portal plans on price change to still reflect updated monthly/yearly prices in Portal UI.
This commit is contained in:
parent
eecd6d03b6
commit
f9672e7095
2 changed files with 19 additions and 1 deletions
|
@ -233,6 +233,7 @@ export default class MembersAccessController extends Controller {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (monthlyPrice && yearlyPrice) {
|
if (monthlyPrice && yearlyPrice) {
|
||||||
|
this.updatePortalPlans(monthlyPrice.id, yearlyPrice.id);
|
||||||
this.settings.set('membersMonthlyPriceId', monthlyPrice.id);
|
this.settings.set('membersMonthlyPriceId', monthlyPrice.id);
|
||||||
this.settings.set('membersYearlyPriceId', yearlyPrice.id);
|
this.settings.set('membersYearlyPriceId', yearlyPrice.id);
|
||||||
return this.product;
|
return this.product;
|
||||||
|
@ -242,6 +243,7 @@ export default class MembersAccessController extends Controller {
|
||||||
const updatedStripePrices = savedProduct.stripePrices || [];
|
const updatedStripePrices = savedProduct.stripePrices || [];
|
||||||
const updatedMonthlyPrice = getActivePrice(updatedStripePrices, 'month', monthlyAmount);
|
const updatedMonthlyPrice = getActivePrice(updatedStripePrices, 'month', monthlyAmount);
|
||||||
const updatedYearlyPrice = getActivePrice(updatedStripePrices, 'year', yearlyAmount);
|
const updatedYearlyPrice = getActivePrice(updatedStripePrices, 'year', yearlyAmount);
|
||||||
|
this.updatePortalPlans(updatedMonthlyPrice.id, updatedYearlyPrice.id);
|
||||||
this.settings.set('membersMonthlyPriceId', updatedMonthlyPrice.id);
|
this.settings.set('membersMonthlyPriceId', updatedMonthlyPrice.id);
|
||||||
this.settings.set('membersYearlyPriceId', updatedYearlyPrice.id);
|
this.settings.set('membersYearlyPriceId', updatedYearlyPrice.id);
|
||||||
return savedProduct;
|
return savedProduct;
|
||||||
|
@ -249,6 +251,22 @@ export default class MembersAccessController extends Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updatePortalPlans(monthlyPriceId, yearlyPriceId) {
|
||||||
|
let portalPlans = this.settings.get('portalPlans') || [];
|
||||||
|
const currentMontlyPriceId = this.settings.get('membersMonthlyPriceId');
|
||||||
|
const currentYearlyPriceId = this.settings.get('membersYearlyPriceId');
|
||||||
|
if (portalPlans.includes(currentMontlyPriceId)) {
|
||||||
|
portalPlans = portalPlans.filter(d => d.id !== currentMontlyPriceId);
|
||||||
|
portalPlans.push(monthlyPriceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (portalPlans.includes(currentYearlyPriceId)) {
|
||||||
|
portalPlans = portalPlans.filter(d => d.id !== currentYearlyPriceId);
|
||||||
|
portalPlans.push(yearlyPriceId);
|
||||||
|
}
|
||||||
|
this.settings.set('portalPlans', portalPlans);
|
||||||
|
}
|
||||||
|
|
||||||
getPrice(prices, type) {
|
getPrice(prices, type) {
|
||||||
const monthlyPriceId = this.settings.get('membersMonthlyPriceId');
|
const monthlyPriceId = this.settings.get('membersMonthlyPriceId');
|
||||||
const yearlyPriceId = this.settings.get('membersYearlyPriceId');
|
const yearlyPriceId = this.settings.get('membersYearlyPriceId');
|
||||||
|
|
|
@ -167,7 +167,7 @@
|
||||||
@placeholder=''
|
@placeholder=''
|
||||||
data-test-title-input={{true}}
|
data-test-title-input={{true}}
|
||||||
/>
|
/>
|
||||||
<span class="gh-input-append"><span class="ttu">{{this.currency}}</span>/month</span>
|
<span class="gh-input-append"><span class="ttu">{{this.currency}}</span>/year</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{#if this.stripePlanError}}
|
{{#if this.stripePlanError}}
|
||||||
|
|
Loading…
Add table
Reference in a new issue