Merge version_12 into main #14

Merged
bender merged 1 commits from version_12 into main 2026-03-06 08:11:44 +00:00

View File

@@ -1,32 +1,32 @@
import { NextRequest, NextResponse } from 'next/server';
import nodemailer from 'nodemailer';
interface WaitlistFormData {
interface WaitlistEntry {
email: string;
instagram?: string;
tiktok?: string;
createdAt: string;
}
// In-memory storage for demo purposes. Replace with database in production.
const waitlistDatabase: WaitlistFormData[] = [];
// Configure your email service here
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST || 'smtp.gmail.com',
port: parseInt(process.env.SMTP_PORT || '587'),
secure: process.env.SMTP_SECURE === 'true', // true for 465, false for other ports
secure: process.env.SMTP_SECURE === 'true',
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASSWORD,
},
});
const waitlistEntries: WaitlistEntry[] = [];
export async function POST(request: NextRequest) {
try {
const body: WaitlistFormData = await request.json();
const body = await request.json();
const { email, instagram, tiktok } = body;
// Validate email
if (!body.email || !body.email.includes('@')) {
if (!email || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
return NextResponse.json(
{ error: 'Invalid email address' },
{ status: 400 }
@@ -34,110 +34,91 @@ export async function POST(request: NextRequest) {
}
// Check if email already exists
if (waitlistDatabase.some(entry => entry.email === body.email)) {
if (waitlistEntries.some(entry => entry.email === email)) {
return NextResponse.json(
{ error: 'Email already on waitlist' },
{ status: 409 }
);
}
// Add to database
waitlistDatabase.push(body);
// Create waitlist entry
const entry: WaitlistEntry = {
email,
instagram: instagram || undefined,
tiktok: tiktok || undefined,
createdAt: new Date().toISOString(),
};
waitlistEntries.push(entry);
// Send confirmation email to user
const userEmailContent = `
<html>
<body style="font-family: Arial, sans-serif; color: #333;">
<div style="max-width: 600px; margin: 0 auto; padding: 20px;">
<h1 style="color: #0d5238;">Welcome to Clearance Waitlist!</h1>
<p>Hi ${body.email.split('@')[0]},</p>
<p>Thank you for joining our waitlist. You're now part of an exclusive group of creators and agencies who will get early access to Clearance.</p>
<p><strong>What to expect:</strong></p>
<ul>
<li>Early access to Clearance platform</li>
<li>Lifetime discount for early adopters</li>
<li>1-on-1 onboarding call with our team</li>
<li>Direct access to our founder for feedback</li>
</ul>
${body.instagram ? `<p><strong>Instagram:</strong> ${body.instagram}</p>` : ''}
${body.tiktok ? `<p><strong>TikTok:</strong> ${body.tiktok}</p>` : ''}
<p>We'll be in touch soon with more details!</p>
<p>Best regards,<br/>The Clearance Team</p>
</div>
</body>
</html>
const userEmailHtml = `
<div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto;">
<h2 style="color: #333;">Welcome to Clearance Waitlist!</h2>
<p>Hi ${email.split('@')[0]},</p>
<p>Thank you for joining the Clearance waitlist! We're excited to have you on board.</p>
<p>We'll be reaching out soon with early access to our platform. In the meantime, here's what you can expect:</p>
<ul>
<li>Exclusive early access before our public launch</li>
<li>Lifetime discounts as an early adopter</li>
<li>1-on-1 onboarding support from our team</li>
</ul>
<p>If you have any questions, feel free to reply to this email.</p>
<p>Best regards,<br/>The Clearance Team</p>
</div>
`;
// Send notification email to admin
const adminEmailContent = `
<html>
<body style="font-family: Arial, sans-serif; color: #333;">
<div style="max-width: 600px; margin: 0 auto; padding: 20px;">
<h1>New Waitlist Submission</h1>
<p><strong>Email:</strong> ${body.email}</p>
${body.instagram ? `<p><strong>Instagram:</strong> ${body.instagram}</p>` : ''}
${body.tiktok ? `<p><strong>TikTok:</strong> ${body.tiktok}</p>` : ''}
<p><strong>Submitted at:</strong> ${new Date().toISOString()}</p>
<p><strong>Total waitlist entries:</strong> ${waitlistDatabase.length}</p>
</div>
</body>
</html>
`;
// Send emails in parallel
const emailPromises = [];
// Send confirmation to user
if (process.env.SMTP_USER) {
emailPromises.push(
transporter.sendMail({
from: process.env.SMTP_FROM || process.env.SMTP_USER,
to: body.email,
subject: 'Welcome to Clearance Waitlist - Confirmation',
html: userEmailContent,
})
);
// Send notification to admin
emailPromises.push(
transporter.sendMail({
from: process.env.SMTP_FROM || process.env.SMTP_USER,
to: process.env.ADMIN_EMAIL || process.env.SMTP_USER,
subject: 'New Waitlist Submission',
html: adminEmailContent,
})
);
try {
await transporter.sendMail({
from: process.env.SMTP_FROM || process.env.SMTP_USER,
to: email,
subject: 'Welcome to Clearance Waitlist - Early Access Confirmed',
html: userEmailHtml,
});
} catch (emailError) {
console.error('Error sending confirmation email:', emailError);
// Continue even if email fails - user still added to waitlist
}
// Wait for all emails to send
if (emailPromises.length > 0) {
await Promise.all(emailPromises);
// Send notification email to admin
const adminEmailHtml = `
<div style="font-family: Arial, sans-serif;">
<h2>New Waitlist Submission</h2>
<p><strong>Email:</strong> ${email}</p>
<p><strong>Instagram:</strong> ${instagram || 'Not provided'}</p>
<p><strong>TikTok:</strong> ${tiktok || 'Not provided'}</p>
<p><strong>Submitted:</strong> ${new Date().toLocaleString()}</p>
</div>
`;
try {
await transporter.sendMail({
from: process.env.SMTP_FROM || process.env.SMTP_USER,
to: process.env.ADMIN_EMAIL || process.env.SMTP_USER,
subject: `New Clearance Waitlist Submission: ${email}`,
html: adminEmailHtml,
});
} catch (emailError) {
console.error('Error sending admin notification:', emailError);
// Continue even if email fails
}
return NextResponse.json(
{
success: true,
message: 'Successfully added to waitlist',
data: {
email: body.email,
timestamp: new Date().toISOString(),
},
},
{ success: true, message: 'Successfully joined waitlist', entry },
{ status: 201 }
);
} catch (error) {
console.error('Waitlist submission error:', error);
return NextResponse.json(
{ error: 'Failed to submit waitlist form' },
{ error: 'Failed to process submission' },
{ status: 500 }
);
}
}
export async function GET() {
// Admin endpoint to view waitlist (add authentication in production)
return NextResponse.json({
total: waitlistDatabase.length,
entries: waitlistDatabase,
count: waitlistEntries.length,
entries: waitlistEntries,
});
}