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
5 changes: 5 additions & 0 deletions .changeset/selfish-eggs-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@guardian/support-dotcom-components': minor
---

adds destination url parameter to choice card
29 changes: 29 additions & 0 deletions src/server/lib/choiceCards/choiceCards.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,35 @@ describe('getChoiceCardsSettings', () => {
supportTier: 'SupporterPlus',
ratePlan: 'Monthly',
});
expect(result?.choiceCards[1].destinationUrl).toBeNull();
});

it('preserves custom destinationUrl when provided', () => {
const variantChoiceCardSettings: ChoiceCardsSettings = {
choiceCards: [
{
...defaultEpicChoiceCardsSettings('UnitedStates').choiceCards[0],
destinationUrl: 'https://support.theguardian.com/contribute/one-time',
},
defaultEpicChoiceCardsSettings('UnitedStates').choiceCards[1],
defaultEpicChoiceCardsSettings('UnitedStates').choiceCards[2],
],
};
const promoCodes: string[] = [];

const result = getChoiceCardsSettings(
'UnitedStates',
'Epic',
mockProductCatalog,
mockPromotionsCache,
promoCodes,
variantChoiceCardSettings,
);

expect(result).toBeDefined();
expect(result?.choiceCards[0].destinationUrl).toEqual(
'https://support.theguardian.com/contribute/one-time',
);
});

it('returns choice cards with monthly discount (PROMO_B) applied', () => {
Expand Down
1 change: 1 addition & 0 deletions src/server/lib/choiceCards/choiceCards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const enrichChoiceCard = (
benefitsLabel: choiceCard.benefitsLabel,
benefits,
pill,
destinationUrl: choiceCard.destinationUrl, // Preserve the destination URL
};
};

Expand Down
4 changes: 4 additions & 0 deletions src/server/lib/choiceCards/defaultChoiceCardSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const oneOffCard = (countryGroupId: CountryGroupId): ChoiceCard => ({
: 'We welcome support of any size, any time',
},
],
destinationUrl: null, // Will use default CTA behavior
});

const fullChoiceCards = (countryGroupId: CountryGroupId): ChoiceCard[] => [
Expand All @@ -35,6 +36,7 @@ const fullChoiceCards = (countryGroupId: CountryGroupId): ChoiceCard[] => [
copy: 'Give to the Guardian every month with Support',
},
],
destinationUrl: null, // Will use default CTA behavior
},
{
product: {
Expand All @@ -56,6 +58,7 @@ const fullChoiceCards = (countryGroupId: CountryGroupId): ChoiceCard[] => [
pill: {
copy: 'Recommended',
},
destinationUrl: null, // Will use default CTA behavior
},
oneOffCard(countryGroupId),
];
Expand Down Expand Up @@ -88,6 +91,7 @@ const shorterChoiceCards = (countryGroupId: CountryGroupId): ChoiceCard[] => [
pill: {
copy: 'Recommended',
},
destinationUrl: null, // Will use default CTA behavior
},
oneOffCard(countryGroupId),
];
Expand Down
1 change: 1 addition & 0 deletions src/shared/types/props/choiceCards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const choiceCardSchema = z.object({
benefitsLabel: z.string().nullish(), // e.g. "Unlock All-access digital benefits:"
benefits: z.array(productBenefitSchema),
pill: pillSchema.nullish(),
destinationUrl: z.string().nullish(), // Optional override URL for this choice card
});

export type ChoiceCard = z.infer<typeof choiceCardSchema>;
Expand Down