import React, { useState } from 'react';
import UploadForm from './UploadForm';
import UploadForm from './UploadForm';
import axios from 'axios';
import { API_BASE_URL } from './config';
const Dashboard = () => {
const [step, setStep] = useState(1);
const [uploadData, setUploadData] = useState(null);
const [generatedEmails, setGeneratedEmails] = useState([]);
const [smtpEmail, setSmtpEmail] = useState("");
const [smtpPassword, setSmtpPassword] = useState("");
const [sendingResults, setSendingResults] = useState([]);
// Background Orbs for "Alive" feel
const BackgroundOrbs = () => (
);
const handleUploadSuccess = (data) => {
setUploadData(data);
setStep(2);
generateEmails(data);
};
const generateEmails = async (data) => {
try {
const response = await axios.post(`${API_BASE_URL}/generate-emails`, {
resume_filename: data.resume_filename,
excel_filename: data.excel_filename
});
setGeneratedEmails(response.data.emails);
setStep(3);
} catch (error) {
console.error(error);
alert("Error generating emails. Ensure Backend is active.");
setStep(1);
}
};
const handleSendEmails = async () => {
if (!smtpEmail || !smtpPassword) {
alert("Please enter SMTP Credentials");
return;
}
try {
const payload = {
emails: generatedEmails.map(item => ({
to: item.hr_email,
subject: item.email.includes("Subject:") ? item.email.split('\n').find(l => l.includes("Subject:")).replace("Subject:", "").trim() : "Application Inquiry",
body: item.email
})),
smtp_email: smtpEmail,
smtp_password: smtpPassword
};
const response = await axios.post(`${API_BASE_URL}/send-bulk-emails`, payload);
setSendingResults(response.data.results);
setStep(4);
} catch (error) {
console.error(error);
alert("Error sending emails");
}
};
return (
{/* Header */}
{step === 1 && (
)}
{step === 2 && (
AI Brain at Work
Parsing resume, analyzing tech stack, and crafting perfect pitches...
)}
{step === 3 && (
Draft Reviews
We've prepared {generatedEmails.length} personalized emails for you.
{generatedEmails.map((item, index) => (
{item.company}
{item.hr_email}
))}
)}
{step === 4 && (
🎉
Campaign Completed!
Here's how your outreach went.
| Recipient |
Status |
Details |
{sendingResults.map((res, index) => (
| {res.to} |
{res.status === 'sent' ? (
SENT
) : (
FAILED
)}
|
{res.error || "Delivered"} |
))}
)}
);
};
export default Dashboard;