import Link from 'next/link'; import { ChevronLeft, ChevronRight, Mail, Plus, Send, Users, } from 'lucide-react'; import { createNewsletterApi } from '@kit/newsletter/api'; import { formatDate } from '@kit/shared/dates'; 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 { ListToolbar } from '@kit/ui/list-toolbar'; import { AccountNotFound } from '~/components/account-not-found'; import { CmsPageShell } from '~/components/cms-page-shell'; import { EmptyState } from '~/components/empty-state'; import { StatsCard } from '~/components/stats-card'; import { NEWSLETTER_STATUS_VARIANT, NEWSLETTER_STATUS_LABEL, } from '~/lib/status-badges'; const PAGE_SIZE = 25; interface PageProps { params: Promise<{ account: string }>; searchParams: Promise>; } function buildQuery( base: Record, overrides: Record, ): string { const params = new URLSearchParams(); for (const [key, value] of Object.entries({ ...base, ...overrides })) { if (value !== undefined && value !== '') { params.set(key, String(value)); } } const qs = params.toString(); return qs ? `?${qs}` : ''; } export default async function NewsletterPage({ params, searchParams, }: PageProps) { const { account } = await params; const search = await searchParams; const client = getSupabaseServerClient(); const { data: acct } = await client .from('accounts') .select('id') .eq('slug', account) .single(); if (!acct) return ; const q = typeof search.q === 'string' ? search.q : undefined; const status = typeof search.status === 'string' ? search.status : undefined; const page = Math.max(1, Number(search.page) || 1); const api = createNewsletterApi(client); const result = await api.listNewsletters(acct.id, { search: q, status, page, pageSize: PAGE_SIZE, }); const newsletters = result.data; const totalItems = result.total; const totalPages = result.totalPages; const safePage = result.page; const sentCount = newsletters.filter( (n: Record) => n.status === 'sent', ).length; const totalRecipients = newsletters.reduce( (sum: number, n: Record) => sum + (Number(n.total_recipients) || 0), 0, ); const queryBase = { q, status }; return (
{/* Header */}

Newsletter

Newsletter erstellen und versenden

{/* Stats */}
} /> } /> } />
{/* Toolbar */} {/* Table or Empty State */} {totalItems === 0 ? ( } title="Keine Newsletter vorhanden" description="Erstellen Sie Ihren ersten Newsletter, um loszulegen." actionLabel="Neuer Newsletter" actionHref={`/home/${account}/newsletter/new`} /> ) : ( Alle Newsletter ({totalItems})
{newsletters.map((nl: Record) => ( ))}
Betreff Status Empfänger Erstellt Gesendet
{String(nl.subject ?? '(Kein Betreff)')} {NEWSLETTER_STATUS_LABEL[String(nl.status)] ?? String(nl.status)} {nl.total_recipients != null ? String(nl.total_recipients) : '—'} {formatDate(nl.created_at)} {formatDate(nl.sent_at)}
{/* Pagination */} {totalPages > 1 && (

Seite {safePage} von {totalPages}

{safePage > 1 ? ( ) : ( )} {safePage} / {totalPages} {safePage < totalPages ? ( ) : ( )}
)}
)}
); }