@@ -4,13 +4,14 @@ import { useState } from "preact/hooks"
44import "./NewsletterCTA.css"
55import button from "../../styles/cl-design-system/button.module.css"
66import { clsx } from "~/lib"
7+ import jsonp from "jsonp"
8+ import toQueryString from "to-querystring"
79
810const TAG_1 = "Developers"
911const TAG_2 = "Developer Docs"
1012
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"
1415
1516export const NewsletterSignupForm = ( ) => {
1617 const [ isLoading , setIsLoading ] = useState ( false )
@@ -20,31 +21,26 @@ export const NewsletterSignupForm = () => {
2021 e . preventDefault ( )
2122 const email = new FormData ( e . target ) . get ( "Email" )
2223 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 ,
3426 } )
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 )
3840 }
39- setIsSuccess ( true )
40- } )
41- . catch ( ( err ) => {
42- console . error ( err )
43- setIsError ( true )
44- } )
45- . finally ( ( ) => {
4641 setIsLoading ( false )
47- } )
42+ }
43+ )
4844 }
4945
5046 return (
0 commit comments