import { createClient } from '@/lib/supabase/server' import { redirect } from 'next/navigation' import Link from 'next/link' import { CheckCircle2, Download, ExternalLink, ShoppingBag, ArrowRight } from 'lucide-react' import { Button } from '@/components/ui/button' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { Separator } from '@/components/ui/separator' import { Badge } from '@/components/ui/badge' import type { Order } from '@/lib/types' export default async function OrderSuccessPage({ searchParams, }: { searchParams: Promise<{ id?: string }> }) { const { id } = await searchParams if (!id) redirect('/') const supabase = await createClient() // Authentifizierung prüfen const { data: { user } } = await supabase.auth.getUser() if (!user) redirect('/auth/login') // Bestellung laden und prüfen ob sie dem eingeloggten User gehört const { data: order, error } = await supabase .from('orders') .select('*') .eq('id', id) .eq('user_id', user.id) .single() if (error || !order) redirect('/') const o = order as Order const items = o.order_data?.items ?? [] const statusLabel: Record = { pending: 'Eingegangen', active: 'In Bearbeitung', cancelled: 'Storniert', } return (
{/* Erfolgsmeldung */}

Bestellung eingegangen!

Ihre Bestellung wurde erfolgreich gespeichert.

#{o.order_number}
{/* Bestell-Details */} Bestellübersicht {statusLabel[o.status] ?? o.status} {/* Produkte */}
{items.map((item) => (
{item.product_name} {new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(item.base_price)} {item.billing_interval === 'one_time' ? 'einmalig' : '/ Monat'}
{item.selected_modules.map((mod) => (
+ {mod.module_name} {new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(mod.price)}
))}
))}
{/* Gesamtbetrag */}
Gesamtbetrag {new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(o.total_price)}
{/* Kundendaten */}

{o.customer_data?.company_name}

{o.customer_data?.first_name} {o.customer_data?.last_name}

{o.customer_data?.address}, {o.customer_data?.zip_code} {o.customer_data?.city}

{/* PDF-Download */} {o.pdf_url && ( )}
{/* Aktions-Buttons */}
) }