import { useEffect, useState } from 'react'; import { useParams, useNavigate } from 'react-router-dom'; import { Card, Button, Space, Spin, Tag, Typography, Table, message, Empty, Popconfirm } from 'antd'; import { ArrowLeftOutlined, FileTextOutlined, CloseCircleOutlined, LinkOutlined } from '@ant-design/icons'; import type { ColumnsType } from 'antd/es/table'; import dayjs from 'dayjs'; import { emailsApi, type EmailItem, type EmailAttachment } from '../api/emails'; import { emailImportApi } from '../api/email-import'; import { getEnv } from '../utils/env'; import MailImportWizard from '../components/MailImportWizard'; const { Title, Text } = Typography; export default function MailDetailPage() { const { id } = useParams<{ id: string }>(); const navigate = useNavigate(); const [email, setEmail] = useState(null); const [attachments, setAttachments] = useState([]); const [selected, setSelected] = useState(null); const [previewUrl, setPreviewUrl] = useState(null); const [loading, setLoading] = useState(true); const [previewLoading, setPreviewLoading] = useState(false); const [wizardOpen, setWizardOpen] = useState(false); useEffect(() => { if (!id) return; const emailId = parseInt(id, 10); Promise.all([emailsApi.get(emailId), emailsApi.listAttachments(emailId)]) .then(([mail, att]) => { setEmail(mail); setAttachments(att); if (att.length > 0) setSelected(att[0]); }) .catch(() => message.error('E-Mail nicht gefunden')) .finally(() => setLoading(false)); }, [id]); const handleIgnore = async () => { if (!email) return; try { await emailsApi.updateStatus(email.Id, 3); message.success('E-Mail als ignoriert markiert'); navigate('/mailpostfach'); } catch (err) { message.error('Fehler beim Markieren der E-Mail'); } }; useEffect(() => { if (!selected) { setPreviewUrl(null); return; } setPreviewLoading(true); let objectUrl: string | null = null; emailsApi.getAttachmentContent(selected.Id) .then((blob) => { objectUrl = URL.createObjectURL(blob); setPreviewUrl(objectUrl); }) .catch(() => message.error('Vorschau konnte nicht geladen werden')) .finally(() => setPreviewLoading(false)); return () => { if (objectUrl) URL.revokeObjectURL(objectUrl); }; }, [selected]); if (loading) return ; if (!email) return E-Mail nicht gefunden.; const isHtml = /<[a-z][\s\S]*>/i.test(email.Body); const hasErechnung = attachments.some((a) => a.Erechnung); const columns: ColumnsType = [ { title: 'Dateiname', dataIndex: 'FileName', key: 'FileName', ellipsis: true, }, { title: 'Typ', dataIndex: 'ContentType', key: 'ContentType', width: 160, ellipsis: true, }, { title: 'eRechnung', dataIndex: 'Erechnung', key: 'Erechnung', width: 100, align: 'center', render: (v: boolean) => (v ? Ja : Nein), }, { title: 'Paperless ID', dataIndex: 'PaperlessDocumentIds', key: 'PaperlessDocumentIds', width: 130, render: (ids: Record | null) => { if (!ids) return null; const entries = Object.entries(ids); if (entries.length === 0) return null; return ( {entries.map(([, id]) => { const paperlessUrl = getEnv('PAPERLESS_URL'); return ( e.stopPropagation()} > {id} ); })} ); } }, ]; return (
{email.Subject} {hasErechnung && eRechnung}
{/* Linke Seite: E-Mail-Inhalt */}
Von: {email.SenderAddress}
An: {email.RecipientAddress}
Datum: {dayjs(email.Date).format('DD.MM.YYYY HH:mm')}
{isHtml ? (