0
Fork 0
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:
Rishabh 2021-06-28 18:43:12 +05:30
parent d43998eb47
commit 5d4e5aa4c8
2 changed files with 23 additions and 4 deletions

View file

@ -1,7 +1,7 @@
import React, {useContext} from 'react';
import AppContext from '../../AppContext';
import calculateDiscount from '../../utils/discount';
import {isCookiesDisabled, formatNumber, hasOnlyFreePlan} from '../../utils/helpers';
import {isCookiesDisabled, formatNumber, hasOnlyFreePlan, hasBenefits} from '../../utils/helpers';
export const PlanSectionStyles = `
.gh-portal-plans-container {
@ -433,6 +433,7 @@ function PlanOptions({plans, selectedPlan, onPlanSelect, changePlan}) {
const {site} = useContext(AppContext);
const {free_price_name: freePriceName, free_price_description: freePriceDescription} = site;
addDiscountToPlans(plans);
const _hasBenefits = hasBenefits({prices: plans});
return plans.map(({name, currency_symbol: currencySymbol, amount, description, interval, id}) => {
const price = amount / 100;
const isChecked = selectedPlan === id;
@ -458,9 +459,7 @@ function PlanOptions({plans, selectedPlan, onPlanSelect, changePlan}) {
<h4 className={planNameClass}>{displayName}</h4>
<PriceLabel currencySymbol={currencySymbol} price={price} interval={interval} />
<div className='gh-portal-plan-featurewrapper'>
<div className='gh-portal-plan-feature'>
{planDetails.feature}
</div>
<PlanFeature feature={planDetails.feature} hide={_hasBenefits} />
{(changePlan && selectedPlan === id ? <span className='gh-portal-plan-current'>Current plan</span> : '')}
</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}) {
if (!benefit?.name) {
return null;

View file

@ -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}) {
const products = getAvailableProducts({site});
if (hasFreeProductPrice({site}) && products.length > 0) {