@@ -4,13 +4,14 @@ import { useState } from "preact/hooks"
4
4
import "./NewsletterCTA.css"
5
5
import button from "../../styles/cl-design-system/button.module.css"
6
6
import { clsx } from "~/lib"
7
+ import jsonp from "jsonp"
8
+ import toQueryString from "to-querystring"
7
9
8
10
const TAG_1 = "Developers"
9
11
const TAG_2 = "Developer Docs"
10
12
11
- // TODO: setup zapier hook or use custom integration for newsletter signup
12
- // const NEWSLETTER_URL = "https://hooks.zapier.com/hooks/catch/10015000/bb8efqc"
13
- const NEWSLETTER_URL = ""
13
+ const NEWSLETTER_URL =
14
+ "https://gmail.us14.list-manage.com/subscribe/post-json?u=3b1d822eb27b2fa64d82d430b&id=0b4603244e"
14
15
15
16
export const NewsletterSignupForm = ( ) => {
16
17
const [ isLoading , setIsLoading ] = useState ( false )
@@ -20,31 +21,26 @@ export const NewsletterSignupForm = () => {
20
21
e . preventDefault ( )
21
22
const email = new FormData ( e . target ) . get ( "Email" )
22
23
setIsLoading ( true )
23
- fetch ( NEWSLETTER_URL , {
24
- mode : "no-cors" ,
25
- method : "POST" ,
26
- body : JSON . stringify ( {
27
- email,
28
- tag1 : TAG_1 ,
29
- tag2 : TAG_2 ,
30
- } ) ,
31
- headers : {
32
- "Content-Type" : "application/json" ,
33
- } ,
24
+ const params = toQueryString ( {
25
+ EMAIL : email ,
34
26
} )
35
- . then ( ( response ) => {
36
- if ( response . type !== "opaque" && ! response . ok ) {
37
- throw Error ( response . statusText )
27
+ const url = NEWSLETTER_URL + "&" + params
28
+ jsonp (
29
+ url ,
30
+ {
31
+ param : "c" ,
32
+ } ,
33
+ ( err , data ) => {
34
+ if ( err ) {
35
+ setIsError ( true )
36
+ } else if ( data . result !== "success" ) {
37
+ setIsError ( true )
38
+ } else {
39
+ setIsSuccess ( true )
38
40
}
39
- setIsSuccess ( true )
40
- } )
41
- . catch ( ( err ) => {
42
- console . error ( err )
43
- setIsError ( true )
44
- } )
45
- . finally ( ( ) => {
46
41
setIsLoading ( false )
47
- } )
42
+ }
43
+ )
48
44
}
49
45
50
46
return (
0 commit comments