import { createResource, createSignal, createMemo, Show, For } from 'solid-js'; import AdminShell from '~/components/AdminShell'; const API = '/api/gateway'; type Order = { id: string; order_number?: string; user_name?: string; user_email?: string; package_name?: string; tracecoin_amount?: number; coupon_code?: string; total?: number; amount?: number; status: string; created_at?: string; }; async function loadOrders(): Promise { try { const res = await fetch(`${API}/api/admin/orders`); if (!res.ok) throw new Error('Failed to load'); const data = await res.json(); return Array.isArray(data) ? data : (data.orders || []); } catch { return []; } } function statusClass(status: string): string { const s = (status || '').toUpperCase(); if (s === 'PAID' || s === 'COMPLETED') return 'active'; if (s === 'PENDING') return 'pending'; if (s === 'FAILED') return 'failed'; return ''; } function statusStyle(status: string): string { const s = (status || '').toUpperCase(); if (s === 'PAID' || s === 'COMPLETED') return 'background:#dcfce7;color:#166534;border-color:#bbf7d0'; if (s === 'PENDING') return 'background:#fff7ed;color:#c2410c;border-color:#fed7aa'; if (s === 'FAILED') return 'background:#fee2e2;color:#991b1b;border-color:#fecaca'; if (s === 'REFUNDED') return 'background:#f1f5f9;color:#475569;border-color:#e2e8f0'; return ''; } export default function OrderPage() { const [orders] = createResource(loadOrders); const [search, setSearch] = createSignal(''); const filtered = createMemo(() => { const q = search().toLowerCase().trim(); const all = orders() ?? []; if (!q) return all; return all.filter((o) => { const orderNum = (o.order_number || o.id || '').toLowerCase(); const email = (o.user_email || '').toLowerCase(); const name = (o.user_name || '').toLowerCase(); const status = (o.status || '').toLowerCase(); return orderNum.includes(q) || email.includes(q) || name.includes(q) || status.includes(q); }); }); const formatAmount = (order: Order) => { const raw = order.total ?? order.amount; if (raw == null) return '—'; return `₹${(raw / 100).toFixed(2)}`; }; return (

Order Management

TraceCoin package purchase orders

setSearch(e.currentTarget.value)} class="rounded-lg border border-gray-200 px-3 py-2 text-sm" style="width:100%;max-width:420px" />
0}> {(item) => ( )}
Order # User Package TraceCoins Coupon Total Status Created At
Loading...
Failed to load. Is the backend running?
No orders found.
{item.order_number || item.id} {item.user_name || item.user_email || '—'} {item.package_name || '—'} {item.tracecoin_amount ?? '—'} {item.coupon_code || '—'} {formatAmount(item)} {item.status || '—'} {item.created_at ? new Date(item.created_at).toLocaleString() : '—'}
); }