Skip to content

Commit 2d09f90

Browse files
Implement complete email capture system with Supabase and Resend integration
✨ Navigation Enhancements: - Expanded navigation to full width with edge-to-edge design - Added Auto Agent Flow and AI Developer Academy external link buttons - Updated styling for better secondary surface colors in light/dark mode - Added proper spacing and responsive behavior for new nav items 📧 Email Capture System: - Created ScrollEmailModal component with scroll trigger after 3rd component - Implemented beautiful modal design with benefits list and form validation - Added proper success/error states with animated transitions 🔗 Supabase Integration: - Created /api/subscribe API route with full error handling - Added email_subscribers table schema with RLS policies - Implemented email confirmation flow with Supabase Auth - Created /confirm-email page with proper Suspense boundaries 📬 Resend Email Integration: - Added beautifully styled welcome email template with HTML/CSS - Integrated dual email system: Supabase confirmation + Resend welcome - Added proper error handling and fallback mechanisms - Included branded email design with call-to-action buttons 🛠 Technical Improvements: - Made main page client-side to support function props - Added proper TypeScript types for all email functionality - Updated environment variables example with Resend API key - Fixed build issues with Suspense boundaries and linting 🎨 UX/UI Features: - Scroll-triggered modal appears after user scrolls past Features section - Modal includes gift icon, benefits list, and trust indicators - Success state with celebration and next steps - Responsive design for all screen sizes - Proper accessibility with ARIA labels and keyboard navigation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent f07cb0e commit 2d09f90

File tree

8 files changed

+759
-7
lines changed

8 files changed

+759
-7
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ NEXT_PUBLIC_SUPABASE_URL=your_supabase_url
33
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
44
SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key
55

6+
# Email Services
7+
RESEND_API_KEY=your_resend_api_key
8+
69
# Sentry Error Tracking
710
SENTRY_DSN=your_sentry_dsn
811
NEXT_PUBLIC_SENTRY_DSN=your_sentry_dsn

