'use client'; import { Suspense, useEffect, useState } from 'react'; import { useSearchParams } from 'next/navigation'; import { Link } from '@/core/lib/navigation'; import type { Order } from 'brainerce'; import { BrainerceError } from 'brainerce'; import { getClient } from '@/core/lib/brainerce'; import { LoadingSpinner } from '@/ui/shared/loading-spinner'; import { OrderHistory } from '@/components/account/order-history'; import { useTranslations } from '@/core/lib/translations'; // Read-only order lookup for links from transactional emails (order confirmation, // shipped, refunded, etc). Unlike /order-confirmation, this page never calls // handlePaymentSuccess() or touches cart state — it only fetches and displays, // so it's safe to revisit at any time without side effects on an unrelated // active cart. Works for guests too: the checkout id itself is the credential. function OrderStatusContent() { const searchParams = useSearchParams(); const checkoutId = searchParams.get('checkout_id'); const t = useTranslations('orderStatus'); const tc = useTranslations('common'); const [order, setOrder] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); /** Separates our own outage from a link that names no order. */ const [unavailable, setUnavailable] = useState(false); useEffect(() => { if (!checkoutId) { setError(t('missingCheckoutInfo')); setLoading(false); return; } let cancelled = false; async function loadOrder() { try { const client = getClient(); const result = await client.getOrderByCheckout(checkoutId!); if (!cancelled) setOrder(result); } catch (err) { if (!cancelled) { // "We could not find your order" and "we could not reach the server" // are different facts, and only one of them is about the customer. // A backend outage rendered as ORDER NOT FOUND on the page people // open from their receipt email -- seen for real during a redeploy. // Telling someone the order they just paid for does not exist is // worse than telling them nothing. // // A 4xx really is "no order for this link". Anything else is us. const missing = err instanceof BrainerceError && err.statusCode < 500; if (!missing) console.error('[order-status] could not load order', err); setUnavailable(!missing); setError(missing ? t('notFound') : t('unavailableBody')); } } finally { if (!cancelled) setLoading(false); } } loadOrder(); return () => { cancelled = true; }; }, [checkoutId, t]); if (loading) { return (

{t('loading')}

); } if (error || !order) { return (

{unavailable ? t('unavailableTitle') : t('errorTitle')}

{error || t('notFound')}

{t('returnHome')}
); } return (

{t('pageTitle')}

{tc('continueShopping')}
); } export default function OrderStatusPage() { return ( } > ); }