-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewsletter.js
54 lines (43 loc) · 1.54 KB
/
newsletter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { useState } from "react";
import axios from "axios";
import styles from '../styles/Home.module.css'
export default function newsletter() {
const [email, setEmail] = useState("");
const [state, setState] = useState("IDLE");
const [errorMessage, setErrorMessage] = useState(null);
const subscribe = async () => {
setState("LOADING");
setErrorMessage(null);
try {
const response = await axios.post("/api/newsletter", { email });
setState("SUCCESS");
} catch (e) {
setErrorMessage(e.response.data.error);
setState("ERROR");
}
};
return (
<div>
<p className={styles.descriptiontitle}>
Follow our progress. Join our newsletter to receive monthly updates about tech meetups, conferences and special activities.
</p>
<div className={styles.registerMailchimp}>
<input className={styles.registerMailchimpInput}
type="text"
placeholder="Enter Email"
value={email}
onChange={(e) => setEmail(e.target.value)}
/>
<button type="button" className={styles.registerMailchimpButton} disabled={state === "LOADING"} onClick={subscribe}>Join</button>
</div>
{state === "ERROR" && (
<p className={styles.description}>{errorMessage}</p>
)}
{state === "SUCCESS" && (
<p className={styles.description}>Thanks! I'll be in touch shortly :) Chris Mazur.-</p>
)}
</div>
);
};
// Attributions:
// https://github.com/uriklar/uriklar-next/blob/master/components/newsletter.jsx