9b368f9b7a
Admin: Firmen mit Vertriebsstufe und Wiedervorlage, Ansprechpartner mit Einladung ins Portal, B2B-Patenschaften mit Lieferungen und Neuigkeiten, private Dokumente, Notizen und Anfragen. Portal unter /konto/firma: Patenschaften, Lieferungen, Neuigkeiten, Dokument-Download und Anfrageformular. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
180 lines
7.2 KiB
Plaintext
180 lines
7.2 KiB
Plaintext
---
|
|
import Layout from "../../layouts/Layout.astro";
|
|
import { getCustomerMe, getEmailVerification, listMyOrders } from "../../lib/auth";
|
|
import { getMyCompany } from "../../lib/b2b";
|
|
|
|
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>> = [];
|
|
// Im Zweifel als bestätigt behandeln: lieber kein Hinweis als ein falscher.
|
|
let emailBestaetigt = true;
|
|
try {
|
|
customer = await getCustomerMe(token);
|
|
// Vor den Bestellungen: ist die Adresse bestätigt, holt dieser Aufruf
|
|
// Gastbestellungen mit derselben Adresse ins Konto.
|
|
emailBestaetigt = (await getEmailVerification(token).catch(() => ({ verified: true }))).verified;
|
|
orders = await listMyOrders(token);
|
|
} catch {
|
|
Astro.cookies.delete("customer_jwt", { path: "/" });
|
|
return Astro.redirect("/konto/anmelden?redirect=/konto");
|
|
}
|
|
|
|
// Firmenkunden bekommen einen Weg ins Firmenportal. Fehler hier sollen das
|
|
// normale Konto nicht blockieren.
|
|
const firma = await getMyCompany(token).catch(() => null);
|
|
|
|
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>
|
|
|
|
{!emailBestaetigt && (
|
|
<div class="surface mt-10 p-6 shadow-xs sm:p-7">
|
|
<p class="font-medium text-brand-ink">Bitte bestätigen Sie Ihre E-Mail-Adresse</p>
|
|
<p class="mt-2 text-sm leading-relaxed text-brand-text">
|
|
Wir haben Ihnen einen Link an {customer?.email} geschickt. Erst danach erscheinen hier auch
|
|
Bestellungen und Abos, die Sie ohne Anmeldung mit dieser Adresse abgeschlossen haben.
|
|
</p>
|
|
<button id="verify-resend" type="button" class="btn btn-outline mt-5 disabled:pointer-events-none disabled:opacity-55">
|
|
Link erneut senden
|
|
</button>
|
|
<p id="verify-status" role="status" class="mt-3 hidden text-sm text-brand-text"></p>
|
|
</div>
|
|
)}
|
|
|
|
{firma && (
|
|
<a href="/konto/firma" class="group card-interactive mt-10 flex flex-wrap items-center justify-between gap-4 p-6 sm:p-7">
|
|
<div>
|
|
<p class="font-medium text-brand-ink">Firmenportal {firma.company.name}</p>
|
|
<p class="mt-1 text-sm text-brand-text">Bienenpatenschaften, Lieferungen, Neuigkeiten und Dokumente</p>
|
|
</div>
|
|
<span class="text-sm font-medium text-brand-primary">Öffnen →</span>
|
|
</a>
|
|
)}
|
|
|
|
<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, getCustomerTokenClient } from "../../lib/customerCookie";
|
|
import { requestEmailVerification } from "../../lib/auth";
|
|
|
|
// astro:page-load feuert beim ersten Laden und nach jedem
|
|
// View-Transition-Wechsel.
|
|
document.addEventListener("astro:page-load", () => {
|
|
|
|
const resend = document.getElementById("verify-resend") as HTMLButtonElement | null;
|
|
const verifyStatus = document.getElementById("verify-status");
|
|
resend?.addEventListener("click", async () => {
|
|
const token = getCustomerTokenClient();
|
|
if (!token || !verifyStatus) return;
|
|
resend.disabled = true;
|
|
try {
|
|
await requestEmailVerification(token);
|
|
verifyStatus.textContent = "Ein neuer Link ist unterwegs. Er gilt 15 Minuten.";
|
|
} catch (err) {
|
|
verifyStatus.textContent =
|
|
err instanceof Error && /warten/i.test(err.message)
|
|
? err.message
|
|
: "Das hat nicht geklappt. Bitte versuchen Sie es später noch einmal.";
|
|
resend.disabled = false;
|
|
}
|
|
verifyStatus.classList.remove("hidden");
|
|
});
|
|
|
|
document.getElementById("logout-button")?.addEventListener("click", () => {
|
|
clearCustomerTokenClient();
|
|
window.location.href = "/";
|
|
});
|
|
});
|
|
</script>
|