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

Handled custom prices in portal settings

refs https://github.com/TryGhost/Team/issues/637

Updates Portal settings to use list of custom prices for default product instead of hardcoded Monthly/Yearly
This commit is contained in:
Rishabh 2021-05-04 21:13:31 +05:30 committed by Rishabh Garg
parent ae95eee5df
commit 5d2e456f61
3 changed files with 55 additions and 40 deletions

View file

@ -53,44 +53,29 @@
<p>Free</p>
</label>
</div>
<div class="form-group mb0 for-checkbox">
<label
class="checkbox"
for="monthly-plan"
>
<input
type="checkbox"
id="monthly-plan"
name="monthly-plan"
checked={{this.isMonthlyChecked}}
disabled={{or (not this.isStripeConfigured) (not-eq this.settings.membersSignupAccess "all")}}
class="gh-input post-settings-featured"
{{on "click" (action "toggleMonthlyPlan" value="target.checked")}}
data-test-checkbox="featured"
>
<span class="input-toggle-component"></span>
<p>Monthly</p>
</label>
</div>
<div class="form-group mb0 for-checkbox">
<label
class="checkbox"
for="yearly-plan"
>
<input
type="checkbox"
id="yearly-plan"
name="yearly-plan"
checked={{this.isYearlyChecked}}
disabled={{or (not this.isStripeConfigured) (not-eq this.settings.membersSignupAccess "all")}}
class="gh-input post-settings-featured"
{{on "click" (action "toggleYearlyPlan" value="target.checked")}}
data-test-checkbox="featured"
>
<span class="input-toggle-component"></span>
<p>Yearly</p>
</label>
</div>
{{#if this.prices}}
{{#each this.filteredPrices as |price|}}
<div class="form-group mb0 for-checkbox">
<label class="checkbox" for="{{price.id}}">
<input
type="checkbox"
checked={{price.checked}}
id={{price.id}}
name={{price.id}}
disabled={{or
(not this.isStripeConfigured)
(not-eq this.settings.membersSignupAccess "all")
}}
class="gh-input post-settings-featured"
data-test-checkbox="featured"
{{on "click" (action "togglePlan" price.id)}}
/>
<span class="input-toggle-component"></span>
<p>{{price.nickname}}</p>
</label>
</div>
{{/each}}
{{/if}}
</div>
{{else}}
<div class="gh-portal-setting-no-stripe">

View file

@ -36,6 +36,7 @@ export default ModalComponent.extend({
config: service(),
membersUtils: service(),
settings: service(),
store: service(),
page: 'signup',
iconExtensions: null,
@ -46,11 +47,24 @@ export default ModalComponent.extend({
showLeaveSettingsModal: false,
freeSignupRedirect: undefined,
paidSignupRedirect: undefined,
prices: null,
confirm() {},
isStripeConfigured: reads('membersUtils.isStripeEnabled'),
filteredPrices: computed('prices', 'settings.portalPlans.[]', function () {
const portalPlans = this.get('settings.portalPlans');
return this.prices.filter((d) => {
return d.amount !== 0 && d.type === 'recurring';
}).map((price) => {
return {
...price,
checked: !!portalPlans.find(d => d === price.id)
};
});
}),
buttonIcon: computed('settings.portalButtonIcon', function () {
const defaultIconKeys = this.defaultButtonIcons.map(buttonIcon => buttonIcon.value);
return (this.settings.get('portalButtonIcon') || defaultIconKeys[0]);
@ -68,8 +82,9 @@ export default ModalComponent.extend({
return `data-portal`;
}),
portalPreviewUrl: computed('buttonIcon', 'page', 'isFreeChecked', 'isMonthlyChecked', 'isYearlyChecked', 'settings.{portalName,portalButton,portalButtonSignupText,portalButtonStyle,accentColor}', function () {
portalPreviewUrl: computed('buttonIcon', 'page', 'isFreeChecked', 'isMonthlyChecked', 'isYearlyChecked', 'settings.{portalName,portalButton,portalButtonSignupText,portalButtonStyle,accentColor,portalPlans.[]}', function () {
const options = this.getProperties(['buttonIcon', 'page', 'isFreeChecked', 'isMonthlyChecked', 'isYearlyChecked']);
options.portalPlans = this.get('settings.portalPlans');
return this.membersUtils.getPortalPreviewUrl(options);
}),
@ -119,7 +134,7 @@ export default ModalComponent.extend({
if (portalButtonIcon && !defaultIconKeys.includes(portalButtonIcon)) {
this.set('customIcon', this.settings.get('portalButtonIcon'));
}
this.getAvailablePrices.perform();
this.siteUrl = this.config.get('blogUrl');
},
@ -141,6 +156,9 @@ export default ModalComponent.extend({
toggleYearlyPlan(isChecked) {
this.updateAllowedPlan('yearly', isChecked);
},
togglePlan(priceId, event) {
this.updateAllowedPlan(priceId, event.target.checked);
},
togglePortalButton(showButton) {
this.settings.set('portalButton', showButton);
},
@ -297,5 +315,12 @@ export default ModalComponent.extend({
}
yield this.settings.save();
this.closeModal();
}).drop(),
getAvailablePrices: task(function* () {
const products = yield this.store.query('product', {include: 'stripe_prices'});
const product = products.firstObject;
const prices = product.get('stripePrices');
this.set('prices', prices);
}).drop()
});

View file

@ -28,6 +28,7 @@ export default class MembersUtilsService extends Service {
isYearlyChecked = true,
monthlyPrice,
yearlyPrice,
portalPlans,
currency
} = args;
@ -53,6 +54,10 @@ export default class MembersUtilsService extends Service {
settingsParam.append('signupButtonText', encodeURIComponent(signupButtonText));
settingsParam.append('allowSelfSignup', allowSelfSignup);
if (portalPlans) {
settingsParam.append('portalPrices', encodeURIComponent(portalPlans));
}
if (this.settings.get('accentColor') === '' || this.settings.get('accentColor')) {
settingsParam.append('accentColor', encodeURIComponent(`${this.settings.get('accentColor')}`));
}