import React, { useState, useRef } from 'react'; import { Upload, FileSpreadsheet, CheckCircle2, X, Users } from 'lucide-react'; import { Button } from "@/components/ui/button"; import { motion, AnimatePresence } from 'framer-motion'; export default function UploadStep({ onFileUploaded, uploadedFile, onRemoveFile }) { const [isDragging, setIsDragging] = useState(false); const fileInputRef = useRef(null); const handleDragOver = (e) => { e.preventDefault(); setIsDragging(true); }; const handleDragLeave = (e) => { e.preventDefault(); setIsDragging(false); }; const handleDrop = async (e) => { e.preventDefault(); setIsDragging(false); const file = e.dataTransfer.files[0]; if (file && file.name.endsWith('.csv')) { await handleFileUpload(file); } }; const handleFileSelect = async (e) => { const file = e.target.files[0]; if (file && file.name.endsWith('.csv')) { await handleFileUpload(file); } }; const handleFileUpload = async (file) => { const formData = new FormData(); formData.append('file', file); try { const response = await fetch('/api/upload-csv', { method: 'POST', body: formData, }); if (response.ok) { const data = await response.json(); onFileUploaded({ name: file.name, size: file.size, contactCount: data.contact_count, fileId: data.file_id }); } else { alert('Failed to upload file. Please try again.'); } } catch (error) { console.error('Upload error:', error); alert('Error uploading file. Please try again.'); } }; return (
{!uploadedFile ? (
fileInputRef.current?.click()} className={` relative cursor-pointer rounded-2xl border-2 border-dashed transition-all duration-300 ease-out ${isDragging ? 'border-violet-500 bg-violet-50 scale-[1.02]' : 'border-slate-200 bg-slate-50/50 hover:border-violet-300 hover:bg-violet-50/30' } `} >

Upload your Apollo CSV

Drag and drop your contact list here, or click to browse

Supports .csv files exported from Apollo
) : (

{uploadedFile.name}

{(uploadedFile.size / 1024).toFixed(1)} KB
{uploadedFile.contactCount} contacts found
)}
); }