From 35efde0db979a4cbaa609d8729694b2acf9ef541 Mon Sep 17 00:00:00 2001 From: Nareshkumar Rao Date: Wed, 2 Apr 2025 23:30:25 +0200 Subject: [PATCH] hopefully works now? --- src/app/contact/ContactComponent.tsx | 81 ------------------------ src/app/contact/action.ts | 4 ++ src/app/contact/page.tsx | 94 +++++++++++++++++++++++++--- 3 files changed, 89 insertions(+), 90 deletions(-) delete mode 100644 src/app/contact/ContactComponent.tsx create mode 100644 src/app/contact/action.ts diff --git a/src/app/contact/ContactComponent.tsx b/src/app/contact/ContactComponent.tsx deleted file mode 100644 index f287b3d..0000000 --- a/src/app/contact/ContactComponent.tsx +++ /dev/null @@ -1,81 +0,0 @@ -"use client"; - -import SubmitContact from "@/components/contact"; -import { useActionState } from "react"; -import ReCAPTCHA from "react-google-recaptcha"; - -export default function ContactComponent({ - recaptchaSiteKey, -}: { - recaptchaSiteKey: string | undefined; -}) { - const inputStyle = { - backgroundColor: "#111", - color: "#eee", - borderWidth: 0, - padding: "1rem", - }; - const [state, formAction, pending] = useActionState(SubmitContact, null); - - return ( - <> - Need to get in touch? -
-
-
- - - - {state && ( - - {"error" in state && state.error} - {"success" in state && "Submitted successfully!"} - - )} - - - - - ); -} diff --git a/src/app/contact/action.ts b/src/app/contact/action.ts new file mode 100644 index 0000000..a89f8bf --- /dev/null +++ b/src/app/contact/action.ts @@ -0,0 +1,4 @@ +"use server"; +export async function getReCaptchaSiteKey() { + return process.env.RECAPTCHA_SITE_KEY; +} diff --git a/src/app/contact/page.tsx b/src/app/contact/page.tsx index 439bf1f..810219b 100644 --- a/src/app/contact/page.tsx +++ b/src/app/contact/page.tsx @@ -1,12 +1,88 @@ -"use server"; +"use client"; -import ContactComponent from "./ContactComponent"; +import SubmitContact from "@/components/contact"; +import { useActionState, useEffect, useState } from "react"; +import ReCAPTCHA from "react-google-recaptcha"; +import { getReCaptchaSiteKey } from "./action"; -export default async function ContactPage() { - const recaptchaSiteKey = await getSiteKey(); - return ; -} - -async function getSiteKey() { - return process.env.RECAPTCHA_SITE_KEY; +export default function ContactPage() { + const [recaptchaSiteKey, setRecaptchaSiteKey] = useState( + undefined + ); + + useEffect(() => { + getReCaptchaSiteKey().then(setRecaptchaSiteKey); + }, []); + + const inputStyle = { + backgroundColor: "#111", + color: "#eee", + borderWidth: 0, + padding: "1rem", + }; + const [state, formAction, pending] = useActionState(SubmitContact, null); + + return recaptchaSiteKey == null ? ( + <>Loading... + ) : ( + <> + Need to get in touch? +
+
+
+ + + + {state && ( + + {"error" in state && state.error} + {"success" in state && "Submitted successfully!"} + + )} + + + + + ); }