import React, { useCallback, useState } from 'react' import { useDropzone } from 'react-dropzone' import { DocumentArrowUpIcon } from '@heroicons/react/24/outline' import { Document, documentService } from '../services/api' import { useNotifications } from '../contexts/NotificationContext' interface FileUploadProps { onUploadSuccess: (document: Document) => void } function FileUpload({ onUploadSuccess }: FileUploadProps) { const [uploading, setUploading] = useState(false) const [error, setError] = useState(null) const { addBatchNotification } = useNotifications() const onDrop = useCallback(async (acceptedFiles: File[]) => { const file = acceptedFiles[0] if (!file) return setUploading(true) setError(null) try { const response = await documentService.upload(file) onUploadSuccess(response.data) // Trigger success notification addBatchNotification('success', 'upload', [{ name: file.name, success: true }]) } catch (err: any) { setError(err.response?.data?.message || 'Upload failed') // Trigger error notification addBatchNotification('error', 'upload', [{ name: file.name, success: false }]) } finally { setUploading(false) } }, [onUploadSuccess, addBatchNotification]) const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop, multiple: false, accept: { 'application/pdf': ['.pdf'], 'text/plain': ['.txt'], 'image/*': ['.png', '.jpg', '.jpeg', '.tiff', '.bmp'], 'application/msword': ['.doc'], 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': ['.docx'], }, }) return (

{isDragActive ? 'Drop the file here...' : 'Drag & drop a file here, or click to select'}

Supported: PDF, TXT, DOC, DOCX, PNG, JPG, JPEG, TIFF, BMP

{uploading && (

Uploading and processing...

)}
{error && (
{error}
)}
) } export default FileUpload