export const dynamic = "force-dynamic"; /** * /dashboard — the customer's order history. * * This page used to render "No active eSIMs yet." unconditionally, which told * a paying customer their purchase had not happened. It now reads the orders * they have actually claimed and asks fulfilment about each one. Three * outcomes, all of them stated rather than implied: no orders, orders we could * read, and orders we could not read. */ import { auth } from "@clerk/nextjs/server"; import { redirect } from "next/navigation"; import { listClaimedOrderIds } from "@/lib/checkout-order-claim"; import { fetchOrder } from "@/vendor/carrier/client"; import type { EsimOrder, OrderStatus } from "@/vendor/carrier/types"; import { EsimControls } from "./EsimControls"; export const metadata = { title: "Dashboard" }; const STATUS_LABEL: Record = { pending: "Payment received", provisioning: "Setting up", ready: "Active", failed: "Needs attention", }; function EmptyState() { return (

No active eSIMs yet.

Browse plans
); } function OrderRow({ orderId, order }: { orderId: string; order: EsimOrder | null }) { return (
  • {order?.planName ?? order?.templateId ?? "eSIM order"}

    {order ? order.cancelledAt ? "Cancelled" : STATUS_LABEL[order.status] : "Status unavailable"}

    {orderId}

    {order?.iccid &&

    ICCID {order.iccid}

    } {!order && (

    We couldn't reach this order just now. Your purchase is safe — try again shortly.

    )} {order?.status === "ready" ? "View QR code" : "View order"} → {/* Only once there is an eSIM behind the row. Usage, top-up and cancel all address a thing that exists; offering them over a pending order invites three calls that can only answer "not yet". */} {order?.status === "ready" && ( )}
  • ); } export default async function DashboardPage() { const { userId } = await auth(); if (!userId) redirect("/sign-in?redirect_url=/dashboard"); const orderIds = await listClaimedOrderIds(userId); const orders = await Promise.all( orderIds.map(async (orderId) => { const lookup = await fetchOrder(orderId); return { orderId, order: lookup.ok ? lookup.order : null }; }), ); const unreadable = orders.filter((entry) => entry.order === null).length; return (

    Your eSIMs

    {orders.length === 0 ? ( ) : ( <> {unreadable > 0 && (

    We couldn't load {unreadable === orders.length ? "your orders" : "some of your orders"}{" "} right now. Nothing is lost — refresh in a minute, or contact us with the order number.

    )}
      {orders.map((entry) => ( ))}
    )}
    ); }