-
Notifications
You must be signed in to change notification settings - Fork 219
feat(payments-next): Cancellation flow: Create page - Interstitial Offer #19859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
elizabeth-ilina
wants to merge
1
commit into
main
Choose a base branch
from
PAY-3371-create-page-interstitial-offer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+533
−23
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
apps/payments/next/app/[locale]/subscriptions/[subscriptionId]/offer/en.ftl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
9 changes: 9 additions & 0 deletions
9
apps/payments/next/app/[locale]/subscriptions/[subscriptionId]/offer/error/en.ftl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
146 changes: 146 additions & 0 deletions
146
apps/payments/next/app/[locale]/subscriptions/[subscriptionId]/offer/error/page.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| ); | ||
| } |
149 changes: 149 additions & 0 deletions
149
apps/payments/next/app/[locale]/subscriptions/[subscriptionId]/offer/page.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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`); | ||
| } | ||
|
|
||
| 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> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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