Skip to content

Commit 4c25252

Browse files
Merge pull request #15027 from guardian/442-add-feature-flag-toggle-for-sign-up-component
added feature flag for signup component
2 parents ac95a39 + f825378 commit 4c25252

File tree

5 files changed

+267
-131
lines changed

5 files changed

+267
-131
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+
hideNewsletterSignupComponentForSubscribers?: boolean;
2830
}
2931

3032
/**
@@ -41,9 +43,14 @@ export const EmailSignUpWrapper = ({
4143
index,
4244
listId,
4345
idApiUrl,
46+
hideNewsletterSignupComponentForSubscribers = false,
4447
...emailSignUpProps
4548
}: EmailSignUpWrapperProps) => {
46-
const isSubscribed = useNewsletterSubscription(listId, idApiUrl);
49+
const isSubscribed = useNewsletterSubscription(
50+
listId,
51+
idApiUrl,
52+
hideNewsletterSignupComponentForSubscribers,
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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,42 @@ export const SignedInNotSubscribed: Story = {
8383

8484
// User is signed in and IS subscribed - component returns null (hidden)
8585
// Note: This story will render nothing as the component returns null when subscribed
86+
// Requires hideNewsletterSignupComponentForSubscribers: true to enable the subscription check
8687
export const SignedInAlreadySubscribed: Story = {
8788
args: {
8889
hidePrivacyMessage: false,
8990
...defaultArgs,
91+
hideNewsletterSignupComponentForSubscribers: true,
9092
},
9193
async beforeEach() {
9294
mocked(useNewsletterSubscription).mockReturnValue(true);
9395
},
9496
};
9597

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

0 commit comments

Comments
 (0)