fix: unsubscribe from the newsletter right after solving the CAPTCHA on the unsubscription form
Some checks failed
Deploy Next.js application / deploy (push) Has been cancelled
Some checks failed
Deploy Next.js application / deploy (push) Has been cancelled
This commit is contained in:
parent
004ecc5c60
commit
bdc679376d
1 changed files with 6 additions and 13 deletions
|
@ -13,14 +13,13 @@ const UnsubscribePage = ({
|
|||
const { toast } = useToast();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [showCaptcha, setShowCaptcha] = useState(false);
|
||||
const [captchaToken, setCaptchaToken] = useState<string | null>(null);
|
||||
|
||||
const onSubmit = async () => {
|
||||
if (!captchaToken) {
|
||||
setShowCaptcha(true);
|
||||
return;
|
||||
}
|
||||
const handleCaptchaVerify = async (token: string) => {
|
||||
setShowCaptcha(false);
|
||||
await submit(token); // Trigger form submission after captcha is verified
|
||||
};
|
||||
|
||||
const submit = async (captchaToken: string) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await fetch("/api/unsubscribe", {
|
||||
|
@ -33,7 +32,6 @@ const UnsubscribePage = ({
|
|||
});
|
||||
|
||||
if (res.ok) {
|
||||
setCaptchaToken(null); // Reset captcha token after successful submission
|
||||
toast({
|
||||
description: "Unsubscribed successfully."
|
||||
});
|
||||
|
@ -55,11 +53,6 @@ const UnsubscribePage = ({
|
|||
}
|
||||
};
|
||||
|
||||
const handleCaptchaVerify = async (token: string) => {
|
||||
setCaptchaToken(token);
|
||||
await onSubmit(); // Trigger form submission after captcha is verified
|
||||
};
|
||||
|
||||
return (
|
||||
<section
|
||||
id="vulnerabilities"
|
||||
|
@ -76,7 +69,7 @@ const UnsubscribePage = ({
|
|||
className="mx-auto text-center"
|
||||
onSubmit={(e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
onSubmit();
|
||||
setShowCaptcha(true);
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
|
|
Loading…
Reference in a new issue