@@ -17,7 +17,7 @@ enum FormStatus {
17
17
NORMAL = 'normal' ,
18
18
LOADING = 'loading' ,
19
19
SUCCESS = 'success' ,
20
- ERROR = 'error' ,
20
+ ERROR = 'error'
21
21
}
22
22
23
23
interface NewsletterSubscribeProps {
@@ -46,12 +46,12 @@ export default function NewsletterSubscribe({
46
46
title = 'Subscribe to our newsletter to receive news about AsyncAPI.' ,
47
47
subtitle = 'We respect your inbox. No spam, promise ✌️' ,
48
48
type = 'Newsletter' ,
49
- errorSubtitle = 'Subscription failed, please let us know about it by submitting a bug' ,
49
+ errorSubtitle = 'Subscription failed, please let us know about it by submitting a bug'
50
50
} : NewsletterSubscribeProps ) {
51
51
const [ email , setEmail ] = useState < string > ( '' ) ;
52
52
const [ name , setName ] = useState < string > ( '' ) ;
53
53
const [ status , setStatus ] = useState < FormStatus > ( FormStatus . NORMAL ) ;
54
- const [ emailError , setEmailError ] = useState < ( error : string ) => void > ( ) ;
54
+ const [ setEmailError ] = useState < ( error : string ) => void > ( ) ;
55
55
56
56
const { t, ready } = useTranslation ( 'common' , { keyPrefix : 'newsletterCTA' } ) ;
57
57
@@ -69,28 +69,30 @@ export default function NewsletterSubscribe({
69
69
setStatus ( FormStatus . LOADING ) ;
70
70
event . preventDefault ( ) ;
71
71
72
- //validate email
72
+ // validate email
73
73
const emailPattern = / ^ [ ^ \s @ ] + @ [ ^ \s @ ] + \. [ ^ \s @ ] + $ / ;
74
+
74
75
if ( ! emailPattern . test ( email ) ) {
75
76
setEmailError ( 'Invalid email address' ) ;
76
77
setFormStatus ( FormStatus . ERROR ) ;
78
+
77
79
return ;
78
80
}
79
81
setEmailError ( '' ) ; // Clear error if valid
80
82
setStatus ( FormStatus . LOADING ) ;
81
- //end
83
+ // end
82
84
const data = {
83
85
name,
84
86
email,
85
- interest : type ,
87
+ interest : type
86
88
} ;
87
89
88
90
fetch ( '/.netlify/functions/newsletter_subscription' , {
89
91
method : 'POST' ,
90
92
body : JSON . stringify ( data ) ,
91
93
headers : {
92
- 'Content-Type' : 'application/json' ,
93
- } ,
94
+ 'Content-Type' : 'application/json'
95
+ }
94
96
} )
95
97
. then ( ( res ) => {
96
98
if ( res . status === 200 ) {
@@ -107,16 +109,11 @@ export default function NewsletterSubscribe({
107
109
108
110
if ( status === FormStatus . SUCCESS ) {
109
111
return (
110
- < div className = { className } data-testid = "NewsletterSubscribe-main" >
111
- < Heading
112
- level = { HeadingLevel . h3 }
113
- textColor = { headTextColor }
114
- typeStyle = { HeadingTypeStyle . lg }
115
- className = "mb-4"
116
- >
112
+ < div className = { className } data-testid = 'NewsletterSubscribe-main' >
113
+ < Heading level = { HeadingLevel . h3 } textColor = { headTextColor } typeStyle = { HeadingTypeStyle . lg } className = 'mb-4' >
117
114
{ ready ? t ( 'successTitle' ) : 'Thank you for subscribing!' }
118
115
</ Heading >
119
- < Paragraph className = " mb-8" textColor = { paragraphTextColor } >
116
+ < Paragraph className = ' mb-8' textColor = { paragraphTextColor } >
120
117
{ ready ? t ( 'subtitle' ) : subtitle }
121
118
</ Paragraph >
122
119
</ div >
@@ -125,21 +122,13 @@ export default function NewsletterSubscribe({
125
122
126
123
if ( status === FormStatus . ERROR ) {
127
124
return (
128
- < div className = { className } data-testid = "NewsletterSubscribe-main" >
129
- < Heading
130
- level = { HeadingLevel . h3 }
131
- textColor = { headTextColor }
132
- typeStyle = { HeadingTypeStyle . lg }
133
- className = "mb-4"
134
- >
125
+ < div className = { className } data-testid = 'NewsletterSubscribe-main' >
126
+ < Heading level = { HeadingLevel . h3 } textColor = { headTextColor } typeStyle = { HeadingTypeStyle . lg } className = 'mb-4' >
135
127
{ ready ? t ( 'errorTitle' ) : 'Something went wrong' }
136
128
</ Heading >
137
- < Paragraph className = " mb-8" textColor = { paragraphTextColor } >
129
+ < Paragraph className = ' mb-8' textColor = { paragraphTextColor } >
138
130
{ ready ? t ( 'errorSubtitle' ) : errorSubtitle } { ' ' }
139
- < TextLink
140
- href = "https://github.com/asyncapi/website/issues/new?template=bug.md"
141
- target = "_blank"
142
- >
131
+ < TextLink href = 'https://github.com/asyncapi/website/issues/new?template=bug.md' target = '_blank' >
143
132
{ ready ? t ( 'errorLinkText' ) : 'here' }
144
133
</ TextLink >
145
134
</ Paragraph >
@@ -148,48 +137,36 @@ export default function NewsletterSubscribe({
148
137
}
149
138
150
139
return (
151
- < div className = { className } data-testid = "NewsletterSubscribe-main" >
152
- < Heading
153
- level = { HeadingLevel . h3 }
154
- textColor = { headTextColor }
155
- typeStyle = { HeadingTypeStyle . lg }
156
- className = "mb-4"
157
- >
140
+ < div className = { className } data-testid = 'NewsletterSubscribe-main' >
141
+ < Heading level = { HeadingLevel . h3 } textColor = { headTextColor } typeStyle = { HeadingTypeStyle . lg } className = 'mb-4' >
158
142
{ ready ? t ( 'title' ) : title }
159
143
</ Heading >
160
- < Paragraph className = " mb-8" textColor = { paragraphTextColor } >
144
+ < Paragraph className = ' mb-8' textColor = { paragraphTextColor } >
161
145
{ ready ? t ( 'subtitle' ) : subtitle }
162
146
</ Paragraph >
163
147
{ status === 'loading' ? (
164
- < Loader
165
- loaderText = { 'Waiting for response...' }
166
- loaderIcon = { < IconCircularLoader dark /> }
167
- dark = { dark }
168
- />
148
+ < Loader loaderText = { 'Waiting for response...' } loaderIcon = { < IconCircularLoader dark /> } dark = { dark } />
169
149
) : (
170
- < form
171
- className = "flex flex-col gap-4 md:flex-row"
172
- onSubmit = { handleSubmit }
173
- >
150
+ < form className = 'flex flex-col gap-4 md:flex-row' onSubmit = { handleSubmit } >
174
151
< InputBox
175
152
inputType = { InputTypes . TEXT }
176
- inputName = " name"
153
+ inputName = ' name'
177
154
placeholder = { ready ? t ( 'nameInput' ) : 'Your name' }
178
155
inputValue = { name }
179
156
setInput = { setName }
180
157
/>
181
158
< InputBox
182
159
inputType = { InputTypes . EMAIL }
183
- inputName = " email"
160
+ inputName = ' email'
184
161
placeholder = { ready ? t ( 'emailInput' ) : 'Your email' }
185
162
inputValue = { email }
186
163
setInput = { setEmail }
187
164
/>
188
165
< Button
189
166
type = { ButtonType . SUBMIT }
190
167
text = { ready ? t ( 'subscribeBtn' ) : 'Subscribe' }
191
- className = " mt-2 w-full md:flex-1 md:mt-0 md:mr-2"
192
- href = ""
168
+ className = ' mt-2 w-full md:mr-2 md:mt-0 md:flex-1'
169
+ href = ''
193
170
/>
194
171
</ form >
195
172
) }
0 commit comments