Skip to content

Newsletter Signup Form - signed in and out#15747

Merged
georgerichmond merged 8 commits intomainfrom
newsletter-signup-form-signed-in-and-out
Apr 27, 2026
Merged

Newsletter Signup Form - signed in and out#15747
georgerichmond merged 8 commits intomainfrom
newsletter-signup-form-signed-in-and-out

Conversation

@georgerichmond
Copy link
Copy Markdown
Contributor

@georgerichmond georgerichmond commented Apr 24, 2026

What does this change?

Implements the signed-in and signed-out flows for the new NewsletterSignupForm component, closing issues #15678 and #15686.

New components & files

  • NewsletterSignupForm.island.tsx — the new auth-aware signup form, replacing SecureSignup as the inner content of the newsletter signup card when showNewNewsletterSignupCard is enabled. Supports both signed-in (email pre-filled from Identity, email input hidden) and signed-out (email input visible) states in a single component.
  • useNewsletterSignupForm.ts — a custom hook that encapsulates all form state and side-effects (email resolution, reCAPTCHA, Ophan tracking, form submission). Extracted from the component so that every visual state is trivially reproducible in Storybook by mocking a single hook, and to keep the component itself as a pure rendering layer.

Signed-in flow (closes #15678)

  • Email is pre-filled from Identity; the email <input> is hidden
  • "Sign up" button is shown; on success, displays "You're signed up!", the newsletter name & frequency, and a "Browse more newsletters" link
  • Privacy message is rendered outside the card (below it), since the marketing toggle is not shown for signed-in users
  • Ophan tracking reuses the same interaction lifecycle as SecureSignup

Signed-out flow (closes #15686)

  • Email input with "Enter your email" label and a "Sign up" button
  • Marketing opt-in toggle and privacy message are revealed when the email field is focused/interacted with
  • Inline validation error shown for empty or incorrectly formatted email
  • Same success state as the signed-in flow after submission completes
  • Ophan tracking reuses the same interaction lifecycle as SecureSignup

Why a custom hook?

All form logic (email fetch, reCAPTCHA, marketing opt-in, Ophan tracking, submission, validation) lives in useNewsletterSignupForm. This separation means:

  1. Storybook screenshots are easy — every visual state (idle, focused, loading, success, failure, validation error) can be covered by mocking the single hook return value, with no need to stub network requests or drive interactions.
  2. The component stays thinNewsletterSignupFormActive is purely a rendering layer, making it straightforward to review and maintain.

Refactored from SecureSignup

The submission and tracking logic (buildFormData, postFormData, sendTracking) has been lifted from SecureSignup.island.tsx and consolidated into useNewsletterSignupForm. SecureSignup was previously used as an intermediate placeholder inside the new card; it is now replaced by NewsletterSignupForm.

Other changes

  • NewsletterSignupCardContainer updated to accept a render-prop children (so it can pass openPreview down), and now renders the privacy message outside the card when the user is signed in
  • EmailSignUpWrapper wired up to pass isSignedIn and the new form props through to NewsletterSignupCardContainer
  • renderElement.tsx prop name corrected (showNewsletterSignupCardshowNewNewsletterSignupCard)
  • Minor NewsletterSignupCard style tweaks (illustration size, spacing)

Why?

Part of the rollout of the new newsletter signup card design. This PR delivers the complete signup experience for both signed-in and signed-out readers.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 24, 2026

@georgerichmond georgerichmond force-pushed the newsletter-signup-form-signed-in-and-out branch from 12262f4 to ac85def Compare April 24, 2026 08:32
@georgerichmond georgerichmond added run_chromatic Runs chromatic when label is applied feature Departmental tracking: work on a new feature labels Apr 24, 2026
@georgerichmond georgerichmond marked this pull request as ready for review April 24, 2026 08:46
@georgerichmond georgerichmond requested a review from a team as a code owner April 24, 2026 08:46
@github-actions github-actions Bot removed the run_chromatic Runs chromatic when label is applied label Apr 24, 2026
@georgerichmond georgerichmond self-assigned this Apr 24, 2026
@georgerichmond georgerichmond added the run_chromatic Runs chromatic when label is applied label Apr 24, 2026
@github-actions github-actions Bot removed the run_chromatic Runs chromatic when label is applied label Apr 24, 2026
@georgerichmond georgerichmond force-pushed the newsletter-signup-form-signed-in-and-out branch from 172c794 to de508c3 Compare April 27, 2026 10:09
Copy link
Copy Markdown
Contributor

@mgosz-guardian mgosz-guardian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 comments. One v minor, other possibly worth looking at.

Comment thread dotcom-rendering/src/components/NewsletterSignupForm.island.tsx Outdated
'captcha-not-passed',
renderingTarget,
);
setIsWaitingForResponse(false);
Copy link
Copy Markdown
Contributor

@mgosz-guardian mgosz-guardian Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This flag is set to false in the happy path. I think we might have a possible edge case when the recaptcha fails (due network issue for example) and the user could be stuck due to this flag not switched to false.

@georgerichmond georgerichmond force-pushed the newsletter-signup-form-signed-in-and-out branch from 7738832 to de18733 Compare April 27, 2026 13:43
};

const containerStyles = css`
clear: left;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, I'm curious about the use of clear here. I guess traditionally this would have been paired with floated elements. But nowadays we tend to use flex box to handle similar layouts. It looks like we are using flex and not float, I"ve never seen clear used with flex before.

Copy link
Copy Markdown
Contributor Author

@georgerichmond georgerichmond Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's needed to clear a floated element from the previous block in dynamic content in an article page - EmailSignup.tsx does it. However it's not needed on the container actually as it's on the divider above which was added recently. I've removed it from the container and kept it on the divider styles.

@georgerichmond georgerichmond merged commit 26e54a2 into main Apr 27, 2026
24 checks passed
@georgerichmond georgerichmond deleted the newsletter-signup-form-signed-in-and-out branch April 27, 2026 14:52
@gu-prout
Copy link
Copy Markdown

gu-prout Bot commented Apr 27, 2026

Seen on PROD (merged by @georgerichmond 10 minutes and 17 seconds ago) Please check your changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Departmental tracking: work on a new feature Seen-on-PROD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NewsletterSignup.island.tsx - signed-out flow NewsletterSignup.island.tsx — signed in flow

3 participants