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 (
Drag and drop your contact list here, or click to browse