import Link from 'next/link'; import { Landmark, Plus } from 'lucide-react'; import { getSupabaseServerClient } from '@kit/supabase/server-client'; import { Badge } from '@kit/ui/badge'; import { Button } from '@kit/ui/button'; import { Card, CardContent, CardHeader, CardTitle } from '@kit/ui/card'; import { createFinanceApi } from '@kit/finance/api'; import { CmsPageShell } from '~/components/cms-page-shell'; import { EmptyState } from '~/components/empty-state'; interface PageProps { params: Promise<{ account: string }>; } const STATUS_VARIANT: Record< string, 'secondary' | 'default' | 'info' | 'outline' | 'destructive' > = { draft: 'secondary', ready: 'default', submitted: 'info', completed: 'outline', failed: 'destructive', }; const STATUS_LABEL: Record = { draft: 'Entwurf', ready: 'Bereit', submitted: 'Eingereicht', completed: 'Abgeschlossen', failed: 'Fehlgeschlagen', }; const formatCurrency = (amount: unknown) => new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format( Number(amount), ); export default async function SepaPage({ params }: PageProps) { const { account } = await params; const client = getSupabaseServerClient(); const { data: acct } = await client .from('accounts') .select('id') .eq('slug', account) .single(); if (!acct) return
Konto nicht gefunden
; const api = createFinanceApi(client); const batches = await api.listBatches(acct.id); return (
{/* Header */}

SEPA-Lastschriften

Lastschrifteinzüge verwalten

{/* Table or Empty State */} {batches.length === 0 ? ( } title="Keine SEPA-Einzüge" description="Erstellen Sie Ihren ersten SEPA-Einzug." actionLabel="Neuer Einzug" actionHref={`/home/${account}/finance/sepa/new`} /> ) : ( Alle Einzüge ({batches.length})
{batches.map((batch: Record) => ( ))}
Status Typ Beschreibung Betrag Anzahl Ausführungsdatum
{STATUS_LABEL[String(batch.status)] ?? String(batch.status)} {batch.batch_type === 'direct_debit' ? 'Lastschrift' : 'Überweisung'} {String(batch.description ?? '—')} {batch.total_amount != null ? formatCurrency(batch.total_amount) : '—'} {String(batch.item_count ?? 0)} {batch.execution_date ? new Date( String(batch.execution_date), ).toLocaleDateString('de-DE') : '—'}
)}
); }