Skip to content

Commit a1ce898

Browse files
authored
add newsletter signup (#1)
* add newsletter signup * remove TODO
1 parent 0b75096 commit a1ce898

File tree

3 files changed

+81
-27
lines changed

3 files changed

+81
-27
lines changed

package-lock.json

Lines changed: 57 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@
3131
"ethers": "^5.7.2",
3232
"focus-trap-react": "^10.0.0",
3333
"github-slugger": "^1.4.0",
34+
"jsonp": "^0.2.1",
3435
"nanostores": "^0.7.1",
3536
"preact": "^10.11.3",
3637
"query-string": "^7.1.1",
3738
"react-instantsearch-hooks-web": "^6.38.1",
38-
"tailwindcss": "^3.2.4"
39+
"tailwindcss": "^3.2.4",
40+
"to-querystring": "^1.1.1"
3941
},
4042
"devDependencies": {
4143
"@astrojs/mdx": "^0.11.6",

src/components/Footer/NewsletterSignupForm.tsx

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import { useState } from "preact/hooks"
44
import "./NewsletterCTA.css"
55
import button from "../../styles/cl-design-system/button.module.css"
66
import { clsx } from "~/lib"
7+
import jsonp from "jsonp"
8+
import toQueryString from "to-querystring"
79

810
const TAG_1 = "Developers"
911
const 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

1516
export 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

Comments
 (0)