Compare commits
7 Commits
version_9
...
version_11
| Author | SHA1 | Date | |
|---|---|---|---|
| 8f96928c52 | |||
| 92065771c3 | |||
| 1792646e60 | |||
| 7d9e3379cc | |||
| a255161583 | |||
| ad8bbfecf6 | |||
| 73710d854b |
86
src/app/api/waitlist/route.ts
Normal file
86
src/app/api/waitlist/route.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
interface WaitlistEntry {
|
||||
email: string;
|
||||
instagram?: string;
|
||||
tiktok?: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
// In-memory storage for demonstration
|
||||
// In production, replace with actual database (MongoDB, PostgreSQL, etc.)
|
||||
const waitlistEntries: WaitlistEntry[] = [];
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const { email, instagram, tiktok } = body;
|
||||
|
||||
// Validate email
|
||||
if (!email || typeof email !== 'string' || !email.includes('@')) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Valid email is required' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// Check for duplicate email
|
||||
if (waitlistEntries.some(entry => entry.email === email)) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Email already registered' },
|
||||
{ status: 409 }
|
||||
);
|
||||
}
|
||||
|
||||
// Create waitlist entry
|
||||
const entry: WaitlistEntry = {
|
||||
email,
|
||||
instagram: instagram || undefined,
|
||||
tiktok: tiktok || undefined,
|
||||
createdAt: new Date().toISOString()
|
||||
};
|
||||
|
||||
// Add to in-memory storage
|
||||
waitlistEntries.push(entry);
|
||||
|
||||
// TODO: In production, save to database here
|
||||
// Example for MongoDB:
|
||||
// await db.collection('waitlist').insertOne(entry);
|
||||
|
||||
// TODO: Send confirmation email
|
||||
// Example:
|
||||
// await sendEmail({
|
||||
// to: email,
|
||||
// subject: 'Welcome to Clearance Waitlist',
|
||||
// template: 'waitlist-confirmation'
|
||||
// });
|
||||
|
||||
console.log('Waitlist entry created:', entry);
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: 'Successfully joined the waitlist',
|
||||
data: entry
|
||||
},
|
||||
{ status: 201 }
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('Waitlist API error:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Internal server error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function GET() {
|
||||
// Optional: Get all waitlist entries (add authentication in production)
|
||||
return NextResponse.json(
|
||||
{
|
||||
count: waitlistEntries.length,
|
||||
entries: waitlistEntries
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
}
|
||||
@@ -15,6 +15,9 @@ export default function RootLayout({
|
||||
}) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<head>
|
||||
<script async src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
||||
</head>
|
||||
<body className={inter.className}>{children}
|
||||
<script
|
||||
dangerouslySetInnerHTML={{
|
||||
|
||||
@@ -37,12 +37,26 @@ export default function LandingPage() {
|
||||
const [formStatus, setFormStatus] = useState<'idle' | 'success' | 'error'>('idle');
|
||||
const contactFormRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const handleWaitlistSubmit = (formData: WaitlistFormData) => {
|
||||
const handleWaitlistSubmit = async (formData: WaitlistFormData) => {
|
||||
try {
|
||||
const response = await fetch('/api/waitlist', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(formData),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
throw new Error(errorData.error || 'Failed to submit form');
|
||||
}
|
||||
|
||||
const responseData = await response.json();
|
||||
setWaitlistData([...waitlistData, formData]);
|
||||
setFormStatus('success');
|
||||
setTimeout(() => setFormStatus('idle'), 3000);
|
||||
console.log('Waitlist submission:', formData);
|
||||
console.log('Waitlist submission successful:', responseData);
|
||||
} catch (error) {
|
||||
setFormStatus('error');
|
||||
console.error('Error submitting waitlist form:', error);
|
||||
@@ -52,7 +66,6 @@ export default function LandingPage() {
|
||||
const handleJoinWaitlistClick = () => {
|
||||
if (contactFormRef.current) {
|
||||
contactFormRef.current.scrollIntoView({ behavior: 'smooth' });
|
||||
// Focus on the email input after scroll
|
||||
setTimeout(() => {
|
||||
const emailInput = contactFormRef.current?.querySelector('input[type="email"]') as HTMLInputElement;
|
||||
if (emailInput) {
|
||||
|
||||
Reference in New Issue
Block a user