import type { Metadata } from "next"; import { redirect } from "next/navigation"; import Link from "next/link"; import { Container, SectionHeading, LinkButton } from "@/components/ui"; import { BackLink } from "@/components/back-link"; import { ReorderButton } from "@/components/reorder-button"; import { AccountEmptyState, OrderStatusBadge, OrderStatusTimeline, OrderIcon } from "@/components/account-ui"; import { getCurrentCustomer } from "@/lib/auth"; import { getOrdersForCustomer } from "@/lib/account-data"; import { formatPrice, formatDate } from "@/lib/format"; import { getCarrierTrackingUrl } from "@/lib/shipment-tracking"; import { getLocale } from "@/i18n/locale"; import { getDictionary } from "@/i18n/get-dictionary"; export const metadata: Metadata = { title: "Meine Bestellungen" }; export const dynamic = "force-dynamic"; // Deckt sich mit RETURN_ELIGIBLE_STATUSES in bestellungen/actions.ts. const RETURN_ELIGIBLE_STATUSES = [ "BEZAHLT", "IN_VORBEREITUNG", "VERSANDBEREIT", "VERSENDET", "ABHOLBEREIT", "ABGEHOLT", ]; export default async function KontoBestellungenPage() { const locale = await getLocale(); const t = getDictionary(locale); const statusLabels = t.orderStatusBadge; const returnStatusLabels = t.ordersPage.returnStatusLabels; const customer = await getCurrentCustomer(); if (!customer) redirect("/konto"); const orders = await getOrdersForCustomer(customer.id); return (
{orders.length === 0 ? ( } title={t.ordersPage.emptyTitle} description={t.ordersPage.emptyDescription} action={{t.cartPage.goToShop}} /> ) : (
{orders.map((order) => (

{order.orderNumber}

{formatDate(order.createdAt, locale)}

{order.fulfillmentMethod === "VERSAND" ? order.shipment?.shippedAt ? t.ordersPage.shippedOn(formatDate(order.shipment.shippedAt, locale)) : t.ordersPage.shippingPending : order.pickup?.pickedUpAt ? t.ordersPage.pickedUpOn(formatDate(order.pickup.pickedUpAt, locale)) : order.pickup?.readyAt ? t.ordersPage.readySince(formatDate(order.pickup.readyAt, locale)) : t.ordersPage.pickupPending}

    {order.items.map((item) => (
  • {item.quantity} ร—{" "} {item.productName}
  • ))}
{order.shipment?.carrier && order.shipment.trackingNumber ? (

{t.shipmentInfo.carrierLabel}: {order.shipment.carrier} ยท {t.shipmentInfo.trackingNumberLabel}:{" "} {order.shipment.trackingNumber} {(() => { const url = getCarrierTrackingUrl(order.shipment.carrier, order.shipment.trackingNumber); return url ? ( <> {" "} ยท{" "} {t.shipmentInfo.trackPackage} ) : null; })()}

) : null} {order.giftMessage ? (

๐ŸŽ {t.ordersPage.giftMessagePrefix} โ€ž{order.giftMessage}โ€œ

) : null}

{formatPrice(order.totalCents, order.currency, locale)}

{order.invoice ? ( {t.ordersPage.viewInvoice} ) : null} {order.returnRequest ? ( {returnStatusLabels[order.returnRequest.status] ?? order.returnRequest.status} ) : RETURN_ELIGIBLE_STATUSES.includes(order.status) ? ( {t.ordersPage.requestReturn} ) : null} ({ productId: item.productId, slug: item.product.slug, name: item.productName, weightGrams: item.weightGrams, priceCents: item.unitPriceCents, quantity: item.quantity, }))} />
))}
)}
); }