From b514ec233f443b2aec5fcc28d2e013f2d23d4791 Mon Sep 17 00:00:00 2001 From: Graeme Fulton Date: Thu, 27 Jun 2024 08:40:42 -0400 Subject: [PATCH] fix #50 --- components/newsletter/SignupHorizontal.js | 101 +++++++++++++++------- components/newsletter/SignupSidebar.js | 92 +++++++++++++------- 2 files changed, 129 insertions(+), 64 deletions(-) diff --git a/components/newsletter/SignupHorizontal.js b/components/newsletter/SignupHorizontal.js index 6b64384a..57e66b5e 100644 --- a/components/newsletter/SignupHorizontal.js +++ b/components/newsletter/SignupHorizontal.js @@ -5,47 +5,56 @@ import { FormattedMessage, useIntl } from "react-intl"; import Button from "../Primitives/Button"; export default function SignupHorizontal({ className, showNoSpam }) { - const [registered, setRegistered] = useState(false); + const [registered, setRegistered] = useState(false); const [error, setError] = useState(false); + const [tryEmail, setTryEmail] = useState(false); + const [alreadySubscribed, setAlreadySubscribed] = useState(false); const intl = useIntl(); const [buttonText, setButtonText] = useState( intl.formatMessage({ id: "intro.button.updates" }) ); + const onSubmit = async (data) => { setButtonText(intl.formatMessage({ id: "signup.button.submitting" })); - axios - .post( - "https://req.prototypr.io/https://emailoctopus.com/lists/c70b3a0c-1390-11eb-a3d0-06b4694bee2a/members/embedded/1.3/add", - { - field_0: data.emailRequired, - } - ) - .then(function (response) { - console.log("success"); - // var cookieDomain = process.env.customKey && { domain: ".prototypr.io" }; - // jsCookie.set("prototypr_signupbar", "hide", cookieDomain); + const response = await fetch(`/api/subscribe`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + email: data.emailRequired, + listId: "et15895b31367", + }), + }); + setTryEmail(false); + setAlreadySubscribed(false); + setRegistered(false); + setError(false); - if (response.data.success) { - setRegistered(true); - setError(false); - setButtonText(intl.formatMessage({ id: "intro.button.updates" })); - } - }) - .catch(function (error) { - setRegistered(false); - setError(true); - setButtonText(intl.formatMessage({ id: "intro.button.updates" })); - }); + if (response.status == 200) { + setRegistered(true); + setButtonText(intl.formatMessage({ id: "intro.button.updates" })); + } else if (response.status == 204) { + setAlreadySubscribed(true); + setButtonText(intl.formatMessage({ id: "intro.button.updates" })); + }else if(response.status==202){ + setTryEmail(true); + setButtonText(intl.formatMessage({ id: "intro.button.updates" })); + } + else { + setRegistered(false); + setError(true); + setButtonText(intl.formatMessage({ id: "intro.button.updates" })); + } }; return ( <> -
- {registered == false ? ( +
+ {registered == false && tryEmail == false && alreadySubscribed == false ? ( <> ) : error ? ( <> -

+

{intl.formatMessage({ id: "signup.tip.again" })}  {" "}
🤖

@@ -66,18 +73,40 @@ export default function SignupHorizontal({ className, showNoSpam }) { {intl.formatMessage({ id: "signup.res.error" })}
+ ) : tryEmail ? ( +
+

+ Please check your email   +

+
+ You've tried to sign up before. There should be a confirmation email in your inbox from the first time you tried to signed up - if you can't find it, check your spam folder. +
+
+ ) : alreadySubscribed ? ( +
+

+ You've already subscribed to the newsletter +

+
+ Thanks for being a part of the community! 🎉 +
+
) : ( - <> -

+
+

{intl.formatMessage({ id: "signup.input.check" })}  {" "}
🎉

{intl.formatMessage({ id: "signup.input.click" })}
- +
)}

@@ -135,6 +164,12 @@ function HookForm(props) {