@@ -5,22 +5,18 @@ import {
55 palette ,
66 space ,
77} from '@guardian/source/foundations' ;
8- import {
9- Button ,
10- Checkbox ,
11- CheckboxGroup ,
12- TextInput ,
13- } from '@guardian/source/react-components' ;
8+ import { Button } from '@guardian/source/react-components' ;
149import {
1510 type ChangeEventHandler ,
1611 type ReactEventHandler ,
1712 useState ,
1813} from 'react' ;
19- import ReactGoogleRecaptcha from 'react-google-recaptcha' ;
14+ import type ReactGoogleRecaptcha from 'react-google-recaptcha' ;
2015import { InlineSkipToWrapper } from './InlineSkipToWrapper' ;
16+ import { ManyNewslettersFormFields } from './ManyNewslettersFormFields' ;
2117import { NewsletterPrivacyMessage } from './NewsletterPrivacyMessage' ;
2218
23- interface FormProps {
19+ export interface FormProps {
2420 status : 'NotSent' | 'Loading' | 'Success' | 'Failed' | 'InvalidEmail' ;
2521 email : string ;
2622 handleTextInput : ChangeEventHandler < HTMLInputElement > ;
@@ -71,29 +67,6 @@ const formFieldsStyle = css`
7167 }
7268` ;
7369
74- const inputWrapperStyle = css `
75- margin-bottom : ${ space [ 2 ] } px;
76- ${ from . desktop } {
77- margin-bottom : 0 ;
78- margin-right : ${ space [ 2 ] } px;
79- flex-basis : 296px ;
80- }
81- ` ;
82-
83- const inputAndOptInWrapperStyle = css `
84- ${ from . desktop } {
85- flex-basis : 296px ;
86- margin-right : ${ space [ 2 ] } px;
87- }
88- ` ;
89-
90- const optInCheckboxTextSmall = css `
91- label > div {
92- font-size : 13px ;
93- line-height : 16px ;
94- }
95- ` ;
96-
9770const formAsideStyle = ( hideOnMobile : boolean ) => css `
9871 overflow : hidden;
9972 transition : max-height 1.5s linear;
@@ -155,24 +128,13 @@ export const ManyNewslettersForm = ({
155128 handleCaptchaError,
156129} : FormProps ) => {
157130 const [ formHasFocus , setFormHasFocus ] = useState ( false ) ;
158- const [ firstInteractionOccurred , setFirstInteractionOccurred ] =
159- useState ( false ) ;
160131 const hidePrivacyOnMobile = ! formHasFocus && email . length === 0 ;
161132
162- const isMarketingOptInVisible = marketingOptIn !== undefined ;
163-
164133 const ariaLabel =
165134 newsletterCount === 1
166135 ? 'Sign up for the newsletter you selected'
167136 : `Sign up for the ${ newsletterCount } newsletters you selected` ;
168137
169- const errorMessage =
170- status === 'Failed'
171- ? 'Sign up failed. Please try again'
172- : status === 'InvalidEmail'
173- ? 'Please enter a valid email address'
174- : undefined ;
175-
176138 return (
177139 < form
178140 aria-label = "sign-up confirmation form"
@@ -200,75 +162,18 @@ export const ManyNewslettersForm = ({
200162 < div css = { formFieldsStyle } >
201163 { status !== 'Success' ? (
202164 < >
203- < div css = { inputAndOptInWrapperStyle } >
204- < span css = { inputWrapperStyle } >
205- < TextInput
206- label = "Enter your email"
207- value = { email }
208- onChange = { handleTextInput }
209- error = { errorMessage }
210- disabled = { status === 'Loading' }
211- onFocus = { ( ) =>
212- setFirstInteractionOccurred ( true )
213- }
214- />
215- </ span >
216- { isMarketingOptInVisible && (
217- < div >
218- < CheckboxGroup
219- name = "marketing-preferences"
220- label = "Marketing preferences"
221- hideLabel = { true }
222- cssOverrides = { optInCheckboxTextSmall }
223- >
224- < Checkbox
225- label = "Get updates about our journalism and ways to support and enjoy our work."
226- value = "marketing-opt-in"
227- checked = { marketingOptIn }
228- onChange = { ( e ) =>
229- setMarketingOptIn (
230- e . target . checked ,
231- )
232- }
233- theme = { {
234- fillUnselected :
235- palette . neutral [ 100 ] ,
236- borderUnselected :
237- palette . neutral [ 46 ] ,
238- fillSelected :
239- palette . brand [ 500 ] ,
240- borderSelected :
241- palette . brand [ 500 ] ,
242- borderHover : palette . brand [ 500 ] ,
243- } }
244- />
245- </ CheckboxGroup >
246- </ div >
247- ) }
248- { useReCaptcha && ! ! captchaSiteKey && (
249- < div
250- css = { css `
251- .grecaptcha-badge {
252- visibility : hidden;
253- }
254- ` }
255- >
256- { ( ! visibleRecaptcha ||
257- firstInteractionOccurred ) && (
258- < ReactGoogleRecaptcha
259- sitekey = { captchaSiteKey }
260- ref = { reCaptchaRef }
261- onError = { handleCaptchaError }
262- size = {
263- visibleRecaptcha
264- ? 'normal'
265- : 'invisible'
266- }
267- />
268- ) }
269- </ div >
270- ) }
271- </ div >
165+ < ManyNewslettersFormFields
166+ status = { status }
167+ email = { email }
168+ handleTextInput = { handleTextInput }
169+ marketingOptIn = { marketingOptIn }
170+ setMarketingOptIn = { setMarketingOptIn }
171+ useReCaptcha = { useReCaptcha }
172+ captchaSiteKey = { captchaSiteKey }
173+ visibleRecaptcha = { visibleRecaptcha }
174+ reCaptchaRef = { reCaptchaRef }
175+ handleCaptchaError = { handleCaptchaError }
176+ />
272177 < Button
273178 aria-label = { ariaLabel }
274179 isLoading = { status === 'Loading' }
0 commit comments