import React, { useState, useRef } from 'react'; import { Sparkles, ArrowRight, ArrowLeft, Mail, Zap } from 'lucide-react'; import { Button } from "@/components/ui/button"; import { motion, AnimatePresence } from 'framer-motion'; import UploadStep from '@/components/upload/UploadStep'; import ProductSelector from '@/components/products/ProductSelector'; import PromptEditor from '@/components/prompts/PromptEditor'; import SequenceViewer from '@/components/sequences/SequenceViewer'; export default function EmailSequenceGenerator() { const [step, setStep] = useState(1); const [uploadedFile, setUploadedFile] = useState(null); const [selectedProducts, setSelectedProducts] = useState([]); const [prompts, setPrompts] = useState({}); const [isGenerating, setIsGenerating] = useState(false); const [generationComplete, setGenerationComplete] = useState(false); const [generationRunId, setGenerationRunId] = useState(0); const generateButtonRef = useRef(null); const canProceedToStep2 = uploadedFile && selectedProducts.length > 0; const canProceedToStep3 = Object.keys(prompts).length > 0; const scrollToGenerateButton = () => { if (generateButtonRef.current) { generateButtonRef.current.scrollIntoView({ behavior: 'smooth', block: 'center' }); } }; const handleGenerate = async () => { if (!uploadedFile?.fileId || selectedProducts.length === 0 || Object.keys(prompts).length === 0) { alert('Please complete all steps before generating sequences.'); return; } // Save prompts to backend first, then start generation (avoids "No prompts found" race) try { const res = await fetch('/api/save-prompts', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ file_id: uploadedFile.fileId, prompts: prompts, products: selectedProducts.map(p => p.name) }) }); if (!res.ok) { const err = await res.json().catch(() => ({})); throw new Error(err.detail || res.statusText); } } catch (error) { console.error('Error saving prompts:', error); alert('Failed to save templates. Please try again.'); return; } setGenerationRunId((r) => r + 1); setStep(3); setIsGenerating(true); }; const handleGenerationComplete = () => { setIsGenerating(false); setGenerationComplete(true); }; const handleReset = () => { setStep(1); setUploadedFile(null); setSelectedProducts([]); setPrompts({}); setIsGenerating(false); setGenerationComplete(false); }; return (
{/* Header */}

SequenceAI

Personalized Email Outreach

{step > 1 && ( )}
{/* Progress Steps */}
{[ { num: 1, label: 'Upload & Select' }, { num: 2, label: 'Configure Prompts' }, { num: 3, label: 'Generate & Export' } ].map((s, idx) => (
= s.num ? 'bg-violet-600 text-white shadow-lg shadow-violet-200' : 'bg-slate-100 text-slate-400' } `}> {s.num}
{idx < 2 && (
s.num ? 'bg-violet-600' : 'bg-slate-200' }`} /> )} ))}
{/* Step 1: Upload & Product Selection */} {step === 1 && (

Upload Your Contacts

Import your Apollo CSV and select the products for your outreach campaign

setUploadedFile(null)} /> {uploadedFile && ( )}
)} {/* Step 2: Prompt Configuration */} {step === 2 && (

Customize Your Email Templates

Edit the prompt templates for each product. The AI will personalize these for each contact.

)} {/* Step 3: Generation & Results */} {step === 3 && (

{generationComplete ? 'Your Sequences Are Ready!' : 'Generating Personalized Emails'}

{generationComplete ? 'Review your sequences below and download when ready' : 'Our AI is crafting personalized emails for each contact' }

{!isGenerating && (
)}
)}
{/* Footer */} {/* Custom Scrollbar Styles */}
); }