import { useState, useEffect, useCallback } from 'react' import { FaFileLines, FaEye, FaDownload, FaSpinner, FaMagnifyingGlass, FaRotate, FaUpload } from 'react-icons/fa6' import { integrationsApi } from '../lib/integrationsApi' import { useCustomers } from '../hooks/useCustomers' import { PageHeader, Card, Button, EmptyState } from '../components/ui' import FileUploadModal from '../components/FileUploadModal' export default function DocumentsPage() { const { customers } = useCustomers() const [docs, setDocs] = useState([]) const [count, setCount] = useState(0) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) const [query, setQuery] = useState('') const [correspondent, setCorrespondent] = useState('') const [busyId, setBusyId] = useState(null) const [showUpload, setShowUpload] = useState(false) const load = useCallback(async () => { setLoading(true) setError(null) try { const params = { page_size: 50 } if (query) params.query = query if (correspondent) params.correspondent = correspondent const data = await integrationsApi.listDocuments(params) setDocs(data.documents || []) setCount(data.count || 0) } catch (err) { setError(err.message) setDocs([]) } finally { setLoading(false) } }, [query, correspondent]) useEffect(() => { load() }, [load]) const open = async (id, kind) => { setBusyId(id + kind) try { await integrationsApi.openDocument(id, kind) } catch (err) { alert('Fehler: ' + err.message) } finally { setBusyId(null) } } return (
} />
setQuery(e.target.value)} onKeyDown={(e) => e.key === 'Enter' && load()} />
{loading ? (
) : error ? (
{error}
) : docs.length === 0 ? ( } title="Keine Dokumente" hint="Keine Dokumente gefunden." /> ) : ( <>
{count} Dokument(e)
{docs.map((d) => (
{d.title}
{d.created ? new Date(d.created).toLocaleDateString('de-DE') : ''}
))}
)}
setShowUpload(false)} workorderId="" ticket={correspondent ? { customerName: correspondent, woid: '' } : { customerName: '', woid: '' }} onUploadComplete={() => setTimeout(load, 1500)} />
) }