diff --git a/app/(root)/unsubscribe/page.tsx b/app/(root)/unsubscribe/page.tsx index bd016ea..cd4712b 100644 --- a/app/(root)/unsubscribe/page.tsx +++ b/app/(root)/unsubscribe/page.tsx @@ -13,14 +13,13 @@ const UnsubscribePage = ({ const { toast } = useToast(); const [loading, setLoading] = useState(false); const [showCaptcha, setShowCaptcha] = useState(false); - const [captchaToken, setCaptchaToken] = useState(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 (
{ e.preventDefault(); - onSubmit(); + setShowCaptcha(true); }} >