import { useEffect, useState } from 'react'; import { Table, Popover, Button, Space, message, Tooltip, Typography } from 'antd'; import { AuthImage } from '../utils/auth-resource'; import { ReloadOutlined } from '@ant-design/icons'; const { Title, Text } = Typography; import dayjs from 'dayjs'; import { posteingangApi } from '../api/posteingang'; import type { PosteingangDocument } from '../api/posteingang'; import DocumentEditModal from '../components/DocumentEditModal'; import { getEnv } from '../utils/env'; import { useIsMobile } from '../hooks/useIsMobile'; import MobileCardList from '../components/MobileCardList'; export default function PosteingangPage() { const isMobile = useIsMobile(); const [data, setData] = useState([]); const [loading, setLoading] = useState(false); const [editModalOpen, setEditModalOpen] = useState(false); const [selectedDoc, setSelectedDoc] = useState(null); const fetchData = async () => { setLoading(true); try { const docs = await posteingangApi.getList(); setData(docs || []); } catch (e) { message.error("Posteingang konnte nicht geladen werden."); } finally { setLoading(false); } }; useEffect(() => { fetchData(); // Refresh interval every 30 seconds const interval = setInterval(() => { fetchData(); }, 30000); return () => clearInterval(interval); }, []); const handleEdit = (doc: PosteingangDocument) => { setSelectedDoc(doc); setEditModalOpen(true); }; const handleCloseModal = (openNext?: boolean) => { setEditModalOpen(false); if (openNext && data.length > 0) { const currentIndex = data.findIndex(d => d.id === selectedDoc?.id); const nextIndex = currentIndex !== -1 && currentIndex + 1 < data.length ? currentIndex + 1 : 0; const nextDoc = data[nextIndex]; setTimeout(() => { setSelectedDoc(nextDoc); setEditModalOpen(true); }, 300); } else { setSelectedDoc(null); } }; const popoverContent = (id: number) => ( ); const getEingangsdatum = (record: PosteingangDocument) => { const cf = record.customFields?.find((f) => f.field === 9); return cf?.value ? dayjs(cf.value).format('DD.MM.YYYY') : '-'; }; const columns = [ { title: 'Vorschau', key: 'preview', width: 150, render: (_: any, record: PosteingangDocument) => ( ), }, { title: 'Titel', dataIndex: 'title', key: 'title', width: '35%', }, { title: 'Eingangsdatum', key: 'eingangsdatum', render: (_: any, record: PosteingangDocument) => getEingangsdatum(record), }, { title: 'Importiert am', dataIndex: 'added', key: 'added', render: (text: string) => dayjs(text).format('DD.MM.YYYY HH:mm'), }, { title: 'Aktionen', key: 'action', width: 150, render: (_: any, record: PosteingangDocument) => ( ), }, ]; return (
Posteingang
{isMobile ? ( dataSource={data} rowKey="id" loading={loading} pagination={{ pageSize: 20, showTotal: (t) => `${t} Dokumente` }} renderCard={(record) => (
{record.title || '—'} Eingangsdatum: {getEingangsdatum(record)} Importiert am: {dayjs(record.added).format('DD.MM.YYYY HH:mm')}
)} /> ) : ( `${t} Dokumente` }} locale={{ emptyText: 'Keine Einträge vorhanden' }} /> )} 1} /> ); }