From 006b3adc3bdc4334891edb32d37824420df08d96 Mon Sep 17 00:00:00 2001 From: Djordje Vlaisavljevic Date: Fri, 19 Aug 2022 14:20:50 +0200 Subject: [PATCH] Updated how discounts appear when there are no tiers with trial refs https://github.com/TryGhost/Team/issues/1724 --- .../src/components/common/ProductsSection.js | 40 +++++++++++++------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/ghost/portal/src/components/common/ProductsSection.js b/ghost/portal/src/components/common/ProductsSection.js index 0836abedf5..f677a3837e 100644 --- a/ghost/portal/src/components/common/ProductsSection.js +++ b/ghost/portal/src/components/common/ProductsSection.js @@ -1,7 +1,7 @@ import React, {useContext, useEffect, useState} from 'react'; import {ReactComponent as LoaderIcon} from '../../images/icons/loader.svg'; import {ReactComponent as CheckmarkIcon} from '../../images/icons/checkmark.svg'; -import {getCurrencySymbol, getPriceString, getStripeAmount, getMemberActivePrice, getProductFromPrice, getFreeTierTitle, getFreeTierDescription, getFreeProduct, getFreeProductBenefits, formatNumber, isCookiesDisabled, hasOnlyFreeProduct, isMemberActivePrice} from '../../utils/helpers'; +import {getCurrencySymbol, getPriceString, getStripeAmount, getMemberActivePrice, getProductFromPrice, getFreeTierTitle, getFreeTierDescription, getFreeProduct, getFreeProductBenefits, formatNumber, isCookiesDisabled, hasOnlyFreeProduct, isMemberActivePrice, hasFreeTrialTier} from '../../utils/helpers'; import AppContext from '../../AppContext'; import calculateDiscount from '../../utils/discount'; @@ -565,13 +565,25 @@ function ProductCardAlternatePrice({price}) { ); } -function ProductCardTrialDays({trialDays}) { - if (trialDays) { - return ( - {trialDays} days free - ); +function ProductCardTrialDays({trialDays, discount}) { + const {site} = useContext(AppContext); + const {selectedInterval} = useContext(ProductsContext); + if (hasFreeTrialTier({site})) { + if (trialDays) { + return ( + {trialDays} days free + ); + } else { + return null; + } } + if (selectedInterval === 'year') { + return ( + {discount}% discount + ); + } + return null; } @@ -599,7 +611,7 @@ function ProductCardPrice({product}) { {formatNumber(getStripeAmount(activePrice.amount))} /{activePrice.interval} - + {(selectedInterval === 'year' ? : '')} @@ -828,11 +840,15 @@ function YearlyDiscount({discount, trialDays}) { } if (freeTrialFlag) { - return ( - <> - {discount}% discount - - ); + if (hasFreeTrialTier({site})) { + return ( + <> + {discount}% discount + + ); + } else { + return null; + } } return (