From 6d520fb1e7aa8014dcbf7b07f6c6883cbc36312c Mon Sep 17 00:00:00 2001 From: Sergey Mankovsky Date: Wed, 5 Feb 2025 01:25:52 +0100 Subject: [PATCH] Post event form --- www/app/webinars/[title]/page.tsx | 126 ++++++++++++++++++++++++++++-- 1 file changed, 119 insertions(+), 7 deletions(-) diff --git a/www/app/webinars/[title]/page.tsx b/www/app/webinars/[title]/page.tsx index 33d2bfe0..977d32d8 100644 --- a/www/app/webinars/[title]/page.tsx +++ b/www/app/webinars/[title]/page.tsx @@ -8,6 +8,27 @@ import dynamic from "next/dynamic"; const WherebyEmbed = dynamic(() => import("../../lib/WherebyEmbed"), { ssr: false, }); +import { FormEvent } from "react"; +import { Input, FormControl } from "@chakra-ui/react"; +import { VStack } from "@chakra-ui/react"; +import { Alert, AlertIcon } from "@chakra-ui/react"; +import { Text } from "@chakra-ui/react"; +import { Button } from "@chakra-ui/react"; + +type FormData = { + name: string; + email: string; + company: string; + role: string; +}; + +const FORM_ID = "1hhtO6x9XacRwSZS-HRBLN9Ca_7iGZVpNX3_EC4I1uzc"; +const FORM_FIELDS = { + name: "entry.1500809875", + email: "entry.1359095250", + company: "entry.1851914159", + role: "entry.1022377935", +}; export type WebinarDetails = { params: { @@ -88,6 +109,39 @@ export default function WebinarPage(details: WebinarDetails) { return () => clearInterval(timer); }, [webinar]); + const [formSubmitted, setFormSubmitted] = useState(false); + const [formData, setFormData] = useState({ + name: "", + email: "", + company: "", + role: "", + }); + + const handleSubmit = async (e: FormEvent) => { + e.preventDefault(); + + try { + const submitUrl = `https://docs.google.com/forms/d/${FORM_ID}/formResponse`; + const data = Object.entries(FORM_FIELDS) + .map(([key, value]) => { + return `${value}=${formData[key as keyof FormData]}`; + }) + .join("&"); + const response = await fetch(submitUrl, { + method: "POST", + mode: "no-cors", + headers: { + "Content-Type": "application/x-www-form-urlencoded", + }, + body: data, + }); + + setFormSubmitted(true); + } catch (error) { + console.error("Error submitting form:", error); + } + }; + if (status === WebinarStatus.Live) { return <>{roomUrl && }; } @@ -195,13 +249,71 @@ export default function WebinarPage(details: WebinarDetails) {

To Watch This Webinar, Fill Out the Brief Form Below:

- - Get instant access - + + {formSubmitted ? ( + + + Thanks for signing up! The webinar recording will be ready + soon, and we'll email you as soon as it's available. Stay + tuned! + + + ) : ( +
+ + + + setFormData({ ...formData, name: e.target.value }) + } + /> + + + + setFormData({ ...formData, email: e.target.value }) + } + /> + + + setFormData({ ...formData, company: e.target.value }) + } + /> + + setFormData({ ...formData, role: e.target.value }) + } + /> + + +
+ )}