Lumen & Gesso / website · lumengesso.com / app / orders / page.tsx
| 1 | import Link from 'next/link'; |
| 2 | import { redirect } from 'next/navigation'; |
| 3 | import { getCustomerUser } from '@/app/lib/lumen-auth'; |
| 4 | import { commerceDb } from '@/app/lib/commerce-db'; |
| 5 | import { displayOrderId, IN_STUDIO_STATUSES } from '@/app/lib/orders'; |
| 6 | import { PasskeyPanel } from '@/app/components/PasskeyPanel'; |
| 7 | |
| 8 | export const dynamic = 'force-dynamic'; |
| 9 | |
| 10 | export default async function OrdersPage() { |
| 11 | const user = await getCustomerUser(); |
| 12 | if (!user) redirect('/login?next=/orders'); |
| 13 | |
| 14 | const admin = commerceDb(); |
| 15 | // Hide pending_payment rows from the customer's commissions list — |
| 16 | // those are abandoned-cart rows from before Stripe completed, not |
| 17 | // real commissions in the studio. If the customer wants to resume, |
| 18 | // the Stripe-cancel return URL (/checkout?orderId=…&canceled=1) |
| 19 | // gives them a "Resume payment" path; we don't surface them here. |
| 20 | const { data: orders } = await admin |
| 21 | .from('orders') |
| 22 | .select('id, status, price_cents, created_at, config') |
| 23 | .eq('user_id', user.id) |
| 24 | .in('status', [...IN_STUDIO_STATUSES]) |
| 25 | .order('created_at', { ascending: false }); |
| 26 | |
| 27 | return ( |
| 28 | <main className="orders"> |
| 29 | <div className="orders__inner"> |
| 30 | <h1 className="orders__title">Your commissions</h1> |
| 31 | <PasskeyPanel compact /> |
| 32 | <Link href="/orders/photos" className="btn btn--secondary btn--md">Saved photos</Link> |
| 33 | {!orders || orders.length === 0 ? ( |
| 34 | <div className="orders__empty"> |
| 35 | <p>No commissions yet.</p> |
| 36 | <Link href="/builder" className="btn btn--rose btn--md">Start a commission</Link> |
| 37 | </div> |
| 38 | ) : ( |
| 39 | <ul className="orders__list"> |
| 40 | {orders.map(o => ( |
| 41 | <li key={o.id} className="orders__row"> |
| 42 | <Link href={`/orders/${o.id}`} className="orders__rowlink"> |
| 43 | <div className="orders__rowtop"> |
| 44 | <span className="orders__id">{displayOrderId(o.id)}</span> |
| 45 | <span className={`statuschip statuschip--${o.status}`}>{statusLabel(o.status)}</span> |
| 46 | </div> |
| 47 | <div className="orders__rowmeta"> |
| 48 | <span>${(o.price_cents / 100).toFixed(2)}</span> |
| 49 | <span>{new Date(o.created_at).toLocaleDateString()}</span> |
| 50 | </div> |
| 51 | </Link> |
| 52 | </li> |
| 53 | ))} |
| 54 | </ul> |
| 55 | )} |
| 56 | </div> |
| 57 | </main> |
| 58 | ); |
| 59 | } |
| 60 | |
| 61 | function statusLabel(s: string): string { |
| 62 | switch (s) { |
| 63 | // pending_payment / abandoned shouldn't reach this list (filtered |
| 64 | // out at the query), but label them so any stray row doesn't |
| 65 | // render raw. |
| 66 | case 'pending_payment': return 'Checkout not complete'; |
| 67 | case 'abandoned': return 'Checkout abandoned'; |
| 68 | case 'pending_design': return 'In the design queue'; |
| 69 | case 'awaiting_approval': return 'Proof ready — review'; |
| 70 | case 'revision_requested': return 'Revision in progress'; |
| 71 | case 'approved': return 'Approved — final studio review'; |
| 72 | case 'fulfillment_submitting': return 'Payment received · sending to printer'; |
| 73 | case 'fulfillment_review': return 'Payment received · checking print order'; |
| 74 | case 'in_production': return 'In production'; |
| 75 | case 'shipped': return 'Shipped'; |
| 76 | case 'cancelled': return 'Cancelled'; |
| 77 | default: return s; |
| 78 | } |
| 79 | } |