Skip to content
Merged
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
Expand Up @@ -5,7 +5,7 @@
import { headers } from 'next/headers';
import Image from 'next/image';
import Link from 'next/link';
import { notFound, redirect } from 'next/navigation';
import { redirect } from 'next/navigation';

import { SubscriptionParams } from '@fxa/payments/ui';
import { determineChurnCancelEligibilityAction } from '@fxa/payments/ui/actions';
Expand Down Expand Up @@ -45,14 +45,27 @@ export default async function LoyaltyDiscountCancelErrorPage({

const uid = session.user.id;

const pageContent = await determineChurnCancelEligibilityAction(
uid,
subscriptionId,
acceptLanguage
);
let pageContent;
try {
pageContent = await determineChurnCancelEligibilityAction(
uid,
subscriptionId,
acceptLanguage
);
} catch (error) {
pageContent = null;
}

if (!pageContent) {
notFound();
return (
<ChurnError
cmsOfferingContent={undefined}
locale={locale}
reason="general_error"
pageContent={{ flowType: 'not_found' }}
subscriptionId={subscriptionId}
/>
);
}

const { churnCancelContentEligibility } = pageContent;
Expand All @@ -63,18 +76,15 @@ export default async function LoyaltyDiscountCancelErrorPage({
}

const { cmsOfferingContent, reason } = churnCancelContentEligibility;
if (!cmsOfferingContent) {
notFound();
}

const cancelContent = pageContent.cancelContent;

if (cancelContent.flowType !== 'cancel') {
if (cancelContent.flowType !== 'cancel' || !cmsOfferingContent) {
return (
<ChurnError
cmsOfferingContent={cmsOfferingContent}
locale={locale}
reason={reason}
reason={reason ?? 'general_error'}
pageContent={cancelContent}
subscriptionId={subscriptionId}
/>
Expand Down Expand Up @@ -203,7 +213,7 @@ export default async function LoyaltyDiscountCancelErrorPage({
<ChurnError
cmsOfferingContent={cmsOfferingContent}
locale={locale}
reason={reason}
reason={reason ?? 'general_error'}
pageContent={cancelContent}
subscriptionId={subscriptionId}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { headers } from 'next/headers';
import { notFound, redirect } from 'next/navigation';
import { redirect } from 'next/navigation';

import { ChurnCancel, SubscriptionParams } from '@fxa/payments/ui';
import { determineChurnCancelEligibilityAction } from '@fxa/payments/ui/actions';
Expand Down Expand Up @@ -40,13 +40,24 @@ export default async function LoyaltyDiscountCancelPage({

const uid = session.user.id;

const pageContent = await determineChurnCancelEligibilityAction(
uid,
subscriptionId,
acceptLanguage
);
let pageContent;
try {
pageContent = await determineChurnCancelEligibilityAction(
uid,
subscriptionId,
acceptLanguage
);
} catch (error) {
redirect(
`/${locale}/subscriptions/${subscriptionId}/loyalty-discount/cancel/error`
);
}

if (!pageContent) notFound();
if (!pageContent) {
redirect(
`/${locale}/subscriptions/${subscriptionId}/loyalty-discount/cancel/error`
);
}

const { churnCancelContentEligibility, cancelContent } = pageContent;
const { cmsOfferingContent, reason, cmsChurnInterventionEntry } =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { headers } from 'next/headers';
import { notFound, redirect } from 'next/navigation';
import { redirect } from 'next/navigation';

import { SubscriptionParams } from '@fxa/payments/ui';
import { determineStaySubscribedEligibilityAction } from '@fxa/payments/ui/actions';
Expand Down Expand Up @@ -41,14 +41,27 @@ export default async function LoyaltyDiscountStaySubscribedErrorPage({

const uid = session.user.id;

const pageContent = await determineStaySubscribedEligibilityAction(
uid,
subscriptionId,
acceptLanguage
);
let pageContent;
try {
pageContent = await determineStaySubscribedEligibilityAction(
uid,
subscriptionId,
acceptLanguage
);
} catch (error) {
pageContent = null;
}

if (!pageContent) {
notFound();
return (
<ChurnError
cmsOfferingContent={undefined}
locale={locale}
reason="general_error"
pageContent={{ flowType: 'not_found' }}
subscriptionId={subscriptionId}
/>
);
}

const { churnStaySubscribedEligibility } = pageContent;
Expand All @@ -59,15 +72,12 @@ export default async function LoyaltyDiscountStaySubscribedErrorPage({
}

const { cmsOfferingContent, reason } = churnStaySubscribedEligibility;
if (!cmsOfferingContent) {
notFound();
}

return (
<ChurnError
cmsOfferingContent={cmsOfferingContent}
locale={locale}
reason={reason}
reason={reason ?? 'general_error'}
pageContent={pageContent.staySubscribedContent}
subscriptionId={subscriptionId}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,24 @@ export default async function LoyaltyDiscountStaySubscribedPage({

const uid = session.user.id;

const pageContent = await determineStaySubscribedEligibilityAction(
uid,
subscriptionId,
acceptLanguage
);
let pageContent;
try {
pageContent = await determineStaySubscribedEligibilityAction(
uid,
subscriptionId,
acceptLanguage
);
} catch (error) {
redirect(
`/${locale}/subscriptions/${subscriptionId}/loyalty-discount/stay-subscribed/error`
);
}

if (!pageContent) notFound();
if (!pageContent) {
redirect(
`/${locale}/subscriptions/${subscriptionId}/loyalty-discount/stay-subscribed/error`
);
}

const { churnStaySubscribedEligibility, staySubscribedContent } = pageContent;
const { cmsOfferingContent, reason, cmsChurnInterventionEntry } =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
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-customer-mismatch-heading = This subscription is not associated with your account
interstitial-offer-error-customer-mismatch-message = Make sure you are signed in with the correct account, or contact Support if you need help.

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
interstitial-offer-error-button-sign-in = Sign in
interstitial-offer-error-button-contact-support = Contact Support
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { headers } from 'next/headers';
import { notFound, redirect } from 'next/navigation';
import { 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 { LinkExternal } from '@fxa/shared/react';
import { auth } from 'apps/payments/next/auth';
import { config } from 'apps/payments/next/config';

Expand Down Expand Up @@ -44,31 +45,34 @@ export default async function InterstitialOfferErrorPage({
const uid = session.user.id;

let interstitialOfferContent;
let reason = 'general_error';
try {
interstitialOfferContent = await getInterstitialOfferContentAction(
uid,
subscriptionId,
acceptLanguage,
locale
);
reason = interstitialOfferContent?.reason ?? 'general_error';
} catch (error) {
notFound();
interstitialOfferContent = null;
reason = 'general_error';
}

if (!interstitialOfferContent) {
notFound();
}

if (interstitialOfferContent.isEligible && interstitialOfferContent.pageContent) {
redirect(`/${locale}/subscriptions/${subscriptionId}/offer`);
}
const webIcon = interstitialOfferContent?.webIcon;
const productName = interstitialOfferContent?.productName;

const { webIcon, productName } = interstitialOfferContent;
const reason = interstitialOfferContent.reason ?? 'general_error';
if (webIcon && !productName) {
console.error('Missing productName for interstitial offer icon');
reason = 'general_error';
}

if (webIcon && !productName) {
throw new Error('Missing productName for interstitial offer icon');
}
if (
interstitialOfferContent?.isEligible &&
interstitialOfferContent?.pageContent
) {
redirect(`/${locale}/subscriptions/${subscriptionId}/offer`);
}

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

Expand All @@ -85,7 +89,40 @@ export default async function InterstitialOfferErrorPage({
'interstitial-offer-error-subscription-not-found-message',
'It looks like this subscription may no longer be active.'
),
showContinueToCancelButton: false,
primaryButton: {
label: l10n.getString(
'interstitial-offer-error-button-back-to-subscriptions',
'Back to subscriptions'
),
href: `/${locale}/subscriptions/landing`,
},
secondaryButton: null,
};
case 'customer_mismatch':
return {
heading: l10n.getString(
'interstitial-offer-error-customer-mismatch-heading',
'This subscription is not associated with your account'
),
message: l10n.getString(
'interstitial-offer-error-customer-mismatch-message',
'Make sure you are signed in with the correct account, or contact Support if you need help.'
),
primaryButton: {
label: l10n.getString(
'interstitial-offer-error-button-sign-in',
'Sign in'
),
href: `/${locale}/subscriptions/landing`,
},
secondaryButton: {
label: l10n.getString(
'interstitial-offer-error-button-contact-support',
'Contact Support'
),
href: 'https://support.mozilla.org/',
isExternal: true,
},
};
default:
return {
Expand All @@ -97,12 +134,26 @@ export default async function InterstitialOfferErrorPage({
'interstitial-offer-error-general-message',
'It looks like this offer is not available at this time.'
),
showContinueToCancelButton: true,
primaryButton: {
label: l10n.getString(
'interstitial-offer-error-button-back-to-subscriptions',
'Back to subscriptions'
),
href: `/${locale}/subscriptions/landing`,
},
secondaryButton: {
label: l10n.getString(
'interstitial-offer-error-button-cancel-subscription',
'Continue to cancel'
),
href: `/${locale}/subscriptions/${subscriptionId}/cancel`,
isExternal: false,
},
};
}
};

const { heading, message, showContinueToCancelButton } = getErrorContent(reason);
const { heading, message, primaryButton, secondaryButton } = getErrorContent(reason);

return (
<section
Expand Down Expand Up @@ -132,23 +183,26 @@ export default async function InterstitialOfferErrorPage({
<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`}
href={primaryButton.href}
>
{l10n.getString(
'interstitial-offer-error-button-back-to-subscriptions',
'Back to subscriptions'
)}
{primaryButton.label}
</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>
{secondaryButton && (
secondaryButton.isExternal ? (
<LinkExternal
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={secondaryButton.href}
>
{secondaryButton.label}
</LinkExternal>
) : (
<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={secondaryButton.href}
>
<span>{secondaryButton.label}</span>
</Link>
)
)}
</div>
</div>
Expand Down
Loading