Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## InterstitialOffer
interstitial-offer-button-cancel-subscription = Continue to cancel

## Daily/Weekly/Monthly refers to the user's current subscription interval
interstitial-offer-button-keep-current-interval-daily = Keep daily subscription
interstitial-offer-button-keep-current-interval-weekly = Keep weekly subscription
interstitial-offer-button-keep-current-interval-monthly = Keep monthly subscription
interstitial-offer-button-keep-current-interval-halfyearly = Keep six-month subscription
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Error page
interstitial-offer-error-subscription-not-found-heading = We couldn’t find an active subscription
interstitial-offer-error-subscription-not-found-message = It looks like this subscription may no longer be active.

interstitial-offer-error-general-heading = Offer isn’t available
interstitial-offer-error-general-message = It looks like this offer is not available at this time.

interstitial-offer-error-button-back-to-subscriptions = Back to subscriptions
interstitial-offer-error-button-cancel-subscription = Continue to cancel
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { headers } from 'next/headers';
import { notFound, redirect } from 'next/navigation';
import Link from 'next/link';
import Image from 'next/image';
import { getApp } from '@fxa/payments/ui/server';
import { getInterstitialOfferContentAction } from '@fxa/payments/ui/actions';
import { auth } from 'apps/payments/next/auth';
import { config } from 'apps/payments/next/config';

