Skip to content

Commit

Permalink
using discaount api response to return the next payment price in the …
Browse files Browse the repository at this point in the history
…cancellation offer journey
  • Loading branch information
Richard Bangay committed Sep 6, 2024
1 parent 46b29cc commit 581ef98
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
6 changes: 6 additions & 0 deletions client/components/mma/cancel/Cancellation.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const Offer: StoryObj<typeof CancellationContainer> = {
upToPeriodsType: 'months',
firstDiscountedPaymentDate: '2024-05-30',
nextNonDiscountedPaymentDate: '2024-07-30',
nonDiscountedPayments: [{ date: '2024-07-30', amount: 14.99 }],
},
},
},
Expand All @@ -116,6 +117,7 @@ export const OfferReview: StoryObj<typeof CancellationContainer> = {
upToPeriodsType: 'months',
firstDiscountedPaymentDate: '2024-05-30',
nextNonDiscountedPaymentDate: '2024-07-30',
nonDiscountedPayments: [{ date: '2024-07-30', amount: 14.99 }],
},
},
msw: [
Expand All @@ -136,6 +138,7 @@ export const OfferConfirmed: StoryObj<typeof CancellationContainer> = {
reactRouter: {
state: {
nextNonDiscountedPaymentDate: '2024-07-30',
nonDiscountedPayments: [{ date: '2024-07-30', amount: 14.99 }],
},
},
},
Expand All @@ -156,6 +159,9 @@ export const SupportplusCancelConfirm: StoryObj<typeof CancellationContainer> =
upToPeriodsType: 'months',
firstDiscountedPaymentDate: '2024-05-30',
nextNonDiscountedPaymentDate: '2024-07-30',
nonDiscountedPayments: [
{ date: '2024-07-30', amount: 14.99 },
],
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ export const SupporterPlusOffer = () => {
'yyyy-MM-dd',
).dateStr(DATE_FNS_LONG_OUTPUT_FORMAT);

const strikethroughPrice = routerState.nonDiscountedPayments.reduce(
(prev, current) =>
prev && prev.amount > current.amount ? prev : current,
).amount;

return (
<>
<ProgressStepper
Expand Down Expand Up @@ -220,7 +225,7 @@ export const SupporterPlusOffer = () => {
<p css={strikethroughPriceCss}>
<s>
{mainPlan.currency}
{mainPlan.price / 100}/{mainPlan.billingPeriod}
{strikethroughPrice}/{mainPlan.billingPeriod}
</s>
</p>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { useLocation, useNavigate } from 'react-router-dom';
import { measure } from '@/client/styles/typography';
import type { DiscountPreviewResponse } from '@/client/utilities/discountPreview';
import { DATE_FNS_LONG_OUTPUT_FORMAT, parseDate } from '@/shared/dates';
import type { PaidSubscriptionPlan } from '@/shared/productResponse';
import { getMainPlan } from '@/shared/productResponse';
import { DownloadAppCta } from '../../../shared/DownloadAppCta';
import { Heading } from '../../../shared/Heading';
import type {
Expand Down Expand Up @@ -170,6 +172,9 @@ export const SupporterPlusOfferConfirmed = () => {
) as CancellationContextInterface;

const productDetail = cancellationContext.productDetail;
const mainPlan = getMainPlan(
productDetail.subscription,
) as PaidSubscriptionPlan;

useEffect(() => {
pageTitleContext.setPageTitle('Confirmation');
Expand All @@ -181,6 +186,11 @@ export const SupporterPlusOfferConfirmed = () => {
'yyyy-MM-dd',
).dateStr(DATE_FNS_LONG_OUTPUT_FORMAT);

const nextNonDiscountedPrice = routerState.nonDiscountedPayments.reduce(
(prev, current) =>
prev && prev.amount > current.amount ? prev : current,
).amount;

return (
<>
<Heading
Expand Down Expand Up @@ -210,7 +220,9 @@ export const SupporterPlusOfferConfirmed = () => {
</li>
<li>
You will not be billed until{' '}
{nextNonDiscountedPaymentDate}
{nextNonDiscountedPaymentDate} after which you will pay{' '}
{mainPlan.currency}
{nextNonDiscountedPrice}/{mainPlan.billingPeriod}
</li>
</ul>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ export const SupporterPlusOfferReview = () => {
'yyyy-MM-dd',
).dateStr(DATE_FNS_LONG_OUTPUT_FORMAT);

const strikethroughPrice = routerState.nonDiscountedPayments.reduce(
(prev, current) =>
prev && prev.amount > current.amount ? prev : current,
).amount;

const [performingDiscountStatus, setPerformingDiscountStatus] =
useState<OfferApiCallStatus>('NOT_READY');

Expand Down Expand Up @@ -194,7 +199,7 @@ export const SupporterPlusOfferReview = () => {
<p css={strikethroughPriceCss}>
<s>
{mainPlan.currency}
{mainPlan.price / 100}/{mainPlan.billingPeriod}
{strikethroughPrice}/{mainPlan.billingPeriod}
</s>
</p>
)}
Expand Down
1 change: 1 addition & 0 deletions client/utilities/discountPreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export type DiscountPreviewResponse = {
upToPeriodsType: string;
firstDiscountedPaymentDate: string;
nextNonDiscountedPaymentDate: string;
nonDiscountedPayments: Array<{ date: string; amount: number }>;
};
1 change: 1 addition & 0 deletions cypress/tests/mocked/parallel-2/cancelSupporterPlus.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ describe('Cancel Supporter Plus', () => {
upToPeriodsType: 'Months',
firstDiscountedPaymentDate: '2024-05-30',
nextNonDiscountedPaymentDate: '2024-07-30',
nonDiscountedPayments: [{ date: '2024-07-30', amount: 14.99 }],
};
it('user accepts offer instead of cancelling', () => {
cy.intercept('GET', '/api/me/mma', {
Expand Down

0 comments on commit 581ef98

Please sign in to comment.