AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

index.tsx 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import { Head, Link } from '@inertiajs/react';
  2. import { ReceiptText } from 'lucide-react';
  3. import OrderController from '@/actions/App/Http/Controllers/OrderController';
  4. import StoreController from '@/actions/App/Http/Controllers/StoreController';
  5. import StoreNav from '@/components/stores/store-nav';
  6. import { Badge } from '@/components/ui/badge';
  7. import { formatDateTime, formatRinggit } from '@/lib/money';
  8. import { dashboard } from '@/routes';
  9. import type { Order, StoreSummary } from '@/types';
  10. export default function OrdersIndex({
  11. store,
  12. orders,
  13. }: {
  14. store: StoreSummary;
  15. orders: Order[];
  16. }) {
  17. const paid = orders.filter((order) => order.status === 'paid');
  18. const revenue = paid.reduce((sum, order) => sum + order.total, 0);
  19. return (
  20. <>
  21. <Head title={`Orders - ${store.name}`} />
  22. <div className="mx-auto w-full max-w-6xl space-y-6 p-4">
  23. <div>
  24. <h1 className="text-xl font-semibold">{store.name}</h1>
  25. <p className="text-sm text-muted-foreground">
  26. <Link
  27. href={StoreController.show.url(store.slug)}
  28. className="hover:underline"
  29. >
  30. Back to store
  31. </Link>
  32. </p>
  33. </div>
  34. <StoreNav slug={store.slug} current="orders" />
  35. <div className="flex flex-wrap items-baseline justify-between gap-3">
  36. <h2 className="font-medium">
  37. Orders{' '}
  38. <span className="text-muted-foreground">
  39. ({orders.length})
  40. </span>
  41. </h2>
  42. {paid.length > 0 && (
  43. <p className="text-sm text-muted-foreground tabular-nums">
  44. {paid.length} paid · {formatRinggit(revenue)} in
  45. total
  46. </p>
  47. )}
  48. </div>
  49. {orders.length === 0 ? (
  50. <div className="flex flex-col items-center gap-3 rounded-xl border border-dashed p-10 text-center">
  51. <ReceiptText className="size-6 text-muted-foreground" />
  52. <div>
  53. <p className="font-medium">No orders yet</p>
  54. <p className="mt-1 max-w-sm text-sm text-muted-foreground">
  55. When a shopper checks out, their order shows up
  56. here.
  57. </p>
  58. </div>
  59. </div>
  60. ) : (
  61. <div className="overflow-x-auto rounded-xl border">
  62. <table className="w-full text-sm">
  63. <thead className="border-b bg-muted/40 text-left text-muted-foreground">
  64. <tr>
  65. <th className="px-4 py-2.5 font-medium">
  66. Order
  67. </th>
  68. <th className="px-4 py-2.5 font-medium">
  69. Date
  70. </th>
  71. <th className="px-4 py-2.5 font-medium">
  72. Customer
  73. </th>
  74. <th className="px-4 py-2.5 font-medium">
  75. Status
  76. </th>
  77. <th className="px-4 py-2.5 text-right font-medium">
  78. Total
  79. </th>
  80. </tr>
  81. </thead>
  82. <tbody className="divide-y">
  83. {orders.map((order) => (
  84. <tr key={order.id}>
  85. <td className="px-4 py-3">
  86. <Link
  87. href={OrderController.show.url({
  88. slug: store.slug,
  89. order: order.id,
  90. })}
  91. className="font-medium underline-offset-2 hover:underline"
  92. >
  93. #{order.number}
  94. </Link>
  95. </td>
  96. <td className="px-4 py-3 whitespace-nowrap text-muted-foreground">
  97. {formatDateTime(order.created_at)}
  98. </td>
  99. <td className="px-4 py-3">
  100. {order.customer_name}
  101. </td>
  102. <td className="px-4 py-3">
  103. <Badge
  104. variant={
  105. order.status === 'paid'
  106. ? 'default'
  107. : 'secondary'
  108. }
  109. >
  110. {order.status_label}
  111. </Badge>
  112. {order.shipped_at && (
  113. <Badge
  114. variant="outline"
  115. className="ml-1.5"
  116. >
  117. Shipped
  118. </Badge>
  119. )}
  120. </td>
  121. <td className="px-4 py-3 text-right tabular-nums">
  122. {formatRinggit(order.total)}
  123. </td>
  124. </tr>
  125. ))}
  126. </tbody>
  127. </table>
  128. </div>
  129. )}
  130. </div>
  131. </>
  132. );
  133. }
  134. OrdersIndex.layout = {
  135. breadcrumbs: [
  136. { title: 'Dashboard', href: dashboard() },
  137. { title: 'Orders', href: '#' },
  138. ],
  139. };