'use client'; import { useCallback, useState } from 'react'; import { useTranslations } from 'next-intl'; import { useParams } from 'next/navigation'; import Link from 'next/link'; import { PageHeader } from '@/components/layout/page-header'; import { checkNow, type DkvHistoryEntry } from '@/lib/dkv-api'; import { InvoiceHistoryTable } from './components/InvoiceHistoryTable'; import { ExportFileList } from './components/ExportFileList'; /** * Inline spinner SVG per 07-UI-SPEC (20×20, animate-spin, stroke="currentColor"). */ function SpinnerIcon() { return ( ); } /** * DKV Flotte module main page (Surface A from 07-UI-SPEC). * Shows processing history (InvoiceHistoryTable) + export file list (ExportFileList). * "Jetzt prüfen" triggers an immediate inbox poll, then refetches history. */ export default function DkvFleetPage() { const t = useTranslations('dkvFleet'); const params = useParams<{ category?: string; moduleSlug?: string }>(); const basePath = params.category && params.moduleSlug ? `/modules/${params.category}/${params.moduleSlug}` : '/modules/dkv-fleet'; const [isChecking, setIsChecking] = useState(false); const [pollError, setPollError] = useState(null); const [refreshKey, setRefreshKey] = useState(0); const [lastChecked, setLastChecked] = useState(null); const [historyItems, setHistoryItems] = useState([]); const handleCheckNow = async () => { setIsChecking(true); setPollError(null); try { await checkNow(); setLastChecked(new Date()); // Increment refreshKey to trigger InvoiceHistoryTable refetch setRefreshKey((k) => k + 1); } catch { setPollError(t('errors.pollFailed')); } finally { setIsChecking(false); } }; const handleItemsLoaded = useCallback((items: DkvHistoryEntry[]) => { setHistoryItems(items); }, []); const formatLastChecked = (date: Date): string => { const day = String(date.getDate()).padStart(2, '0'); const month = String(date.getMonth() + 1).padStart(2, '0'); const year = date.getFullYear(); const hours = String(date.getHours()).padStart(2, '0'); const minutes = String(date.getMinutes()).padStart(2, '0'); return `${day}.${month}.${year}, ${hours}:${minutes}`; }; return (
{/* Seitenkopf (Design „Mosaik“): App-Kachel, Titel, Stand; Aktionen rechts */} } /> {/* Error banner — conditional per UI-SPEC */} {pollError && (
{pollError}
)} {/* Invoice Processing History */}

{t('historyTitle')}

{/* Last Export Files */}

{t('exportFilesTitle')}

); }