Skip to content
This repository was archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
feat: add success page
Browse files Browse the repository at this point in the history
  • Loading branch information
tobySolutions committed Apr 14, 2024
1 parent e5c39a3 commit ed9bdb9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
"use client";
import { useCallback, useState } from "react";
import Form from "../../ui/form/Form";
import { useFormState } from "react-dom";
import { handleSubmit } from "@/app/server";

const initialState = {
email: "",
};

function HeroSection() {
const [showForm, setShowForm] = useState(false);
const [state, formAction] = useFormState(handleSubmit, initialState);

const handleWaitlistForm = useCallback(() => {
setShowForm(true);
Expand All @@ -21,20 +28,18 @@ function HeroSection() {
</p>
</div>

{showForm === false && (
<div className="mt-5">
<button
onClick={handleWaitlistForm}
className="font-montserrat text-sm bg-buttonBg py-2 w-3/12 rounded font-medium hover:bg-buttonBgHover hover:text-black transition-transform duration-500 sm:w-full"
>
Try Akeru
</button>
</div>
)}
<div className="mt-5">
<button
onClick={handleWaitlistForm}
className="font-montserrat text-sm bg-buttonBg py-2 w-3/12 rounded font-medium hover:bg-buttonBgHover hover:text-black transition-transform duration-500 sm:w-full"
>
Try Akeru
</button>
</div>

{showForm && (
<div className="w-full mt-5">
<Form />
<Form formAction={formAction} />
</div>
)}
</section>
Expand Down
8 changes: 6 additions & 2 deletions packages/akeru-frontend/app/components/ui/form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import { useCallback, useState } from "react";
import FormInput from "./FormInput";
import { handleSubmit } from "@/app/server";

function Form() {
type FormProps = {
formAction: (payload: FormData) => void;
};

function Form({ formAction}: FormProps) {
return (
<form className="w-full" action={handleSubmit}>
<form className="w-full" action={formAction}>
<div className="mt-2.5 tablet_max:mt-2 mobile_lg:mt-3.5">
<FormInput
type="email"
Expand Down
10 changes: 8 additions & 2 deletions packages/akeru-frontend/app/server.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
"use server";

export const handleSubmit = async (formData: FormData) => {
import { redirect } from "next/navigation";

export const handleSubmit = async (
prevState: { email: string },
formData: FormData
) => {
const url = process.env.NEXT_GOOGLE_SHEETS_API!;
const rawFormData = { email: formData.get("emailAddress") };
let rawFormData = { email: formData.get("emailAddress") };

try {
const response = await fetch(url, {
Expand All @@ -24,4 +29,5 @@ export const handleSubmit = async (formData: FormData) => {
} catch (error) {
console.error("Error:", error);
}
redirect("/success");
};
11 changes: 11 additions & 0 deletions packages/akeru-frontend/app/success/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default function Success() {
return (
<main className="flex min-h-screen justify-center pt-40 text-center">
<div className="sm:w-[95%]">
<p className="text-7xl lg:text-6xl air:text-5xl md:text-4xl sm:text-3xl font-extrabold ">
Thank you for registering
</p>
</div>
</main>
);
}

0 comments on commit ed9bdb9

Please sign in to comment.