fix: add an indication that the newsletter subscriber is already subscribed
Some checks are pending
Deploy Next.js application / deploy (push) Waiting to run

This commit is contained in:
Dorian Niemiec 2024-09-09 15:30:24 +02:00
parent a5f89d33af
commit 004ecc5c60

View file

@ -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<string>("");
const [captchaToken, setCaptchaToken] = useState<string | null>(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...
</p>
)}
{submission === "already" && (
<p className="dark:invert text-sm text-center text-green-500">
🙏 You&apos;re already subscribed...
</p>
)}
{submission === "error" && (
<p className="dark:invert text-sm text-center text-red-500">
😥 Something went wrong...