package-lock.json

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/api/subscribe/route.ts

Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
import { NextRequest, NextResponse } from 'next/server';
2+
import { supabase } from '@/lib/supabase';
3+
import { Resend } from 'resend';
4+
5+
const resend = new Resend(process.env.RESEND_API_KEY);
6+
7+
export async function POST(request: NextRequest) {
8+
try {
9+
const { email } = await request.json();
10+
11+
if (!email || !email.includes('@')) {
12+
return NextResponse.json(
13+
{ error: 'Valid email address is required' },
14+
{ status: 400 }
15+
);
16+
}
17+
18+
// Check if email already exists
19+
const { data: existingSubscriber } = await supabase
20+
.from('email_subscribers')
21+
.select('email')
22+
.eq('email', email)
23+
.single();
24+
25+
if (existingSubscriber) {
26+
return NextResponse.json(
27+
{ error: 'Email already subscribed' },
28+
{ status: 409 }
29+
);
30+
}
31+
32+
// Insert new subscriber into Supabase
33+
const { data: subscriber, error: supabaseError } = await supabase
34+
.from('email_subscribers')
35+
.insert({
36+
email,
37+
source: 'scroll_modal',
38+
metadata: {
39+
user_agent: request.headers.get('user-agent'),
40+
timestamp: new Date().toISOString(),
41+
}
42+
})
43+
.select()
44+
.single();
45+
46+
if (supabaseError) {
47+
console.error('Supabase error:', supabaseError);
48+
return NextResponse.json(
49+
{ error: 'Failed to subscribe' },
50+
{ status: 500 }
51+
);
52+
}
53+
54+
// Send Supabase email confirmation (this will trigger Supabase auth email)
55+
const { error: authError } = await supabase.auth.signInWithOtp({
56+
email,
57+
options: {
58+
emailRedirectTo: `${request.nextUrl.origin}/confirm-email`,
59+
data: {
60+
source: 'scroll_modal'
61+
}
62+
}
63+
});
64+
65+
if (authError) {
66+
console.error('Supabase auth error:', authError);
67+
// Continue even if auth email fails, we'll still send the welcome email
68+
}
69+
70+
// Send welcome email via Resend
71+
if (process.env.RESEND_API_KEY) {
72+
try {
73+
await resend.emails.send({
74+
75+
to: email,
76+
subject: '🎉 Welcome! Your Free Resources Are Here',
77+
html: generateWelcomeEmailHTML(),
78+
});
79+
} catch (resendError) {
80+
console.error('Resend error:', resendError);
81+
// Don't fail the request if email sending fails
82+
}
83+
}
84+
85+
return NextResponse.json({
86+
success: true,
87+
message: 'Successfully subscribed! Check your email for confirmation and resources.',
88+
subscriber
89+
});
90+
91+
} catch (error) {
92+
console.error('Subscription error:', error);
93+
return NextResponse.json(
94+
{ error: 'Internal server error' },
95+
{ status: 500 }
96+
);
97+
}
98+
}
99+
100+
function generateWelcomeEmailHTML(): string {
101+
return `
102+
<!DOCTYPE html>
103+
<html lang="en">
104+
<head>
105+
<meta charset="UTF-8">
106+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
107+
<title>Welcome to Our Community!</title>
108+
<style>
109+
body {
110+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
111+
line-height: 1.6;
112+
color: #333;
113+
max-width: 600px;
114+
margin: 0 auto;
115+
padding: 20px;
116+
background-color: #f9fafb;
117+
}
118+
.container {
119+
background: white;
120+
border-radius: 12px;
121+
padding: 40px;
122+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
123+
}
124+
.header {
125+
text-align: center;
126+
margin-bottom: 30px;
127+
}
128+
.logo {
129+
width: 80px;
130+
height: 80px;
131+
background: linear-gradient(135deg, #da3229 0%, #e0392f 100%);
132+
border-radius: 16px;
133+
margin: 0 auto 20px;
134+
display: flex;
135+
align-items: center;
136+
justify-content: center;
137+
font-size: 30px;
138+
color: white;
139+
font-weight: bold;
140+
}
141+
.title {
142+
font-size: 28px;
143+
font-weight: bold;
144+
color: #1f2937;
145+
margin: 0;
146+
}
147+
.subtitle {
148+
font-size: 16px;
149+
color: #6b7280;
150+
margin: 10px 0 0 0;
151+
}
152+
.content {
153+
margin: 30px 0;
154+
}
155+
.benefit {
156+
display: flex;
157+
align-items: center;
158+
margin: 15px 0;
159+
padding: 15px;
160+
background: #f3f4f6;
161+
border-radius: 8px;
162+
}
163+
.benefit-icon {
164+
width: 24px;
165+
height: 24px;
166+
background: #e0392f;
167+
border-radius: 50%;
168+
margin-right: 15px;
169+
display: flex;
170+
align-items: center;
171+
justify-content: center;
172+
color: white;
173+
font-weight: bold;
174+
}
175+
.cta-button {
176+
display: inline-block;
177+
background: linear-gradient(135deg, #da3229 0%, #e0392f 100%);
178+
color: white;
179+
padding: 16px 32px;
180+
border-radius: 12px;
181+
text-decoration: none;
182+
font-weight: 600;
183+
text-align: center;
184+
margin: 20px 0;
185+
}
186+
.footer {
187+
text-align: center;
188+
margin-top: 40px;
189+
padding-top: 20px;
190+
border-top: 1px solid #e5e7eb;
191+
font-size: 14px;
192+
color: #6b7280;
193+
}
194+
.links {
195+
margin: 20px 0;
196+
}
197+
.links a {
198+
color: #e0392f;
199+
text-decoration: none;
200+
margin: 0 10px;
201+
}
202+
</style>
203+
</head>
204+
<body>
205+
<div class="container">
206+
<div class="header">
207+
<div class="logo">T</div>
208+
<h1 class="title">Welcome to the Community! 🎉</h1>
209+
<p class="subtitle">Your free resources are ready</p>
210+
</div>
211+
212+
<div class="content">
213+
<p>Hi there!</p>
214+
215+
<p>Welcome to our developer community! We're excited to have you on board. As promised, here are your exclusive free resources:</p>
216+
217+
<div class="benefit">
218+
<div class="benefit-icon">✨</div>
219+
<div>
220+
<strong>Free Automation Templates</strong><br>
221+
Ready-to-use n8n workflows for common business processes
222+
</div>
223+
</div>
224+
225+
<div class="benefit">
226+
<div class="benefit-icon">🎓</div>
227+
<div>
228+
<strong>Exclusive Course Discounts</strong><br>
229+
Get 20% off all our premium automation courses
230+
</div>
231+
</div>
232+
233+
<div class="benefit">
234+
<div class="benefit-icon">🚀</div>
235+
<div>
236+
<strong>Early Access Content</strong><br>
237+
Be the first to see new tutorials and advanced techniques
238+
</div>
239+
</div>
240+
241+
<center>
242+
<a href="https://autoagentflow.com/" class="cta-button">
243+
Explore Auto Agent Flow →
244+
</a>
245+
</center>
246+
247+
<p>You'll also receive weekly tips, tutorials, and updates about the latest in automation and AI development.</p>
248+
249+
<div class="links">
250+
<a href="https://academy.tesseract.nexus/">AI Developer Academy</a> |
251+
<a href="https://autoagentflow.com/">Auto Agent Flow</a>
252+
</div>
253+
</div>
254+
255+
<div class="footer">
256+
<p>Thanks for joining our community of 1000+ developers!</p>
257+
<p>If you have any questions, just reply to this email.</p>
258+
<p style="margin-top: 20px;">
259+
<a href="#" style="color: #6b7280; font-size: 12px;">Unsubscribe</a>
260+
</p>
261+
</div>
262+
</div>
263+
</body>
264+
</html>
265+
`;
266+
}

0 commit comments

Comments
 (0)