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

Wired expiry values for complimentary subscriptions

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

- adds expiry date for comp subs with expiry value
This commit is contained in:
Rishabh 2022-08-19 20:05:10 +05:30 committed by Rishabh Garg
parent aa1c90f60b
commit d6aae23e86
2 changed files with 25 additions and 2 deletions

View file

@ -3,7 +3,7 @@ import MemberAvatar from '../common/MemberGravatar';
import ActionButton from '../common/ActionButton';
import CloseButton from '../common/CloseButton';
import Switch from '../common/Switch';
import {allowCompMemberUpgrade, getMemberSubscription, getMemberTierName, getSiteNewsletters, getSupportAddress, getUpdatedOfferPrice, hasCommentsEnabled, hasMultipleNewsletters, hasMultipleProductsFeature, hasOnlyFreePlan, isComplimentaryMember, subscriptionHasFreeTrial} from '../../utils/helpers';
import {allowCompMemberUpgrade, getCompExpiry, getMemberSubscription, getMemberTierName, getSiteNewsletters, getSupportAddress, getUpdatedOfferPrice, hasCommentsEnabled, hasMultipleNewsletters, hasMultipleProductsFeature, hasOnlyFreePlan, isComplimentaryMember, subscriptionHasFreeTrial} from '../../utils/helpers';
import {getDateString} from '../../utils/date-time';
import {ReactComponent as LoaderIcon} from '../../images/icons/loader.svg';
import {ReactComponent as OfferTagIcon} from '../../images/icons/offer-tag.svg';
@ -230,8 +230,13 @@ const PaidAccountActions = () => {
label = `${Intl.NumberFormat('en', {currency, style: 'currency'}).format(amount / 100)}/${interval}`;
}
let offerLabelStr = getOfferLabel({price, offer, subscriptionStartDate: startDate});
const compExpiry = getCompExpiry({member});
if (isComplimentary) {
label = label ? `Complimentary (${label})` : `Complimentary`;
if (compExpiry) {
label = `Complimentary - Expires ${compExpiry}`;
} else {
label = label ? `Complimentary (${label})` : `Complimentary`;
}
}
let oldPriceClassName = '';
if (offerLabelStr) {
@ -475,6 +480,15 @@ const AccountWelcome = () => {
}
if (subscription) {
const currentPeriodEnd = subscription?.current_period_end;
if (isComplimentary && getCompExpiry({member})) {
const expiryDate = getCompExpiry({member});
const expiryAt = getDateString(expiryDate);
return (
<div className='gh-portal-section'>
<p className='gh-portal-text-center gh-portal-free-ctatext'>Your subscription will expire on {expiryAt}</p>
</div>
);
}
if (subscription?.cancel_at_period_end) {
return null;
}

View file

@ -1,3 +1,5 @@
import {getDateString} from './date-time';
export function removePortalLinkFromUrl() {
const [path] = window.location.hash.substr(1).split('?');
const linkRegex = /^\/portal\/?(?:\/(\w+(?:\/\w+)*))?\/?$/;
@ -88,6 +90,13 @@ export function allowCompMemberUpgrade({member}) {
return member?.subscriptions?.[0]?.tier?.expiry_at !== undefined;
}
export function getCompExpiry({member}) {
if (member?.subscriptions?.[0]?.tier?.expiry_at) {
return getDateString(member.subscriptions[0].tier.expiry_at);
}
return '';
}
export function getUpgradeProducts({site, member}) {
const activePrice = getMemberActivePrice({member});
const activePriceCurrency = activePrice?.currency;