Skip to content

Commit 9431a8e

Browse files
author
Juarez Mota
committed
feat: add support for contributions epic choice cards with custom destination URL
1 parent 70f805d commit 9431a8e

File tree

3 files changed

+41
-17
lines changed

3 files changed

+41
-17
lines changed

dotcom-rendering/src/components/marketing/epics/ContributionsEpic.stories.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import { SecondaryCtaType } from '@guardian/support-dotcom-components';
88
import type { Meta, StoryObj } from '@storybook/react';
99
import lzstring from 'lz-string';
1010
import React from 'react';
11-
import { choiceCardsSettings } from '../lib/storybook';
11+
import {
12+
choiceCardsSettings,
13+
choiceCardsWithDestinationUrl,
14+
} from '../lib/storybook';
1215
import { ContributionsEpicUnvalidated as ContributionsEpic } from './ContributionsEpic';
1316
import { props } from './utils/storybook';
1417

@@ -381,3 +384,17 @@ export const WithParagraphLinks: Story = {
381384
},
382385
},
383386
};
387+
388+
export const WithThreeTierChoiceCardsAndCustomDestinationUrl: Story = {
389+
name: 'ContributionsEpic with three tier choice cards and custom destination URL',
390+
args: {
391+
...meta.args,
392+
variant: {
393+
...props.variant,
394+
name: 'THREE_TIER_CHOICE_CARDS',
395+
secondaryCta: undefined,
396+
showChoiceCards: true,
397+
choiceCardsSettings: choiceCardsWithDestinationUrl,
398+
},
399+
},
400+
};

dotcom-rendering/src/components/marketing/epics/ctas/ContributionsEpicButtons.tsx

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ interface ContributionsEpicButtonsProps {
139139
submitComponentEvent?: (event: ComponentEvent) => void;
140140
isReminderActive: boolean;
141141
isSignedIn: boolean;
142-
threeTierChoiceCardSelectedProduct?: ChoiceCard['product'];
142+
threeTierSelectedChoiceCard?: ChoiceCard;
143143
amountsTestName?: string;
144144
amountsVariantName?: string;
145145
promoCodes: string[];
@@ -153,7 +153,7 @@ export const ContributionsEpicButtons = ({
153153
submitComponentEvent,
154154
isReminderActive,
155155
isSignedIn,
156-
threeTierChoiceCardSelectedProduct,
156+
threeTierSelectedChoiceCard,
157157
amountsTestName,
158158
amountsVariantName,
159159
promoCodes,
@@ -179,25 +179,32 @@ export const ContributionsEpicButtons = ({
179179
}
180180

181181
const getCta = (cta: Cta): Cta => {
182-
if (threeTierChoiceCardSelectedProduct) {
183-
if (threeTierChoiceCardSelectedProduct.supportTier === 'OneOff') {
184-
return {
185-
text: cta.text,
186-
baseUrl: addChoiceCardsOneTimeParams(cta.baseUrl),
187-
};
188-
}
182+
if (!threeTierSelectedChoiceCard?.product) {
183+
return cta;
184+
}
185+
186+
const { destinationUrl, product } = threeTierSelectedChoiceCard;
187+
188+
const url: string =
189+
destinationUrl && destinationUrl.trim() !== ''
190+
? destinationUrl.trim()
191+
: cta.baseUrl;
189192

193+
if (product.supportTier === 'OneOff') {
190194
return {
191195
text: cta.text,
192-
baseUrl: addChoiceCardsProductParams(
193-
cta.baseUrl,
194-
threeTierChoiceCardSelectedProduct.supportTier,
195-
threeTierChoiceCardSelectedProduct.ratePlan,
196-
),
196+
baseUrl: addChoiceCardsOneTimeParams(url),
197197
};
198198
}
199199

200-
return cta;
200+
return {
201+
text: cta.text,
202+
baseUrl: addChoiceCardsProductParams(
203+
url,
204+
product.supportTier,
205+
product.ratePlan,
206+
),
207+
};
201208
};
202209

203210
const openReminder = () => {

dotcom-rendering/src/components/marketing/epics/ctas/ContributionsEpicCtasContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const ContributionsEpicCtasContainer: ReactComponent<Props> = ({
7676
submitComponentEvent={submitComponentEvent}
7777
isReminderActive={isReminderActive}
7878
isSignedIn={Boolean(fetchedEmail)}
79-
threeTierChoiceCardSelectedProduct={selectedChoiceCard?.product}
79+
threeTierSelectedChoiceCard={selectedChoiceCard}
8080
amountsTestName={amountsTestName}
8181
amountsVariantName={amountsVariantName}
8282
promoCodes={variant.promoCodes ?? []}

0 commit comments

Comments
 (0)