|
1 |
| -import { createRef, useState } from "react"; |
2 |
| -import Button from "./Button.js"; |
3 |
| -import CheckmarkCircleIcon from "./icons/CheckmarkCircleIcon.js"; |
4 |
| -import MailCircleIcon from "./icons/MailCircleIcon.js"; |
5 |
| -import PointerCircleIcon from "./icons/PointerCircleIcon.js"; |
| 1 | +import { useEffect } from "react"; |
6 | 2 | import { useI18n } from "../lib/i18n";
|
7 | 3 |
|
8 |
| -const newsletterFormEndpoint = |
9 |
| - "https://geops.us4.list-manage.com/subscribe/post-json?u=23161055bb6a407f7e6c00038&id=c9694280f7"; |
10 |
| - |
11 | 4 | export default function NewsletterForm({ translations }) {
|
12 |
| - const refHeader = createRef(); |
13 |
| - const [email, setEmail] = useState(""); |
14 |
| - const [submitted, setSubmitted] = useState(false); |
15 | 5 | const { language } = useI18n();
|
| 6 | + useEffect(() => { |
| 7 | + const script = document.createElement("script"); |
| 8 | + script.src = "https://js.hsforms.net/forms/v2.js"; |
| 9 | + document.body.appendChild(script); |
16 | 10 |
|
17 |
| - const handleSubmit = async (event) => { |
18 |
| - event.preventDefault(); |
19 |
| - refHeader.current.scrollIntoView({ behavior: "smooth" }); |
20 |
| - await fetch(`${newsletterFormEndpoint}&EMAIL=${email}&c=?`, { |
21 |
| - mode: "no-cors", |
| 11 | + script.addEventListener("load", () => { |
| 12 | + if (window.hbspt) { |
| 13 | + window.hbspt.forms.create({ |
| 14 | + region: "eu1", |
| 15 | + portalId: "143209811", |
| 16 | + formId: |
| 17 | + language === "de" |
| 18 | + ? "6d86cf62-264e-49bc-a950-f94fa84e2a8e" |
| 19 | + : "e9d6a25f-86d6-4a7b-997f-fce926dfbb18", |
| 20 | + target: "#hubspotForm", |
| 21 | + }); |
| 22 | + } |
22 | 23 | });
|
23 |
| - setSubmitted(true); |
24 |
| - }; |
| 24 | + }, [language]); |
25 | 25 |
|
26 | 26 | return (
|
27 |
| - <form |
28 |
| - className="container mx-auto max-w-screen-lg p-8" |
29 |
| - onSubmit={handleSubmit} |
30 |
| - > |
31 |
| - <h4 className="mb-10 text-center sm:text-left" ref={refHeader}> |
32 |
| - {submitted ? translations.submittedTitle : translations.subtitle} |
33 |
| - </h4> |
34 |
| - {submitted ? ( |
35 |
| - <div className="flex flex-col items-center sm:flex-row sm:items-start sm:justify-between"> |
36 |
| - <div className="w-48 text-center"> |
37 |
| - <MailCircleIcon /> |
38 |
| - <div className="my-4">{translations.submitted1}</div> |
39 |
| - </div> |
40 |
| - <div className="w-56 text-center"> |
41 |
| - <PointerCircleIcon /> |
42 |
| - <div className="my-4">{translations.submitted2}</div> |
43 |
| - </div> |
44 |
| - <div className="w-48 text-center"> |
45 |
| - <CheckmarkCircleIcon /> |
46 |
| - <div className="my-4">{translations.submitted3}</div> |
47 |
| - </div> |
48 |
| - </div> |
49 |
| - ) : ( |
50 |
| - <> |
51 |
| - <label className="block"> |
52 |
| - {translations.email}* |
53 |
| - <input |
54 |
| - autoCapitalize="off" |
55 |
| - autoCorrect="off" |
56 |
| - onChange={(e) => setEmail(e.target.value)} |
57 |
| - value={email} |
58 |
| - type="email" |
59 |
| - className="block h-14 w-full rounded border-2 border-gray-light focus:border-blue focus:ring-0" |
60 |
| - required |
61 |
| - /> |
62 |
| - </label> |
63 |
| - <p className="text-gray-light">* {translations.required}</p> |
64 |
| - <label className="mt-8 inline-flex"> |
65 |
| - <input |
66 |
| - type="checkbox" |
67 |
| - defaultChecked={false} |
68 |
| - className="mt-3 text-blue focus:ring-0" |
69 |
| - required |
70 |
| - /> |
71 |
| - <span className="ml-4">{translations.privacy}</span> |
72 |
| - </label> |
73 |
| - </> |
74 |
| - )} |
75 |
| - <div className="py-16 text-center"> |
76 |
| - {submitted ? ( |
77 |
| - <Button href={language === "de" ? "/" : "/en"}> |
78 |
| - {translations.submittedButton} |
79 |
| - </Button> |
80 |
| - ) : ( |
81 |
| - <Button type="submit">{translations.subscribe}</Button> |
82 |
| - )} |
83 |
| - </div> |
84 |
| - </form> |
| 27 | + <div id="hubspotForm" className="container mx-auto max-w-screen-lg p-8"> |
| 28 | + {translations.loading} |
| 29 | + </div> |
85 | 30 | );
|
86 | 31 | }
|
0 commit comments