import Link from 'next/link'; import { ArrowLeft, Send, Users } 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 { createNewsletterApi } from '@kit/newsletter/api'; import { CmsPageShell } from '~/components/cms-page-shell'; import { StatsCard } from '~/components/stats-card'; interface PageProps { params: Promise<{ account: string; campaignId: string }>; } const STATUS_VARIANT: Record< string, 'secondary' | 'default' | 'info' | 'outline' | 'destructive' > = { draft: 'secondary', scheduled: 'default', sending: 'info', sent: 'outline', failed: 'destructive', }; const STATUS_LABEL: Record = { draft: 'Entwurf', scheduled: 'Geplant', sending: 'Wird gesendet', sent: 'Gesendet', failed: 'Fehlgeschlagen', }; const RECIPIENT_STATUS_VARIANT: Record< string, 'secondary' | 'default' | 'info' | 'outline' | 'destructive' > = { pending: 'secondary', sent: 'default', failed: 'destructive', bounced: 'destructive', }; const RECIPIENT_STATUS_LABEL: Record = { pending: 'Ausstehend', sent: 'Gesendet', failed: 'Fehlgeschlagen', bounced: 'Zurückgewiesen', }; export default async function NewsletterDetailPage({ params }: PageProps) { const { account, campaignId } = 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 = createNewsletterApi(client); const [newsletter, recipients] = await Promise.all([ api.getNewsletter(campaignId), api.getRecipients(campaignId), ]); if (!newsletter) return
Newsletter nicht gefunden
; const status = String(newsletter.status); const sentCount = recipients.filter( (r: Record) => r.status === 'sent', ).length; const failedCount = recipients.filter( (r: Record) => r.status === 'failed' || r.status === 'bounced', ).length; return (
{/* Back link */}
Zurück zu Newsletter
{/* Summary Card */} {String(newsletter.subject ?? '(Kein Betreff)')} {STATUS_LABEL[status] ?? status}
} /> } /> } />
{/* Actions */} {status === 'draft' && (
)}
{/* Recipients Table */} Empfänger ({recipients.length}) {recipients.length === 0 ? (

Keine Empfänger hinzugefügt. Fügen Sie Empfänger aus Ihrer Mitgliederliste hinzu.

) : (
{recipients.map((recipient: Record) => { const rStatus = String(recipient.status ?? 'pending'); return ( ); })}
Name E-Mail Status
{String(recipient.name ?? '—')} {String(recipient.email ?? '—')} {RECIPIENT_STATUS_LABEL[rStatus] ?? rStatus}
)}
); }