import { useState } from "react"; export default function FileUpload({ onUploadSuccess, }: { onUploadSuccess: () => void; }) { const [uploading, setUploading] = useState(false); const handleFileUpload = async (e: React.ChangeEvent) => { const file = e.target.files?.[0]; if (!file) return; setUploading(true); const formData = new FormData(); formData.append("file", file); try { const response = await fetch( `${process.env.NEXT_PUBLIC_API_URL}/upload`, { method: "POST", body: formData, } ); if (!response.ok) throw new Error("Upload failed"); onUploadSuccess(); } catch (error) { console.error("Upload error:", error); } finally { setUploading(false); } }; return (
); }