| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- import { Head, Link } from '@inertiajs/react';
- import { ReceiptText } from 'lucide-react';
- import OrderController from '@/actions/App/Http/Controllers/OrderController';
- import StoreController from '@/actions/App/Http/Controllers/StoreController';
- import StoreNav from '@/components/stores/store-nav';
- import { Badge } from '@/components/ui/badge';
- import { formatDateTime, formatRinggit } from '@/lib/money';
- import { dashboard } from '@/routes';
- import type { Order, StoreSummary } from '@/types';
-
- export default function OrdersIndex({
- store,
- orders,
- }: {
- store: StoreSummary;
- orders: Order[];
- }) {
- const paid = orders.filter((order) => order.status === 'paid');
- const revenue = paid.reduce((sum, order) => sum + order.total, 0);
-
- return (
- <>
- <Head title={`Orders - ${store.name}`} />
-
- <div className="mx-auto w-full max-w-6xl space-y-6 p-4">
- <div>
- <h1 className="text-xl font-semibold">{store.name}</h1>
- <p className="text-sm text-muted-foreground">
- <Link
- href={StoreController.show.url(store.slug)}
- className="hover:underline"
- >
- Back to store
- </Link>
- </p>
- </div>
-
- <StoreNav slug={store.slug} current="orders" />
-
- <div className="flex flex-wrap items-baseline justify-between gap-3">
- <h2 className="font-medium">
- Orders{' '}
- <span className="text-muted-foreground">
- ({orders.length})
- </span>
- </h2>
- {paid.length > 0 && (
- <p className="text-sm text-muted-foreground tabular-nums">
- {paid.length} paid · {formatRinggit(revenue)} in
- total
- </p>
- )}
- </div>
-
- {orders.length === 0 ? (
- <div className="flex flex-col items-center gap-3 rounded-xl border border-dashed p-10 text-center">
- <ReceiptText className="size-6 text-muted-foreground" />
- <div>
- <p className="font-medium">No orders yet</p>
- <p className="mt-1 max-w-sm text-sm text-muted-foreground">
- When a shopper checks out, their order shows up
- here.
- </p>
- </div>
- </div>
- ) : (
- <div className="overflow-x-auto rounded-xl border">
- <table className="w-full text-sm">
- <thead className="border-b bg-muted/40 text-left text-muted-foreground">
- <tr>
- <th className="px-4 py-2.5 font-medium">
- Order
- </th>
- <th className="px-4 py-2.5 font-medium">
- Date
- </th>
- <th className="px-4 py-2.5 font-medium">
- Customer
- </th>
- <th className="px-4 py-2.5 font-medium">
- Status
- </th>
- <th className="px-4 py-2.5 text-right font-medium">
- Total
- </th>
- </tr>
- </thead>
- <tbody className="divide-y">
- {orders.map((order) => (
- <tr key={order.id}>
- <td className="px-4 py-3">
- <Link
- href={OrderController.show.url({
- slug: store.slug,
- order: order.id,
- })}
- className="font-medium underline-offset-2 hover:underline"
- >
- #{order.number}
- </Link>
- </td>
- <td className="px-4 py-3 whitespace-nowrap text-muted-foreground">
- {formatDateTime(order.created_at)}
- </td>
- <td className="px-4 py-3">
- {order.customer_name}
- </td>
- <td className="px-4 py-3">
- <Badge
- variant={
- order.status === 'paid'
- ? 'default'
- : 'secondary'
- }
- >
- {order.status_label}
- </Badge>
- {order.shipped_at && (
- <Badge
- variant="outline"
- className="ml-1.5"
- >
- Shipped
- </Badge>
- )}
- </td>
- <td className="px-4 py-3 text-right tabular-nums">
- {formatRinggit(order.total)}
- </td>
- </tr>
- ))}
- </tbody>
- </table>
- </div>
- )}
- </div>
- </>
- );
- }
-
- OrdersIndex.layout = {
- breadcrumbs: [
- { title: 'Dashboard', href: dashboard() },
- { title: 'Orders', href: '#' },
- ],
- };
|