From 004ecc5c601b9bbe9d10bd5ebd22797ebe3caa80 Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Mon, 9 Sep 2024 15:30:24 +0200 Subject: [PATCH] fix: add an indication that the newsletter subscriber is already subscribed --- components/shared/Newsletter.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/components/shared/Newsletter.tsx b/components/shared/Newsletter.tsx index e23f7cc..b4d4386 100644 --- a/components/shared/Newsletter.tsx +++ b/components/shared/Newsletter.tsx @@ -16,7 +16,7 @@ const happyMonkey = Happy_Monkey({ const Newsletter = () => { const [submission, setSubmission] = useState< - "idle" | "loading" | "success" | "error" + "idle" | "loading" | "success" | "already" | "error" >("idle"); const [input, setInput] = useState(""); const [captchaToken, setCaptchaToken] = useState(null); @@ -49,6 +49,9 @@ const Newsletter = () => { if (response.ok) { setSubmission("success"); setInput(""); + } else if (response.status == 409) { + setSubmission("already"); + setInput(""); } else { setSubmission("error"); } @@ -120,6 +123,11 @@ const Newsletter = () => { 🎉 Subscribed successfully...

)} + {submission === "already" && ( +

+ 🙏 You're already subscribed... +

+ )} {submission === "error" && (

😥 Something went wrong...