0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Updated how discounts appear when there are no tiers with trial

refs https://github.com/TryGhost/Team/issues/1724
This commit is contained in:
Djordje Vlaisavljevic 2022-08-19 14:20:50 +02:00
parent 4671975156
commit 006b3adc3b

View file

@ -1,7 +1,7 @@
import React, {useContext, useEffect, useState} from 'react'; import React, {useContext, useEffect, useState} from 'react';
import {ReactComponent as LoaderIcon} from '../../images/icons/loader.svg'; import {ReactComponent as LoaderIcon} from '../../images/icons/loader.svg';
import {ReactComponent as CheckmarkIcon} from '../../images/icons/checkmark.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 AppContext from '../../AppContext';
import calculateDiscount from '../../utils/discount'; import calculateDiscount from '../../utils/discount';
@ -565,11 +565,23 @@ function ProductCardAlternatePrice({price}) {
); );
} }
function ProductCardTrialDays({trialDays}) { function ProductCardTrialDays({trialDays, discount}) {
const {site} = useContext(AppContext);
const {selectedInterval} = useContext(ProductsContext);
if (hasFreeTrialTier({site})) {
if (trialDays) { if (trialDays) {
return ( return (
<span className="gh-portal-discount-label">{trialDays} days free</span> <span className="gh-portal-discount-label">{trialDays} days free</span>
); );
} else {
return null;
}
}
if (selectedInterval === 'year') {
return (
<span className="gh-portal-discount-label">{discount}% discount</span>
);
} }
return null; return null;
@ -599,7 +611,7 @@ function ProductCardPrice({product}) {
<span className="amount">{formatNumber(getStripeAmount(activePrice.amount))}</span> <span className="amount">{formatNumber(getStripeAmount(activePrice.amount))}</span>
<span className="billing-period">/{activePrice.interval}</span> <span className="billing-period">/{activePrice.interval}</span>
</div> </div>
<ProductCardTrialDays trialDays={trialDays} /> <ProductCardTrialDays trialDays={trialDays} discount={yearlyDiscount} />
</div> </div>
{(selectedInterval === 'year' ? <YearlyDiscount discount={yearlyDiscount} trialDays={trialDays} /> : '')} {(selectedInterval === 'year' ? <YearlyDiscount discount={yearlyDiscount} trialDays={trialDays} /> : '')}
<ProductCardAlternatePrice price={alternatePrice} /> <ProductCardAlternatePrice price={alternatePrice} />
@ -828,11 +840,15 @@ function YearlyDiscount({discount, trialDays}) {
} }
if (freeTrialFlag) { if (freeTrialFlag) {
if (hasFreeTrialTier({site})) {
return ( return (
<> <>
<span className="gh-portal-discount-label-trial">{discount}% discount</span> <span className="gh-portal-discount-label-trial">{discount}% discount</span>
</> </>
); );
} else {
return null;
}
} }
return ( return (