🐛 Removed expired offers shown in portal account detail

closes https://github.com/TryGhost/Team/issues/2376#event-8026429598

- if an offer is expired/in past, we no longer show it in member account info against the price
- one-time offers are never showed in portal in member account detail, as the payment information shown to member in Portal points to charge at next payment
- if trial days are over for a subscription, portal doesn't show any offer data on member account detail
This commit is contained in:
Rishabh 2022-12-14 15:25:58 +05:30
parent 237d4d53d4
commit aa693039a3
3 changed files with 24 additions and 3 deletions

View File

@ -27,7 +27,10 @@ test.describe('Portal', () => {
await page.goto(portalUrl);
const portalFrame = page.frameLocator('#ghost-portal-root div iframe');
const portalTriggerButton = page.frameLocator('#ghost-portal-root iframe.gh-portal-triggerbtn-iframe').locator('div').nth(1);
await expect(portalFrame.locator('.gh-portal-offer-title'), 'URL should open Portal with free-trial offer').toBeVisible();
await expect(portalFrame.getByRole('heading', {name: offerName}), 'URL should open Portal with free-trial offer').toBeVisible();
await portalFrame.locator('#input-name').fill('Testy McTesterson');
await portalFrame.locator('#input-email').fill('testy@example.com');
await portalFrame.getByRole('button', {name: 'Start 14-day free trial'}).click();
@ -38,6 +41,9 @@ test.describe('Portal', () => {
await completeStripeSubscription(page);
await page.waitForSelector('h1.site-title', {state: 'visible'});
await portalTriggerButton.click();
await expect(portalFrame.locator('text=Free Trial Ends'), 'Portal should show free trial info').toBeVisible();
await page.goto('/ghost');
await page.locator('.gh-nav a[href="#/members/"]').click();
@ -74,6 +80,7 @@ test.describe('Portal', () => {
await page.goto(portalUrl);
const portalFrame = page.frameLocator('#ghost-portal-root div iframe');
const portalTriggerButton = page.frameLocator('#ghost-portal-root iframe.gh-portal-triggerbtn-iframe').locator('div').nth(1);
await expect(portalFrame.locator('.gh-portal-offer-title'), 'URL should open Portal with discount offer').toBeVisible();
await portalFrame.locator('#input-name').fill('Testy McTesterson');
await portalFrame.locator('#input-email').fill('testy@example.com');
@ -85,6 +92,8 @@ test.describe('Portal', () => {
await completeStripeSubscription(page);
await page.waitForSelector('h1.site-title', {state: 'visible'});
await portalTriggerButton.click();
await expect(portalFrame.locator('text=$5.40/month'), 'Portal should show discounted price').toBeVisible();
await page.goto('/ghost');
await page.locator('.gh-nav a[href="#/members/"]').click();

View File

@ -1,5 +1,5 @@
import AppContext from 'AppContext';
import {allowCompMemberUpgrade, getCompExpiry, getMemberSubscription, getMemberTierName, getUpdatedOfferPrice, hasMultipleProductsFeature, hasOnlyFreePlan, isComplimentaryMember, subscriptionHasFreeTrial} from 'utils/helpers';
import {allowCompMemberUpgrade, getCompExpiry, getMemberSubscription, getMemberTierName, getUpdatedOfferPrice, hasMultipleProductsFeature, hasOnlyFreePlan, isComplimentaryMember, isInThePast, 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';
@ -187,7 +187,15 @@ function FreeTrialLabel({subscription, priceLabel}) {
function getOfferLabel({offer, price, subscriptionStartDate}) {
let offerLabel = '';
if (offer && offer?.duration !== 'once') {
if (offer?.type === 'trial') {
return '';
}
if (offer?.duration === 'once') {
return '';
}
if (offer) {
const discountDuration = offer.duration;
let durationLabel = '';
if (discountDuration === 'forever') {
@ -196,6 +204,10 @@ function getOfferLabel({offer, price, subscriptionStartDate}) {
const durationInMonths = offer.duration_in_months || 0;
let offerStartDate = new Date(subscriptionStartDate);
let offerEndDate = new Date(offerStartDate.setMonth(offerStartDate.getMonth() + durationInMonths));
// don't show expired offers if the offer is not forever
if (isInThePast(offerEndDate)) {
return '';
}
durationLabel = `Ends ${getDateString(offerEndDate)}`;
}
offerLabel = `${getUpdatedOfferPrice({offer, price, useFormatted: true})}/${price.interval}${durationLabel ? `${durationLabel}` : ``}`;

View File

@ -523,7 +523,7 @@ export function subscriptionHasFreeTrial({sub} = {}) {
return false;
}
function isInThePast(date) {
export function isInThePast(date) {
const today = new Date();
// 👇️ OPTIONAL!