fix: wrap the newsletter unsubscription form in a Suspense component
Some checks failed
Deploy Next.js application / deploy (push) Failing after 10m4s
Some checks failed
Deploy Next.js application / deploy (push) Failing after 10m4s
This commit is contained in:
parent
e27af5ffc1
commit
bd80881e27
1 changed files with 39 additions and 27 deletions
|
@ -1,14 +1,12 @@
|
|||
"use client";
|
||||
import Newsletter from "@/components/shared/Newsletter";
|
||||
import React, { useState } from "react";
|
||||
import React, { Suspense, useState } from "react";
|
||||
import { ReadonlyURLSearchParams, useSearchParams } from "next/navigation";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useToast } from "@/components/ui/use-toast";
|
||||
import HCaptcha from "@hcaptcha/react-hcaptcha";
|
||||
|
||||
const UnsubscribePage = (props: {
|
||||
searchParams: Promise<{ id: string | undefined }>;
|
||||
}) => {
|
||||
const UnsubscribeForm = () => {
|
||||
const searchParams = useSearchParams() as ReadonlyURLSearchParams;
|
||||
const unsubscribeId = searchParams.has("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 (
|
||||
<section
|
||||
id="vulnerabilities"
|
||||
|
@ -68,30 +95,15 @@ const UnsubscribePage = (props: {
|
|||
Are you sure to unsubscribe from the newsletter? You will no longer
|
||||
receive updates from the newsletter.
|
||||
</p>
|
||||
<form
|
||||
className="mx-auto text-center"
|
||||
onSubmit={(e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setShowCaptcha(true);
|
||||
}}
|
||||
<Suspense
|
||||
fallback={
|
||||
<p className="md:text-lg text-muted-foreground text-start mb-6">
|
||||
Loading unsubscription form...
|
||||
</p>
|
||||
}
|
||||
>
|
||||
<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>
|
||||
<UnsubscribeForm />
|
||||
</Suspense>
|
||||
</section>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue