/* eslint-disable @next/next/no-img-element */ import Link from "next/link"; import { notFound, redirect } from "next/navigation"; import { db } from "@/lib/db"; import { getCurrentUser } from "@/lib/auth"; import { formatPrice } from "@/lib/money"; import { PAYMENT_STATUS, dayFmt } from "@/lib/status"; import type { AddressData } from "@/lib/checkout"; import { AddressLines } from "@/components/shop/AddressLines"; import { DhlTracking } from "@/components/shop/DhlTracking"; import { AccountShell } from "@/components/shop/account/AccountShell"; import { StatusBadge } from "@/components/shop/account/OrderCard"; import { fetchTracking, getDhlConfig, syncDelivered } from "@/lib/dhl"; export default async function OrderDetail({ params }: { params: Promise<{ number: string }> }) { const { number } = await params; const user = await getCurrentUser(); if (!user) redirect(`/konto/anmelden?weiter=/konto/bestellung/${encodeURIComponent(number)}`); const order = await db.order.findUnique({ where: { number }, include: { items: { include: { product: { select: { images: true, slug: true, active: true } } } }, invoices: { orderBy: { createdAt: "asc" } } } }); if (!order || order.userId !== user.id) notFound(); const dhl = await getDhlConfig(); const tracking = order.trackingNumber ? await fetchTracking(dhl, order.trackingNumber) : null; if (await syncDelivered(dhl, order, tracking)) order.status = "COMPLETED"; return ( vom {dayFmt.format(order.createdAt)}} >
{PAYMENT_STATUS[order.paymentStatus].label}
{order.trackingNumber && }

Artikel

    {order.items.map((i) => { const href = i.product?.active && i.product.slug ? `/produkt/${i.product.slug}` : null; const img = i.product?.images[0]; return (
  • {img ? : {i.name.charAt(0)}}
    {href ? {i.name} : {i.name}} {i.variantName ? `${i.variantName} · ` : ""}{i.quantity} × {formatPrice(i.unitPrice)}
    {formatPrice(i.total)}
  • ); })}
Zwischensumme
{formatPrice(order.subtotal)}
Versand
{order.shippingCost === 0 ? "Kostenlos" : formatPrice(order.shippingCost)}
{order.discount > 0 &&
Gutschein
−{formatPrice(order.discount)}
}
Gesamt
{formatPrice(order.total)}

Lieferadresse

Rechnungsadresse

{order.billingAddress ? :

Wie Lieferadresse

}
{order.invoices.length > 0 && (

Rechnungen

)}

← Alle Bestellungen

); }