Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions app/signup/EmailSignupForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,50 @@ import { useState } from "react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { useAnalytics } from "@/components/AnalyticsProvider";

export default function EmailSignupForm()
{
const [email, setEmail] = useState("");
const sessionID = useAnalytics()

function handleSubmit(event: React.FormEvent<HTMLFormElement>)
{
async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();

// Placeholder: wire up server action / API route later
console.log("Email submitted:", email);
const sourcePage = "Signup Page";

// Sending data to the API route
try {
const response = await fetch('/api/track', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
event_type: 'click_signup',
payload: {
email,
timestamp: new Date().toISOString(),
sourcePage,
sessionID,
},
}),
});

const result = await response.json();

if (response.ok) {
console.log('Email submitted successfully:', result);
alert('Thank you for subscribing!');
setEmail('');
} else {
console.error('Error:', result.error);
alert('Something went wrong. Please try again.');
}
} catch (error) {
console.error('Request failed', error);
alert('There was a problem with your submission. Please try again later.');
}
}

return (
Expand Down
56 changes: 28 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.