File size: 15,202 Bytes
3fdd55d 5301ae9 952e292 3fdd55d 5301ae9 3fdd55d 5301ae9 7a74d14 5301ae9 7a74d14 5301ae9 7a74d14 5301ae9 7a74d14 5301ae9 7a74d14 952e292 7a74d14 5301ae9 3fdd55d 5301ae9 3fdd55d 5301ae9 952e292 5301ae9 5df542b 5301ae9 5df542b 5301ae9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | 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 (
<div className="min-h-screen bg-gradient-to-br from-slate-50 via-white to-violet-50">
{/* Header */}
<header className="border-b border-slate-100 bg-white/80 backdrop-blur-sm sticky top-0 z-50">
<div className="max-w-6xl mx-auto px-6 py-4">
<div className="flex items-center justify-between">
<div className="flex items-center gap-3">
<div className="h-10 w-10 rounded-xl bg-gradient-to-br from-violet-600 to-purple-600
flex items-center justify-center shadow-lg shadow-violet-200">
<Zap className="h-5 w-5 text-white" />
</div>
<div>
<h1 className="font-bold text-slate-800 text-lg">SequenceAI</h1>
<p className="text-xs text-slate-500">Personalized Email Outreach</p>
</div>
</div>
{step > 1 && (
<Button
variant="ghost"
onClick={handleReset}
className="text-slate-500 hover:text-slate-700"
>
Start Over
</Button>
)}
</div>
</div>
</header>
<main className="max-w-6xl mx-auto px-6 py-8">
{/* Progress Steps */}
<div className="mb-10">
<div className="flex items-center justify-center gap-4">
{[
{ num: 1, label: 'Upload & Select' },
{ num: 2, label: 'Configure Prompts' },
{ num: 3, label: 'Generate & Export' }
].map((s, idx) => (
<React.Fragment key={s.num}>
<div className="flex items-center gap-2">
<div className={`
h-8 w-8 rounded-full flex items-center justify-center text-sm font-semibold
transition-all duration-300
${step >= s.num
? 'bg-violet-600 text-white shadow-lg shadow-violet-200'
: 'bg-slate-100 text-slate-400'
}
`}>
{s.num}
</div>
<span className={`text-sm font-medium hidden sm:block ${
step >= s.num ? 'text-slate-800' : 'text-slate-400'
}`}>
{s.label}
</span>
</div>
{idx < 2 && (
<div className={`h-0.5 w-12 rounded-full transition-colors duration-300 ${
step > s.num ? 'bg-violet-600' : 'bg-slate-200'
}`} />
)}
</React.Fragment>
))}
</div>
</div>
<AnimatePresence mode="wait">
{/* Step 1: Upload & Product Selection */}
{step === 1 && (
<motion.div
key="step1"
initial={{ opacity: 0, x: -20 }}
animate={{ opacity: 1, x: 0 }}
exit={{ opacity: 0, x: 20 }}
transition={{ duration: 0.3 }}
className="space-y-8"
>
<div className="text-center mb-8">
<h2 className="text-2xl font-bold text-slate-800 mb-2">
Upload Your Contacts
</h2>
<p className="text-slate-500">
Import your Apollo CSV and select the products for your outreach campaign
</p>
</div>
<UploadStep
onFileUploaded={setUploadedFile}
uploadedFile={uploadedFile}
onRemoveFile={() => setUploadedFile(null)}
/>
{uploadedFile && (
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: 0.2 }}
>
<ProductSelector
selectedProducts={selectedProducts}
onProductsChange={setSelectedProducts}
/>
</motion.div>
)}
<div className="flex justify-end pt-4">
<Button
onClick={() => setStep(2)}
disabled={!canProceedToStep2}
className="bg-violet-600 hover:bg-violet-700 px-6"
>
Continue to Prompts
<ArrowRight className="h-4 w-4 ml-2" />
</Button>
</div>
</motion.div>
)}
{/* Step 2: Prompt Configuration */}
{step === 2 && (
<motion.div
key="step2"
initial={{ opacity: 0, x: -20 }}
animate={{ opacity: 1, x: 0 }}
exit={{ opacity: 0, x: 20 }}
transition={{ duration: 0.3 }}
className="space-y-8"
>
<div className="text-center mb-8">
<h2 className="text-2xl font-bold text-slate-800 mb-2">
Customize Your Email Templates
</h2>
<p className="text-slate-500">
Edit the prompt templates for each product. The AI will personalize these for each contact.
</p>
</div>
<PromptEditor
selectedProducts={selectedProducts}
prompts={prompts}
onPromptsChange={setPrompts}
onSaveComplete={scrollToGenerateButton}
/>
<div className="flex justify-between pt-4">
<Button
variant="outline"
onClick={() => setStep(1)}
className="px-6"
>
<ArrowLeft className="h-4 w-4 mr-2" />
Back
</Button>
<Button
ref={generateButtonRef}
onClick={handleGenerate}
disabled={!canProceedToStep3}
className="bg-gradient-to-r from-violet-600 to-purple-600 hover:from-violet-700
hover:to-purple-700 px-8 shadow-lg shadow-violet-200"
>
<Sparkles className="h-4 w-4 mr-2" />
Generate Sequences
</Button>
</div>
</motion.div>
)}
{/* Step 3: Generation & Results */}
{step === 3 && (
<motion.div
key="step3"
initial={{ opacity: 0, x: -20 }}
animate={{ opacity: 1, x: 0 }}
exit={{ opacity: 0, x: 20 }}
transition={{ duration: 0.3 }}
className="space-y-8"
>
<div className="text-center mb-8">
<h2 className="text-2xl font-bold text-slate-800 mb-2">
{generationComplete ? 'Your Sequences Are Ready!' : 'Generating Personalized Emails'}
</h2>
<p className="text-slate-500">
{generationComplete
? 'Review your sequences below and download when ready'
: 'Our AI is crafting personalized emails for each contact'
}
</p>
</div>
<SequenceViewer
isGenerating={isGenerating}
generationRunId={generationRunId}
contactCount={uploadedFile?.contactCount || 50}
selectedProducts={selectedProducts}
uploadedFile={uploadedFile}
prompts={prompts}
onComplete={handleGenerationComplete}
/>
{!isGenerating && (
<div className="flex justify-start pt-4">
<Button
variant="outline"
onClick={() => setStep(2)}
className="px-6"
>
<ArrowLeft className="h-4 w-4 mr-2" />
Edit Templates
</Button>
</div>
)}
</motion.div>
)}
</AnimatePresence>
</main>
{/* Footer */}
<footer className="border-t border-slate-100 mt-16">
<div className="max-w-6xl mx-auto px-6 py-6">
<p className="text-center text-sm text-slate-400">
Powered by AI • Export ready for Outreaches, Smartlead, and more
</p>
</div>
</footer>
{/* Custom Scrollbar Styles */}
<style>{`
.custom-scrollbar::-webkit-scrollbar {
width: 6px;
}
.custom-scrollbar::-webkit-scrollbar-track {
background: #f1f5f9;
border-radius: 3px;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
background: #cbd5e1;
border-radius: 3px;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
background: #94a3b8;
}
`}</style>
</div>
);
}
|