export default async function InterstitialOfferErrorPage({
params,
searchParams,
}: {
params: {
locale: string;
subscriptionId: string;
};
searchParams: Record<string, string> | undefined;
}) {
const { locale, subscriptionId } = params;

if (!config.churnInterventionConfig.enabled) {
redirect(`/${locale}/subscriptions/landing`);
}

const acceptLanguage = headers().get('accept-language');
const session = await auth();
if (!session?.user?.id) {
const redirectToUrl = new URL(
`${config.paymentsNextHostedUrl}/${locale}/subscriptions/landing`
);
redirectToUrl.search = new URLSearchParams(searchParams).toString();
redirect(redirectToUrl.href);
}

const uid = session.user.id;

const interstitialOfferContent = await getInterstitialOfferContentAction(
uid,
subscriptionId,
acceptLanguage,
locale
);

if (!interstitialOfferContent) {
notFound();
}

if (interstitialOfferContent.isEligible && interstitialOfferContent.pageContent) {
redirect(`/${locale}/subscriptions/${subscriptionId}/offer`);
}

const { webIcon, productName} = interstitialOfferContent;
const reason = interstitialOfferContent.reason ?? 'general_error';

if (webIcon && !productName) {
throw new Error('Missing productName for interstitial offer icon');
}

const l10n = getApp().getL10n(acceptLanguage, locale);

const getErrorContent = (reason: string) => {
switch (reason) {
case 'subscription_not_found':
return {
heading: l10n.getString(
'interstitial-offer-error-subscription-not-found-heading',
'We couldn’t find an active subscription'
),
message: l10n.getString(
'interstitial-offer-error-subscription-not-found-message',
'It looks like this subscription may no longer be active.'
),
};
default:
return {
heading: l10n.getString(
'interstitial-offer-error-general-heading',
'Offer isn’t available'
),
message: l10n.getString(
'interstitial-offer-error-general-message',
'It looks like this offer is not available at this time.'
),
};
}
};

const { heading, message } = getErrorContent(reason);
const showContinueToCancelButton = reason !== 'subscription_not_found';

return (
<section
className="flex justify-center min-h-[calc(100vh_-_4rem)] tablet:items-center tablet:min-h-[calc(100vh_-_5rem)]"
aria-labelledby="error-heading"
>
<div className="w-full max-w-[480px] flex flex-col justify-center items-center p-10 tablet:bg-white tablet:rounded-xl tablet:border tablet:border-grey-200 tablet:shadow-[0_0_16px_0_rgba(0,0,0,0.08)]">
<div className="w-full flex flex-col items-center gap-6 text-center">
{webIcon && (
<Image
src={webIcon}
alt={productName ?? ''}
height={64}
width={64}
/>
)}
<h1
id="error-heading"
className="font-bold self-stretch text-center font-header text-xl leading-8"
>
{heading}
</h1>
<p className="w-full self-stretch leading-7 text-lg text-grey-900 text-center tablet:text-start">
{message}
</p>
</div>
<div className="w-full flex flex-col gap-3 mt-10">
<Link
className="border box-border font-header h-14 items-center justify-center rounded-md text-white text-center font-bold py-4 px-6 bg-blue-500 hover:bg-blue-700 flex w-full"
href={`/${locale}/subscriptions/landing`}
>
{l10n.getString(
'interstitial-offer-error-button-back-to-subscriptions',
'Back to subscriptions'
)}
</Link>
{showContinueToCancelButton && (
<Link
className="border box-border font-header h-14 items-center justify-center rounded-md text-center font-bold py-4 px-6 bg-grey-10 border-grey-200 hover:bg-grey-50 flex w-full"
href={`/${locale}/subscriptions/${subscriptionId}/cancel`}
>
<span>{l10n.getString(
'interstitial-offer-error-button-cancel-subscription',
'Continue to cancel'
)}</span>
</Link>
)}
</div>
</div>
</section>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { headers } from 'next/headers';
import { redirect } from 'next/navigation';
import { getApp } from '@fxa/payments/ui/server';
import { getInterstitialOfferContentAction } from '@fxa/payments/ui/actions';
import { auth } from 'apps/payments/next/auth';
import { config } from 'apps/payments/next/config';
import Image from 'next/image';
import Link from 'next/link';

export default async function InterstitialOfferPage({
params,
searchParams,
}: {
params: {
locale: string;
subscriptionId: string;
};
searchParams: Record<string, string> | undefined;
}) {
const { locale, subscriptionId } = params;

if (!config.churnInterventionConfig.enabled) {
redirect(`/${locale}/subscriptions/landing`);
}

const acceptLanguage = headers().get('accept-language');
const l10n = getApp().getL10n(acceptLanguage, locale);
const session = await auth();
if (!session?.user?.id) {
const redirectToUrl = new URL(
`${config.paymentsNextHostedUrl}/${locale}/subscriptions/landing`
);
redirectToUrl.search = new URLSearchParams(searchParams).toString();
redirect(redirectToUrl.href);
}

const uid = session.user.id;

let interstitialOfferContent;
try {
interstitialOfferContent = await getInterstitialOfferContentAction(
uid,
subscriptionId,
acceptLanguage,
locale
);
} catch (error) {
redirect(`/${locale}/subscriptions/${subscriptionId}/offer/error`);
}

if (!interstitialOfferContent.isEligible || !interstitialOfferContent.pageContent) {
redirect(`/${locale}/subscriptions/${subscriptionId}/offer/error`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/${locale}/subscriptions/${subscriptionId}/offer/error

}

const {
currentInterval,
modalHeading1,
modalMessage,
upgradeButtonLabel,
upgradeButtonUrl,
webIcon,
productName,
} = interstitialOfferContent.pageContent;

const getKeepCurrentSubscriptionFtlIds = (interval: string) => {
switch (interval) {
case 'daily':
return {
ftlId: 'interstitial-offer-button-keep-current-interval-daily',
fallbackText: 'Keep daily subscription',
};
case 'weekly':
return {
ftlId: 'interstitial-offer-button-keep-current-interval-weekly',
fallbackText: 'Keep weekly subscription',
};
case 'halfyearly':
return {
ftlId: 'interstitial-offer-button-keep-current-interval-halfyearly',
fallbackText: 'Keep six-month subscription',
};
case 'monthly':
default:
return {
ftlId: 'interstitial-offer-button-keep-current-interval-monthly',
fallbackText: 'Keep monthly subscription',
};
}
};

const { ftlId, fallbackText } = getKeepCurrentSubscriptionFtlIds(currentInterval);
const keepCurrentSubscriptionButtonText = l10n.getString(ftlId, fallbackText);

return (
<section
className="flex justify-center min-h-[calc(100vh_-_4rem)] tablet:items-center tablet:min-h-[calc(100vh_-_5rem)]"
>
<div className="w-full max-w-[480px] flex flex-col justify-center items-center p-10 tablet:bg-white tablet:rounded-xl tablet:border tablet:border-grey-200 tablet:shadow-[0_0_16px_0_rgba(0,0,0,0.08)]">
<div className="w-full flex flex-col items-center gap-6 text-center">
<Image
src={webIcon}
alt={productName}
height={64}
width={64}
/>
<h1 className="font-bold self-stretch text-center font-header text-xl leading-8 ">
{modalHeading1}
</h1>
</div>
<p className="w-full self-stretch leading-7 text-lg text-grey-900">
{modalMessage &&
modalMessage.map((line, i) => (
<p className="my-2" key={i}>
{line}
</p>
))}
</p>

<div className="w-full flex flex-col gap-3 mt-12">
<Link
className="border box-border font-header h-14 items-center justify-center rounded-md text-white text-center font-bold py-4 px-6 bg-blue-500 hover:bg-blue-700 flex w-full"
href={upgradeButtonUrl}
>
{upgradeButtonLabel}
</Link>
<Link
className="border box-border font-header h-14 items-center justify-center rounded-md text-center font-bold py-4 px-6 bg-grey-10 border-grey-200 hover:bg-grey-50 flex w-full"
href={`/${locale}/subscriptions/landing`}
>
<span>{keepCurrentSubscriptionButtonText}</span>
</Link>
<Link
className="border box-border font-header h-14 items-center justify-center rounded-md text-center font-bold py-4 px-6 bg-grey-10 border-grey-200 hover:bg-grey-50 flex w-full"
href={`/${locale}/subscriptions/${subscriptionId}/cancel`}
>
<span>{l10n.getString(
'interstitial-offer-button-cancel-subscription',
'Continue to cancel'
)}</span>
</Link>
</div>
</div>
</section>
);
}
Loading
Loading