fix: wrap the newsletter unsubscription form in a Suspense component
Some checks failed
Deploy Next.js application / deploy (push) Failing after 10m4s

This commit is contained in:
Dorian Niemiec 2024-12-10 21:04:36 +01:00
parent e27af5ffc1
commit bd80881e27

View file

@ -1,14 +1,12 @@
"use client"; "use client";
import Newsletter from "@/components/shared/Newsletter"; import Newsletter from "@/components/shared/Newsletter";
import React, { useState } from "react"; import React, { Suspense, useState } from "react";
import { ReadonlyURLSearchParams, useSearchParams } from "next/navigation"; import { ReadonlyURLSearchParams, useSearchParams } from "next/navigation";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { useToast } from "@/components/ui/use-toast"; import { useToast } from "@/components/ui/use-toast";
import HCaptcha from "@hcaptcha/react-hcaptcha"; import HCaptcha from "@hcaptcha/react-hcaptcha";
const UnsubscribePage = (props: { const UnsubscribeForm = () => {
searchParams: Promise<{ id: string | undefined }>;
}) => {
const searchParams = useSearchParams() as ReadonlyURLSearchParams; const searchParams = useSearchParams() as ReadonlyURLSearchParams;
const unsubscribeId = searchParams.has("id") const unsubscribeId = searchParams.has("id")
? searchParams.get("id") ? searchParams.get("id")
@ -56,6 +54,35 @@ const UnsubscribePage = (props: {
} }
}; };
return (
<form
className="mx-auto text-center"
onSubmit={(e: React.FormEvent) => {
e.preventDefault();
setShowCaptcha(true);
}}
>
<Button
type="submit"
variant={"default"}
className="mt-2"
disabled={loading}
>
<div className="flex items-center justify-center">
<span className="tracking-tight font-semibold">Unsubscribe</span>
</div>
</Button>
{showCaptcha && (
<HCaptcha
sitekey={process.env.NEXT_PUBLIC_HCAPTCHA_SITE_KEY!}
onVerify={handleCaptchaVerify}
/>
)}
</form>
);
};
const UnsubscribePage = () => {
return ( return (
<section <section
id="vulnerabilities" id="vulnerabilities"
@ -68,30 +95,15 @@ const UnsubscribePage = (props: {
Are you sure to unsubscribe from the newsletter? You will no longer Are you sure to unsubscribe from the newsletter? You will no longer
receive updates from the newsletter. receive updates from the newsletter.
</p> </p>
<form <Suspense
className="mx-auto text-center" fallback={
onSubmit={(e: React.FormEvent) => { <p className="md:text-lg text-muted-foreground text-start mb-6">
e.preventDefault(); Loading unsubscription form...
setShowCaptcha(true); </p>
}} }
> >
<Button <UnsubscribeForm />
type="submit" </Suspense>
variant={"default"}
className="mt-2"
disabled={loading}
>
<div className="flex items-center justify-center">
<span className="tracking-tight font-semibold">Unsubscribe</span>
</div>
</Button>
{showCaptcha && (
<HCaptcha
sitekey={process.env.NEXT_PUBLIC_HCAPTCHA_SITE_KEY!}
onVerify={handleCaptchaVerify}
/>
)}
</form>
</section> </section>
); );
}; };