Skip to content

Commit

Permalink
feat: add regionalised benefits and Aus partner offer
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewHEguardian committed Jul 18, 2024
1 parent 00d654a commit 186ffc1
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 8 deletions.
1 change: 1 addition & 0 deletions client/components/mma/accountoverview/ProductCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ export const ProductCard = ({
</p>
<BenefitsToggle
productType={specificProductType.productType}
subscriptionPlan={mainPlan}
/>
</Card.Section>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ import {
getNewMembershipPrice,
getOldMembershipPrice,
} from '../../../../../utilities/pricingConfig/membershipPriceRise';
import { benefitsConfiguration } from '../../../shared/benefits/BenefitsConfiguration';
import {
benefitsConfiguration,
filterBenefitByRegion,
} from '../../../shared/benefits/BenefitsConfiguration';
import { BenefitsSection } from '../../../shared/benefits/BenefitsSection';
import { Card } from '../../../shared/Card';
import { Heading } from '../../../shared/Heading';
Expand Down Expand Up @@ -148,7 +151,14 @@ export const SaveOptions = () => {
</Card.Header>
<Card.Section>
<BenefitsSection
benefits={benefitsConfiguration['membership']}
benefits={benefitsConfiguration[
'membership'
].filter((benefit) =>
filterBenefitByRegion(
benefit,
mainPlan.currencyISO,
),
)}
/>
<section css={[cardSectionCss, buttonContainerCss]}>
<Button
Expand Down Expand Up @@ -189,7 +199,14 @@ export const SaveOptions = () => {
</Card.Header>
<Card.Section>
<BenefitsSection
benefits={benefitsConfiguration['contributions']}
benefits={benefitsConfiguration[
'contributions'
].filter((benefit) =>
filterBenefitByRegion(
benefit,
mainPlan.currencyISO,
),
)}
/>
<section css={[cardSectionCss, buttonContainerCss]}>
<Button
Expand Down
40 changes: 39 additions & 1 deletion client/components/mma/shared/benefits/BenefitsConfiguration.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {
type CurrencyIso,
isCurrencyIso,
} from '@/client/utilities/currencyIso';
import type { ProductTypeKeys } from '@/shared/productTypes';

/* Product Switch Benefits, these are also shown on product cards */
Expand Down Expand Up @@ -27,10 +31,37 @@ const guardianWeekly = {
description: 'Print magazine delivered to your door every week',
};

const partnerOffers: ProductBenefit = {
name: 'Exclusive access',
description: ' to partner offers',
specificToRegions: ['AUD'],
};

export interface ProductBenefit {
name?: string;
description?: string;
isUnavailable?: boolean;
specificToRegions?: CurrencyIso[];
}

export function filterBenefitByRegion(
benefit: {
specificToRegions?: CurrencyIso[];
},
currencyIso: string,
) {
if (isCurrencyIso(currencyIso)) {
if (benefit.specificToRegions !== undefined) {
return benefit.specificToRegions.includes(currencyIso);
}

return true;
}

/* If we don't have a valid currency
only show a benefit which is not region specific
*/
return benefit.specificToRegions === undefined;
}

export const supporterPlusSwitchBenefits = [newsApp, adFree];
Expand All @@ -46,13 +77,20 @@ export const benefitsConfiguration: {
isUnavailable: true,
},
],
supporterplus: [supporterNewsletter, uninterruptedReading, newsApp, adFree],
supporterplus: [
supporterNewsletter,
uninterruptedReading,
newsApp,
adFree,
partnerOffers,
],
tierthree: [
guardianWeekly,
supporterNewsletter,
uninterruptedReading,
newsApp,
adFree,
partnerOffers,
],
membership: [newsApp, uninterruptedReading, supporterNewsletter],
digipack: [],
Expand Down
25 changes: 22 additions & 3 deletions client/components/mma/shared/benefits/BenefitsToggle.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
import { css } from '@emotion/react';
import { space } from '@guardian/source/foundations';
import { useState } from 'react';
import type { SubscriptionPlan } from '@/shared/productResponse';
import { isPaidSubscriptionPlan } from '@/shared/productResponse';
import type { ProductTypeKeys } from '../../../../../shared/productTypes';
import { expanderButtonCss } from '../../../shared/ExpanderButton';
import { benefitsConfiguration } from './BenefitsConfiguration';
import {
benefitsConfiguration,
filterBenefitByRegion,
} from './BenefitsConfiguration';
import { BenefitsSection } from './BenefitsSection';
import { benefitsButtonCss } from './BenefitsStyles';

export const BenefitsToggle = (props: { productType: ProductTypeKeys }) => {
type BenfitsToggleProps = {
productType: ProductTypeKeys;
subscriptionPlan: SubscriptionPlan;
};

export const BenefitsToggle = ({
productType,
subscriptionPlan,
}: BenfitsToggleProps) => {
const currencyIso = isPaidSubscriptionPlan(subscriptionPlan)
? subscriptionPlan.currencyISO
: '';

const [showBenefits, setShowBenefits] = useState<boolean>(false);
const benefits = benefitsConfiguration[props.productType];
const benefits = benefitsConfiguration[productType].filter((benefit) =>
filterBenefitByRegion(benefit, currencyIso),
);

return (
<>
Expand Down
5 changes: 4 additions & 1 deletion client/components/mma/switch/review/SwitchReview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,10 @@ export const SwitchReview = () => {
including full access to our app and ad-free
reading
</p>
<BenefitsToggle productType="supporterplus" />
<BenefitsToggle
productType="supporterplus"
subscriptionPlan={mainPlan}
/>
<p css={newAmountCss}>
{mainPlan.currency}
{formatAmount(newAmount)}/
Expand Down

0 comments on commit 186ffc1

Please sign in to comment.