74b0939614
Detailseite: fulfillment_status ist bei Medusa kein gespeichertes Feld, sondern wird im Bestell-Workflow aus den Sendungen berechnet. Über query.graph kam er leer zurück, die Fortschrittsanzeige blieb immer auf "Bestellt". Jetzt über getOrderDetailWorkflow. Bestellliste: zeigte nur den Bestellstatus, der bei Medusa auf "pending" bleibt, auch nach der Zustellung. Jetzt dieselben Stufen wie auf der Detailseite (Verpackt, Versendet, Zugestellt). Im Test über alle Schritte im Admin nachvollzogen. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
126 lines
4.6 KiB
Plaintext
126 lines
4.6 KiB
Plaintext
---
|
|
import Layout from "../../layouts/Layout.astro";
|
|
import { getCustomerMe, listMyOrders } from "../../lib/auth";
|
|
|
|
export const prerender = false;
|
|
|
|
const token = Astro.cookies.get("customer_jwt")?.value;
|
|
if (!token) {
|
|
return Astro.redirect("/konto/anmelden?redirect=/konto");
|
|
}
|
|
|
|
let customer;
|
|
let orders: Awaited<ReturnType<typeof listMyOrders>> = [];
|
|
try {
|
|
customer = await getCustomerMe(token);
|
|
orders = await listMyOrders(token);
|
|
} catch {
|
|
Astro.cookies.delete("customer_jwt", { path: "/" });
|
|
return Astro.redirect("/konto/anmelden?redirect=/konto");
|
|
}
|
|
|
|
const STATUS_LABELS: Record<string, string> = {
|
|
pending: "In Bearbeitung",
|
|
completed: "Abgeschlossen",
|
|
canceled: "Storniert",
|
|
requires_action: "Aktion erforderlich",
|
|
archived: "Archiviert",
|
|
draft: "Entwurf",
|
|
};
|
|
|
|
// Der Bestellstatus bleibt bei Medusa auf "pending", auch wenn das Paket
|
|
// längst zugestellt ist. Was die Kundin wissen will, steckt im Versandstatus —
|
|
// dieselben Stufen wie auf der Detailseite.
|
|
const VERSAND_LABELS: Record<string, string> = {
|
|
fulfilled: "Verpackt",
|
|
partially_fulfilled: "Verpackt",
|
|
shipped: "Versendet",
|
|
partially_shipped: "Versendet",
|
|
delivered: "Zugestellt",
|
|
partially_delivered: "Zugestellt",
|
|
};
|
|
|
|
function statusLabel(order: { status: string; fulfillment_status?: string }): string {
|
|
if (order.status === "pending" && order.fulfillment_status && VERSAND_LABELS[order.fulfillment_status]) {
|
|
return VERSAND_LABELS[order.fulfillment_status];
|
|
}
|
|
return STATUS_LABELS[order.status] ?? order.status;
|
|
}
|
|
---
|
|
|
|
<Layout title="Mein Konto" description="Ihre Bestellungen bei place4bees im Überblick.">
|
|
<section class="honeycomb-bg pt-24 pb-[var(--section-y)] sm:pt-28">
|
|
<div class="mx-auto max-w-[60rem] px-[var(--gutter)]">
|
|
<div class="flex flex-wrap items-end justify-between gap-5">
|
|
<div>
|
|
<span class="section-label">Konto</span>
|
|
<h1 class="mt-5">Hallo{customer?.first_name ? `, ${customer.first_name}` : ""}</h1>
|
|
<p class="mt-2.5 text-brand-text">{customer?.email}</p>
|
|
</div>
|
|
<button id="logout-button" class="btn btn-outline">Abmelden</button>
|
|
</div>
|
|
|
|
<h2 class="mt-16 text-h3">Meine Bestellungen</h2>
|
|
|
|
{orders.length === 0 && (
|
|
<div class="surface mt-6 px-8 py-16 text-center shadow-xs">
|
|
<p class="text-brand-text">Sie haben noch keine Bestellung aufgegeben.</p>
|
|
<a href="/shop" class="btn btn-primary mt-6">Zum Shop</a>
|
|
</div>
|
|
)}
|
|
|
|
{orders.length > 0 && (
|
|
<ul class="mt-6 grid gap-3">
|
|
{orders.map((order) => (
|
|
<li>
|
|
<a
|
|
href={`/konto/bestellungen/${order.id}`}
|
|
class="group card-interactive flex flex-wrap items-center justify-between gap-x-6 gap-y-3 p-6"
|
|
>
|
|
<div>
|
|
<p class="font-medium tabular-nums text-brand-ink">Bestellung #{order.display_id}</p>
|
|
<p class="mt-1 text-sm text-brand-text-muted">
|
|
{new Intl.DateTimeFormat("de-DE", { dateStyle: "medium" }).format(new Date(order.created_at))}
|
|
</p>
|
|
</div>
|
|
<div class="flex items-center gap-5">
|
|
<span class="rounded-[6px] bg-brand-surface-sunk px-3 py-1.5 text-xs font-medium text-brand-text">
|
|
{statusLabel(order)}
|
|
</span>
|
|
<span class="font-medium tabular-nums text-brand-ink">
|
|
{new Intl.NumberFormat("de-DE", { style: "currency", currency: order.currency_code.toUpperCase() }).format(order.total)}
|
|
</span>
|
|
<svg
|
|
viewBox="0 0 20 20"
|
|
class="h-4 w-4 text-brand-primary transition-transform duration-200 ease-out group-hover:translate-x-1"
|
|
fill="none"
|
|
stroke="currentColor"
|
|
stroke-width="1.75"
|
|
aria-hidden="true"
|
|
>
|
|
<path d="M4 10h12M11 5l5 5-5 5" stroke-linecap="round" stroke-linejoin="round" />
|
|
</svg>
|
|
</div>
|
|
</a>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
)}
|
|
</div>
|
|
</section>
|
|
</Layout>
|
|
|
|
<script>
|
|
import { clearCustomerTokenClient } from "../../lib/customerCookie";
|
|
|
|
// astro:page-load feuert beim ersten Laden und nach jedem
|
|
// View-Transition-Wechsel.
|
|
document.addEventListener("astro:page-load", () => {
|
|
|
|
document.getElementById("logout-button")?.addEventListener("click", () => {
|
|
clearCustomerTokenClient();
|
|
window.location.href = "/";
|
|
});
|
|
});
|
|
</script>
|