import { useEffect } from "react"; import { useMutation, useRouter } from "blitz"; import { useForm } from "react-hook-form"; import * as Panelbear from "@panelbear/panelbear-js"; import joinWaitlist from "../mutations/join-waitlist"; type Form = { email: string; }; export default function CTAForm() { const router = useRouter(); const [joinWaitlistMutation] = useMutation(joinWaitlist); const { handleSubmit, register, setFocus, formState: { isSubmitted }, } = useForm
(); useEffect(() => { if (typeof router.query.join_waitlist !== "undefined") { setFocus("email"); router.replace("/"); } }, []); const onSubmit = handleSubmit(async ({ email }) => { if (isSubmitted) { return; } Panelbear.track("join-waitlist"); return joinWaitlistMutation({ email }); }); return ( {isSubmitted ? (

You're on the list! We will be in touch soon

) : (
)}
); }