mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
Added hasBenefits
helper to manage UI
no refs
This commit is contained in:
parent
d43998eb47
commit
5d4e5aa4c8
2 changed files with 23 additions and 4 deletions
|
@ -1,7 +1,7 @@
|
||||||
import React, {useContext} from 'react';
|
import React, {useContext} from 'react';
|
||||||
import AppContext from '../../AppContext';
|
import AppContext from '../../AppContext';
|
||||||
import calculateDiscount from '../../utils/discount';
|
import calculateDiscount from '../../utils/discount';
|
||||||
import {isCookiesDisabled, formatNumber, hasOnlyFreePlan} from '../../utils/helpers';
|
import {isCookiesDisabled, formatNumber, hasOnlyFreePlan, hasBenefits} from '../../utils/helpers';
|
||||||
|
|
||||||
export const PlanSectionStyles = `
|
export const PlanSectionStyles = `
|
||||||
.gh-portal-plans-container {
|
.gh-portal-plans-container {
|
||||||
|
@ -433,6 +433,7 @@ function PlanOptions({plans, selectedPlan, onPlanSelect, changePlan}) {
|
||||||
const {site} = useContext(AppContext);
|
const {site} = useContext(AppContext);
|
||||||
const {free_price_name: freePriceName, free_price_description: freePriceDescription} = site;
|
const {free_price_name: freePriceName, free_price_description: freePriceDescription} = site;
|
||||||
addDiscountToPlans(plans);
|
addDiscountToPlans(plans);
|
||||||
|
const _hasBenefits = hasBenefits({prices: plans});
|
||||||
return plans.map(({name, currency_symbol: currencySymbol, amount, description, interval, id}) => {
|
return plans.map(({name, currency_symbol: currencySymbol, amount, description, interval, id}) => {
|
||||||
const price = amount / 100;
|
const price = amount / 100;
|
||||||
const isChecked = selectedPlan === id;
|
const isChecked = selectedPlan === id;
|
||||||
|
@ -458,9 +459,7 @@ function PlanOptions({plans, selectedPlan, onPlanSelect, changePlan}) {
|
||||||
<h4 className={planNameClass}>{displayName}</h4>
|
<h4 className={planNameClass}>{displayName}</h4>
|
||||||
<PriceLabel currencySymbol={currencySymbol} price={price} interval={interval} />
|
<PriceLabel currencySymbol={currencySymbol} price={price} interval={interval} />
|
||||||
<div className='gh-portal-plan-featurewrapper'>
|
<div className='gh-portal-plan-featurewrapper'>
|
||||||
<div className='gh-portal-plan-feature'>
|
<PlanFeature feature={planDetails.feature} hide={_hasBenefits} />
|
||||||
{planDetails.feature}
|
|
||||||
</div>
|
|
||||||
{(changePlan && selectedPlan === id ? <span className='gh-portal-plan-current'>Current plan</span> : '')}
|
{(changePlan && selectedPlan === id ? <span className='gh-portal-plan-current'>Current plan</span> : '')}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -468,6 +467,17 @@ function PlanOptions({plans, selectedPlan, onPlanSelect, changePlan}) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function PlanFeature({feature, hide}) {
|
||||||
|
if (hide) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div className='gh-portal-plan-feature'>
|
||||||
|
{feature}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function PlanBenefit({benefit}) {
|
function PlanBenefit({benefit}) {
|
||||||
if (!benefit?.name) {
|
if (!benefit?.name) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -211,6 +211,15 @@ export function getAvailableProducts({site}) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function hasBenefits({prices}) {
|
||||||
|
if (!prices?.length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return prices.some((price) => {
|
||||||
|
return price?.benefits?.length;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function getSiteProducts({site}) {
|
export function getSiteProducts({site}) {
|
||||||
const products = getAvailableProducts({site});
|
const products = getAvailableProducts({site});
|
||||||
if (hasFreeProductPrice({site}) && products.length > 0) {
|
if (hasFreeProductPrice({site}) && products.length > 0) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue