Skip to content

Commit 10e0e71

Browse files
added feature flag for signup component
1 parent 5462e5c commit 10e0e71

File tree

5 files changed

+223
-136
lines changed

5 files changed

+223
-136
lines changed

dotcom-rendering/src/components/EmailSignUpWrapper.importable.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ interface EmailSignUpWrapperProps extends EmailSignUpProps {
2525
idApiUrl: string;
2626
/** You should only set this to true if the privacy message will be shown elsewhere on the page */
2727
hidePrivacyMessage?: boolean;
28+
/** Feature flag to enable hiding newsletter signup for already subscribed users */
29+
hideNewsletterForSubscribers?: boolean;
2830
}
2931

3032
/**
@@ -41,9 +43,14 @@ export const EmailSignUpWrapper = ({
4143
index,
4244
listId,
4345
idApiUrl,
46+
hideNewsletterForSubscribers = false,
4447
...emailSignUpProps
4548
}: EmailSignUpWrapperProps) => {
46-
const isSubscribed = useNewsletterSubscription(listId, idApiUrl);
49+
const isSubscribed = useNewsletterSubscription(
50+
listId,
51+
idApiUrl,
52+
hideNewsletterForSubscribers,
53+
);
4754

4855
// Show placeholder while subscription status is being determined
4956
// This prevents layout shift in both subscribed and non-subscribed cases

dotcom-rendering/src/components/EmailSignUpWrapper.stories.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const defaultArgs = {
2323
successDescription: "We'll send you The Recap every week",
2424
theme: 'sport',
2525
idApiUrl: 'https://idapi.theguardian.com',
26+
hideNewsletterForSubscribers: true, // Feature flag enabled by default in stories
2627
} satisfies Story['args'];
2728

2829
// Loading state - shows placeholder while auth status is being determined
@@ -93,4 +94,30 @@ export const SignedInAlreadySubscribed: Story = {
9394
},
9495
};
9596

97+
// Feature flag disabled - always shows signup form regardless of subscription status
98+
// When hideNewsletterForSubscribers is false, the subscription check is skipped
99+
export const FeatureFlagDisabled: Story = {
100+
args: {
101+
hidePrivacyMessage: false,
102+
...defaultArgs,
103+
hideNewsletterForSubscribers: false,
104+
},
105+
async beforeEach() {
106+
// Even though we mock this to return true (subscribed),
107+
// the feature flag being disabled means it won't be checked
108+
mocked(useNewsletterSubscription).mockReturnValue(false);
109+
mocked(useIsSignedIn).mockReturnValue(true);
110+
mocked(lazyFetchEmailWithTimeout).mockReturnValue(() =>
111+
Promise.resolve('[email protected]'),
112+
);
113+
},
114+
parameters: {
115+
docs: {
116+
description: {
117+
story: 'When the hideNewsletterForSubscribers feature flag is disabled, the signup form is always shown regardless of subscription status.',
118+
},
119+
},
120+
},
121+
};
122+
96123
export default meta;

dotcom-rendering/src/lib/renderElement.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,8 @@ export const renderElement = ({
577577
successDescription: element.newsletter.successDescription,
578578
theme: element.newsletter.theme,
579579
idApiUrl: idApiUrl ?? '',
580+
hideNewsletterForSubscribers:
581+
!!switches.hideNewsletterForSubscribers,
580582
};
581583
if (isListElement || isTimeline) return null;
582584
return (

0 commit comments

Comments
 (0)