@stacksjs/defaults 0.75.489 → 0.75.492
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ai/skills/stacks-actions/SKILL.md +1 -1
- package/ai/skills/stacks-dashboard/SKILL.md +20 -2
- package/ai/skills/stacks-native/CATALOG.md +9 -9
- package/ai/skills/stacks-search-engine/SKILL.md +14 -0
- package/app/Actions/Dashboard/Commerce/CommerceCategoriesAction.ts +7 -13
- package/app/Actions/Dashboard/Commerce/CommerceCustomerChoicesAction.ts +34 -0
- package/app/Actions/Dashboard/Commerce/CommerceDeliveryAction.ts +7 -16
- package/app/Actions/Dashboard/Commerce/CommerceGiftCardsAction.ts +21 -15
- package/app/Actions/Dashboard/Commerce/CommerceGiftCardsExportAction.ts +41 -0
- package/app/Actions/Dashboard/Commerce/CommerceOrderCustomersAction.ts +37 -0
- package/app/Actions/Dashboard/Commerce/CommerceOrdersAction.ts +26 -41
- package/app/Actions/Dashboard/Commerce/CommerceOrdersExportAction.ts +43 -0
- package/app/Actions/Dashboard/Commerce/CommercePaymentsAction.ts +24 -21
- package/app/Actions/Dashboard/Commerce/CommercePaymentsExportAction.ts +41 -0
- package/app/Actions/Dashboard/Commerce/CommercePosAction.ts +18 -48
- package/app/Actions/Dashboard/Commerce/CommercePosProductsAction.ts +39 -0
- package/app/Actions/Dashboard/Commerce/CommercePrintLogsAction.ts +14 -104
- package/app/Actions/Dashboard/Commerce/CommercePrintLogsExportAction.ts +41 -0
- package/app/Actions/Dashboard/Commerce/CommerceProductChoicesAction.ts +32 -0
- package/app/Actions/Dashboard/Commerce/CommerceProductsAction.ts +24 -43
- package/app/Actions/Dashboard/Commerce/CommerceProductsExportAction.ts +44 -0
- package/app/Actions/Dashboard/Commerce/CourierIndexAction.ts +3 -1
- package/app/Actions/Dashboard/Commerce/DeliveryRouteIndexAction.ts +23 -12
- package/app/Actions/Dashboard/Commerce/DigitalDeliveryIndexAction.ts +3 -1
- package/app/Actions/Dashboard/Commerce/LicenseKeyIndexAction.ts +24 -23
- package/app/Actions/Dashboard/Commerce/LicenseKeyOptionsAction.ts +35 -16
- package/app/Actions/Dashboard/Commerce/ProductUnitIndexAction.ts +23 -19
- package/app/Actions/Dashboard/Commerce/ProductVariantIndexAction.ts +25 -18
- package/app/Actions/Dashboard/Commerce/ProductWaitlistIndexAction.ts +22 -22
- package/app/Actions/Dashboard/Commerce/RestaurantWaitlistIndexAction.ts +22 -17
- package/app/Actions/Dashboard/Commerce/ReviewIndexAction.ts +22 -31
- package/app/Actions/Dashboard/Commerce/ShippingMethodIndexAction.ts +3 -1
- package/app/Actions/Dashboard/Commerce/ShippingRateIndexAction.ts +3 -1
- package/app/Actions/Dashboard/Commerce/ShippingZoneIndexAction.ts +3 -1
- package/app/Actions/Dashboard/Commerce/commerce-category-list.test.ts +100 -0
- package/app/Actions/Dashboard/Commerce/commerce-category-list.ts +26 -0
- package/app/Actions/Dashboard/Commerce/commerce-choice-records.ts +56 -0
- package/app/Actions/Dashboard/Commerce/commerce-choices.test.ts +88 -0
- package/app/Actions/Dashboard/Commerce/commerce-choices.ts +70 -0
- package/app/Actions/Dashboard/Commerce/commerce-delivery-overview.test.ts +151 -0
- package/app/Actions/Dashboard/Commerce/commerce-delivery-overview.ts +85 -0
- package/app/Actions/Dashboard/Commerce/commerce-delivery-route-list.test.ts +153 -0
- package/app/Actions/Dashboard/Commerce/commerce-delivery-route-list.ts +180 -0
- package/app/Actions/Dashboard/Commerce/commerce-delivery.ts +24 -9
- package/app/Actions/Dashboard/Commerce/commerce-gift-card-list.test.ts +221 -0
- package/app/Actions/Dashboard/Commerce/commerce-gift-card-list.ts +259 -0
- package/app/Actions/Dashboard/Commerce/commerce-license-key-list.test.ts +184 -0
- package/app/Actions/Dashboard/Commerce/commerce-license-key-list.ts +217 -0
- package/app/Actions/Dashboard/Commerce/commerce-order-list.test.ts +183 -0
- package/app/Actions/Dashboard/Commerce/commerce-order-list.ts +278 -0
- package/app/Actions/Dashboard/Commerce/commerce-order-records.test.ts +29 -0
- package/app/Actions/Dashboard/Commerce/commerce-payment-list.test.ts +180 -0
- package/app/Actions/Dashboard/Commerce/commerce-payment-list.ts +272 -0
- package/app/Actions/Dashboard/Commerce/commerce-pos-catalog.test.ts +171 -0
- package/app/Actions/Dashboard/Commerce/commerce-pos-catalog.ts +152 -0
- package/app/Actions/Dashboard/Commerce/commerce-pos.test.ts +1 -12
- package/app/Actions/Dashboard/Commerce/commerce-pos.ts +0 -26
- package/app/Actions/Dashboard/Commerce/commerce-print-log-list.test.ts +202 -0
- package/app/Actions/Dashboard/Commerce/commerce-print-log-list.ts +286 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-list.test.ts +174 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-list.ts +276 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-unit-list.test.ts +146 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-unit-list.ts +178 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-variant-list.test.ts +165 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-variant-list.ts +209 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-waitlist-list.test.ts +183 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-waitlist-list.ts +170 -0
- package/app/Actions/Dashboard/Commerce/commerce-record.ts +21 -0
- package/app/Actions/Dashboard/Commerce/commerce-restaurant-waitlist-list.test.ts +189 -0
- package/app/Actions/Dashboard/Commerce/commerce-restaurant-waitlist-list.ts +177 -0
- package/app/Actions/Dashboard/Commerce/commerce-review-list.test.ts +193 -0
- package/app/Actions/Dashboard/Commerce/commerce-review-list.ts +220 -0
- package/app/Actions/Dashboard/Commerce/commerce-sql.ts +57 -0
- package/app/Actions/Dashboard/Commerce/payment-records.test.ts +16 -0
- package/app/Actions/Dashboard/Commerce/product-unit-records.test.ts +0 -13
- package/app/Actions/Dashboard/Commerce/product-unit-records.ts +0 -17
- package/app/Actions/Dashboard/Commerce/product-variant-records.test.ts +0 -13
- package/app/Actions/Dashboard/Commerce/product-variant-records.ts +0 -17
- package/app/Actions/Dashboard/Commerce/product-waitlist-records.test.ts +6 -5
- package/app/Actions/Dashboard/Commerce/product-waitlist-records.ts +16 -45
- package/app/Actions/Dashboard/Commerce/restaurant-waitlist-records.ts +4 -24
- package/app/Actions/Dashboard/Content/content-list.ts +10 -0
- package/app/Actions/Dashboard/Content/file-listing-metadata.test.ts +46 -0
- package/app/Actions/Dashboard/Content/file-manager.ts +51 -10
- package/app/Actions/Dashboard/DashboardHomeAction.test.ts +13 -9
- package/app/Actions/Dashboard/DashboardHomeAction.ts +42 -21
- package/app/Actions/Dashboard/Jobs/JobStatsAction.ts +5 -2
- package/app/Actions/Dashboard/Kanban/UsersListAction.ts +13 -9
- package/app/Actions/Dashboard/Kanban/kanban-response.test.ts +40 -0
- package/app/Actions/Dashboard/Kanban/kanban-response.ts +53 -1
- package/app/Actions/Dashboard/Kanban/kanban-users.test.ts +114 -0
- package/app/Actions/Dashboard/Kanban/kanban-users.ts +32 -0
- package/app/Actions/Dashboard/Models/ModelShowAction.ts +8 -0
- package/app/Actions/Dashboard/Models/ModelsIndexAction.ts +16 -2
- package/app/Actions/Dashboard/Models/model-migration.test.ts +27 -0
- package/app/Actions/Dashboard/Models/model-migration.ts +23 -0
- package/app/Actions/Dashboard/Queue/QueueStatsAction.ts +5 -3
- package/app/Actions/Dashboard/Queue/QueueWorkersAction.ts +3 -2
- package/app/Actions/Dashboard/Queue/worker-snapshots.test.ts +31 -0
- package/app/Actions/Dashboard/Queue/worker-snapshots.ts +33 -0
- package/app/Actions/Dashboard/named-search.test.ts +36 -0
- package/app/Actions/Dashboard/named-search.ts +80 -0
- package/app/Models/Request.ts +4 -2
- package/functions/commerce/shippings/dashboard-resource.ts +12 -1
- package/functions/commerce/shippings/delivery-routes.ts +1 -0
- package/functions/commerce/shippings/license-keys.ts +1 -0
- package/functions/dashboard-list.test.ts +146 -1
- package/functions/dashboard-list.ts +216 -1
- package/functions/queue.ts +2 -0
- package/ide/vscode/package.json +1 -1
- package/package.json +2 -2
- package/resources/components/Dashboard/Commerce/CommerceGiftCardBreakdown.stx +38 -12
- package/resources/components/Dashboard/Commerce/CommerceGiftCardsDashboard.stx +122 -68
- package/resources/components/Dashboard/Commerce/CommerceGiftCardsTable.stx +29 -6
- package/resources/components/Dashboard/Commerce/CommerceOrderDialog.stx +59 -2
- package/resources/components/Dashboard/Commerce/CommerceOrdersDashboard.stx +126 -80
- package/resources/components/Dashboard/Commerce/CommerceOrdersTable.stx +28 -3
- package/resources/components/Dashboard/Commerce/CommercePaymentsBreakdown.stx +12 -29
- package/resources/components/Dashboard/Commerce/CommercePaymentsDashboard.stx +139 -60
- package/resources/components/Dashboard/Commerce/CommercePaymentsTable.stx +27 -2
- package/resources/components/Dashboard/Commerce/CommercePosCatalog.stx +17 -1
- package/resources/components/Dashboard/Commerce/CommercePosCheckoutDialog.stx +47 -3
- package/resources/components/Dashboard/Commerce/CommercePosDashboard.stx +59 -49
- package/resources/components/Dashboard/Commerce/CommerceProductsDashboard.stx +116 -82
- package/resources/components/Dashboard/Commerce/CommerceProductsTable.stx +28 -4
- package/resources/components/Dashboard/Commerce/CommerceReviewsDashboard.stx +120 -69
- package/resources/components/Dashboard/Commerce/CommerceReviewsTable.stx +29 -6
- package/resources/components/Dashboard/Commerce/CommerceUnitDialog.stx +63 -8
- package/resources/components/Dashboard/Commerce/CommerceUnitsDashboard.stx +48 -60
- package/resources/components/Dashboard/Commerce/CommerceUnitsTable.stx +29 -3
- package/resources/components/Dashboard/Commerce/CommerceVariantDialog.stx +57 -3
- package/resources/components/Dashboard/Commerce/CommerceVariantsDashboard.stx +59 -61
- package/resources/components/Dashboard/Commerce/CommerceVariantsTable.stx +28 -2
- package/resources/components/Dashboard/Commerce/Delivery/DeliveryRoutesDashboard.stx +79 -52
- package/resources/components/Dashboard/Commerce/Delivery/DeliveryRoutesTable.stx +31 -8
- package/resources/components/Dashboard/Commerce/Delivery/LicenseKeyDialog.stx +71 -13
- package/resources/components/Dashboard/Commerce/Delivery/LicenseKeysDashboard.stx +69 -81
- package/resources/components/Dashboard/Commerce/Delivery/LicenseKeysTable.stx +31 -8
- package/resources/components/Dashboard/Commerce/PrintLogBreakdown.stx +21 -17
- package/resources/components/Dashboard/Commerce/PrintLogsDashboard.stx +23 -22
- package/resources/components/Dashboard/Commerce/ProductWaitlistDashboard.stx +116 -20
- package/resources/components/Dashboard/Commerce/ProductWaitlistEntryDialog.stx +100 -12
- package/resources/components/Dashboard/Commerce/ProductWaitlistTable.stx +34 -16
- package/resources/components/Dashboard/Commerce/RestaurantWaitlistDashboard.stx +107 -19
- package/resources/components/Dashboard/Commerce/RestaurantWaitlistEntryDialog.stx +65 -6
- package/resources/components/Dashboard/Commerce/RestaurantWaitlistTable.stx +29 -3
- package/resources/components/Dashboard/Kanban/KanbanBoardsDashboard.stx +10 -1
- package/resources/components/Dashboard/Kanban/KanbanCardDialog.stx +21 -1
- package/resources/components/Dashboard/Models/ModelRecordsDashboard.stx +24 -4
- package/resources/components/Dashboard/Models/ModelsOverview.stx +13 -2
- package/resources/components/Dashboard/Queue/QueueDashboard.stx +7 -1
- package/routes/dashboard-api.ts +11 -0
- package/views/dashboard/stores/kanban.ts +38 -6
|
@@ -2,16 +2,17 @@
|
|
|
2
2
|
import type {
|
|
3
3
|
CommerceOrderRecord,
|
|
4
4
|
CommerceOrderSummary,
|
|
5
|
-
OrderCustomerOption,
|
|
6
5
|
} from '../../../../app/Actions/Dashboard/Commerce/commerce-order-records'
|
|
7
6
|
import { DashboardApiError, dashboardApi } from '../../../../functions/dashboard-api'
|
|
8
7
|
import { pushToast } from '../../../../functions/toasts'
|
|
9
|
-
import { formatCurrency
|
|
8
|
+
import { formatCurrency } from '@stacksjs/commerce/money'
|
|
10
9
|
|
|
11
10
|
interface OrderIndexResponse {
|
|
12
11
|
records: CommerceOrderRecord[]
|
|
12
|
+
total: number
|
|
13
|
+
page: number
|
|
14
|
+
perPage: number
|
|
13
15
|
summary: CommerceOrderSummary
|
|
14
|
-
customers: OrderCustomerOption[]
|
|
15
16
|
statuses: string[]
|
|
16
17
|
orderTypes: string[]
|
|
17
18
|
defaultCurrency: string
|
|
@@ -44,7 +45,6 @@ const emptySummary: CommerceOrderSummary = {
|
|
|
44
45
|
}
|
|
45
46
|
const records = state<CommerceOrderRecord[]>([])
|
|
46
47
|
const summary = state<CommerceOrderSummary>({ ...emptySummary })
|
|
47
|
-
const customers = state<OrderCustomerOption[]>([])
|
|
48
48
|
const statuses = state<string[]>([])
|
|
49
49
|
const orderTypes = state<string[]>([])
|
|
50
50
|
const defaultCurrency = state('USD')
|
|
@@ -52,6 +52,15 @@ const search = state('')
|
|
|
52
52
|
const statusFilter = state('all')
|
|
53
53
|
const typeFilter = state('all')
|
|
54
54
|
const sort = state('newest')
|
|
55
|
+
// A column header's sort, which takes over from the select until it changes.
|
|
56
|
+
const headerSort = state<{ sort: string, direction: string } | null>(null)
|
|
57
|
+
// How many orders match the search and filters, across every page.
|
|
58
|
+
const matchingTotal = state(0)
|
|
59
|
+
const page = state(1)
|
|
60
|
+
const perPage = state(25)
|
|
61
|
+
const appliedSearch = state('')
|
|
62
|
+
let listRequest = 0
|
|
63
|
+
let searchTimer: ReturnType<typeof setTimeout> | null = null
|
|
55
64
|
const loading = state(true)
|
|
56
65
|
const loadError = state('')
|
|
57
66
|
const dialogOpen = state(false)
|
|
@@ -63,16 +72,6 @@ const saving = state(false)
|
|
|
63
72
|
const deleting = state(false)
|
|
64
73
|
const validationErrors = state<Record<string, string>>({})
|
|
65
74
|
|
|
66
|
-
function timestamp(value: string): number {
|
|
67
|
-
if (!value)
|
|
68
|
-
return 0
|
|
69
|
-
const normalized = /^\d{4}-\d{2}-\d{2} \d/.test(value)
|
|
70
|
-
? `${value.replace(' ', 'T')}Z`
|
|
71
|
-
: value
|
|
72
|
-
const result = new Date(normalized).getTime()
|
|
73
|
-
return Number.isFinite(result) ? result : 0
|
|
74
|
-
}
|
|
75
|
-
|
|
76
75
|
function formatMoney(value: number, currency: string): string {
|
|
77
76
|
return formatCurrency(value, currency)
|
|
78
77
|
}
|
|
@@ -81,39 +80,46 @@ function label(value: string): string {
|
|
|
81
80
|
return value.replaceAll('_', ' ').toLowerCase().replace(/\b\w/g, letter => letter.toUpperCase())
|
|
82
81
|
}
|
|
83
82
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
83
|
+
/** The select's four orders, as the server's sort and direction. */
|
|
84
|
+
const SELECT_SORTS: Record<string, { sort: string, direction: string }> = {
|
|
85
|
+
'newest': { sort: 'created', direction: 'desc' },
|
|
86
|
+
'oldest': { sort: 'created', direction: 'asc' },
|
|
87
|
+
'total-high': { sort: 'total', direction: 'desc' },
|
|
88
|
+
'total-low': { sort: 'total', direction: 'asc' },
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The table's sortable columns, as the server's sort names. */
|
|
92
|
+
const COLUMN_SORTS: Record<string, string> = {
|
|
93
|
+
orderLabel: 'id',
|
|
94
|
+
customerLabel: 'customer',
|
|
95
|
+
totalAmount: 'total',
|
|
96
|
+
fulfillmentLabel: 'type',
|
|
97
|
+
statusTone: 'status',
|
|
98
|
+
createdAt: 'created',
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The search, filters and order, as the query the server takes
|
|
103
|
+
* (stacksjs/stacks#3218): it searches, filters, sorts and pages every order,
|
|
104
|
+
* where this page used to do all of that with the newest 500.
|
|
105
|
+
*/
|
|
106
|
+
function filterParams(): URLSearchParams {
|
|
107
|
+
const params = new URLSearchParams()
|
|
108
|
+
const order = headerSort() ?? SELECT_SORTS[sort()] ?? SELECT_SORTS.newest
|
|
109
|
+
params.set('sort', order.sort)
|
|
110
|
+
params.set('direction', order.direction)
|
|
111
|
+
if (appliedSearch())
|
|
112
|
+
params.set('q', appliedSearch())
|
|
113
|
+
if (statusFilter() !== 'all')
|
|
114
|
+
params.set('status', statusFilter())
|
|
115
|
+
if (typeFilter() !== 'all')
|
|
116
|
+
params.set('type', typeFilter())
|
|
117
|
+
return params
|
|
112
118
|
}
|
|
113
119
|
|
|
114
120
|
function matchingLabel(): string {
|
|
115
|
-
const count =
|
|
116
|
-
return `${count} matching ${count === 1 ? 'order' : 'orders'}`
|
|
121
|
+
const count = matchingTotal()
|
|
122
|
+
return `${count.toLocaleString()} matching ${count === 1 ? 'order' : 'orders'}`
|
|
117
123
|
}
|
|
118
124
|
|
|
119
125
|
function metricCards(): Array<{ label: string, value: string, detail: string }> {
|
|
@@ -127,62 +133,102 @@ function metricCards(): Array<{ label: string, value: string, detail: string }>
|
|
|
127
133
|
]
|
|
128
134
|
}
|
|
129
135
|
|
|
136
|
+
/** Every matching order as CSV, built by the server, not just the page shown. */
|
|
130
137
|
function exportHref(): string {
|
|
131
|
-
|
|
132
|
-
record.id,
|
|
133
|
-
record.customerName,
|
|
134
|
-
record.customerEmail,
|
|
135
|
-
record.status,
|
|
136
|
-
record.orderType,
|
|
137
|
-
String(record.itemCount),
|
|
138
|
-
minorToInput(record.totalAmount, record.currency),
|
|
139
|
-
record.currency,
|
|
140
|
-
minorToInput(record.taxAmount, record.currency),
|
|
141
|
-
minorToInput(record.discountAmount, record.currency),
|
|
142
|
-
minorToInput(record.deliveryFee, record.currency),
|
|
143
|
-
minorToInput(record.tipAmount, record.currency),
|
|
144
|
-
record.deliveryAddress,
|
|
145
|
-
record.createdAt,
|
|
146
|
-
])
|
|
147
|
-
const escape = (value: string): string => `"${value.replaceAll('"', '""')}"`
|
|
148
|
-
const csv = [
|
|
149
|
-
['Order ID', 'Customer', 'Customer email', 'Status', 'Order type', 'Items', 'Total', 'Currency', 'Tax', 'Discount', 'Delivery fee', 'Tip', 'Delivery address', 'Created at'],
|
|
150
|
-
...rows,
|
|
151
|
-
].map(row => row.map(escape).join(',')).join('\n')
|
|
152
|
-
return `data:text/csv;charset=utf-8,${encodeURIComponent(`\uFEFF${csv}`)}`
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* What the table is showing: a change returns it to the first page, as this
|
|
157
|
-
* page's own pager did before the table took over paging.
|
|
158
|
-
*/
|
|
159
|
-
function viewKey(): string {
|
|
160
|
-
return JSON.stringify([search(), statusFilter(), typeFilter(), sort()])
|
|
138
|
+
return `/api/dashboard/commerce/orders/export?${filterParams()}`
|
|
161
139
|
}
|
|
162
140
|
|
|
163
141
|
async function loadOrders(): Promise<void> {
|
|
142
|
+
const request = ++listRequest
|
|
164
143
|
loading.set(true)
|
|
165
144
|
loadError.set('')
|
|
166
145
|
try {
|
|
167
|
-
const
|
|
146
|
+
const params = filterParams()
|
|
147
|
+
params.set('page', String(page()))
|
|
148
|
+
params.set('per_page', String(perPage()))
|
|
149
|
+
const data = await dashboardApi<OrderIndexResponse>(`/api/dashboard/commerce/orders?${params}`)
|
|
150
|
+
// Only the newest request lands: a slower answer to an older search does
|
|
151
|
+
// not overwrite the one for what is typed now.
|
|
152
|
+
if (request !== listRequest)
|
|
153
|
+
return
|
|
168
154
|
records.set(Array.isArray(data.records) ? data.records : [])
|
|
155
|
+
matchingTotal.set(Number(data.total) || 0)
|
|
156
|
+
// The server moves back to the last page when a delete or a narrower
|
|
157
|
+
// filter leaves this one past the end.
|
|
158
|
+
page.set(Number(data.page) || 1)
|
|
169
159
|
summary.set(data.summary ?? { ...emptySummary })
|
|
170
|
-
customers.set(Array.isArray(data.customers) ? data.customers : [])
|
|
171
160
|
statuses.set(Array.isArray(data.statuses) ? data.statuses : [])
|
|
172
161
|
orderTypes.set(Array.isArray(data.orderTypes) ? data.orderTypes : [])
|
|
173
162
|
defaultCurrency.set(data.defaultCurrency || 'USD')
|
|
174
163
|
}
|
|
175
164
|
catch (error) {
|
|
165
|
+
if (request !== listRequest)
|
|
166
|
+
return
|
|
176
167
|
loadError.set('Order records could not be loaded.')
|
|
177
168
|
pushToast('error', 'Could not load orders', {
|
|
178
169
|
detail: error instanceof Error ? error.message : String(error),
|
|
179
170
|
})
|
|
180
171
|
}
|
|
181
172
|
finally {
|
|
182
|
-
|
|
173
|
+
if (request === listRequest)
|
|
174
|
+
loading.set(false)
|
|
183
175
|
}
|
|
184
176
|
}
|
|
185
177
|
|
|
178
|
+
function eventValue<T>(value: T | CustomEvent<T>): T {
|
|
179
|
+
return value instanceof CustomEvent ? value.detail : value
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function changePage(value: number | CustomEvent<number>): void {
|
|
183
|
+
page.set(Number(eventValue(value)) || 1)
|
|
184
|
+
void loadOrders()
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function changePageSize(value: number | CustomEvent<number>): void {
|
|
188
|
+
perPage.set(Number(eventValue(value)) || 25)
|
|
189
|
+
page.set(1)
|
|
190
|
+
void loadOrders()
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function changeColumnSort(value: { key: string, direction: string } | CustomEvent<{ key: string, direction: string }>): void {
|
|
194
|
+
const column = eventValue(value)
|
|
195
|
+
const serverSort = COLUMN_SORTS[column.key]
|
|
196
|
+
headerSort.set(serverSort ? { sort: serverSort, direction: column.direction === 'asc' ? 'asc' : 'desc' } : null)
|
|
197
|
+
page.set(1)
|
|
198
|
+
void loadOrders()
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// The filters and the select ask the server for page 1 when they change, and
|
|
202
|
+
// the search once typing pauses. A select change also hands the order back
|
|
203
|
+
// from a column header.
|
|
204
|
+
let shownFilters = JSON.stringify([statusFilter(), typeFilter(), sort()])
|
|
205
|
+
effect(() => {
|
|
206
|
+
const filters = JSON.stringify([statusFilter(), typeFilter(), sort()])
|
|
207
|
+
if (filters === shownFilters)
|
|
208
|
+
return
|
|
209
|
+
const sortChanged = JSON.parse(shownFilters)[2] !== sort()
|
|
210
|
+
shownFilters = filters
|
|
211
|
+
if (sortChanged)
|
|
212
|
+
headerSort.set(null)
|
|
213
|
+
page.set(1)
|
|
214
|
+
void loadOrders()
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
let shownSearch = search().trim()
|
|
218
|
+
effect(() => {
|
|
219
|
+
const term = search().trim()
|
|
220
|
+
if (term === shownSearch)
|
|
221
|
+
return
|
|
222
|
+
shownSearch = term
|
|
223
|
+
if (searchTimer)
|
|
224
|
+
clearTimeout(searchTimer)
|
|
225
|
+
searchTimer = setTimeout(() => {
|
|
226
|
+
appliedSearch.set(term)
|
|
227
|
+
page.set(1)
|
|
228
|
+
void loadOrders()
|
|
229
|
+
}, 250)
|
|
230
|
+
})
|
|
231
|
+
|
|
186
232
|
function openAdd(): void {
|
|
187
233
|
dialogMode.set('add')
|
|
188
234
|
editingRecord.set(null)
|
|
@@ -281,7 +327,7 @@ onMount(() => {
|
|
|
281
327
|
<PageHeader title="Orders" description="Manage native Order records, customer assignments, totals, and fulfillment state.">
|
|
282
328
|
<div class="flex flex-wrap gap-2">
|
|
283
329
|
<Button variant="secondary" :loading="loading()" @click="loadOrders()"><span :if="!loading()" class="h-4 w-4 i-hugeicons-refresh"></span>Refresh</Button>
|
|
284
|
-
<Button tag="a" variant="secondary" :href="exportHref()"
|
|
330
|
+
<Button tag="a" variant="secondary" :href="exportHref()" download><span class="h-4 w-4 i-hugeicons-download-04"></span>Export filtered</Button>
|
|
285
331
|
<Button @click="openAdd()"><span class="h-4 w-4 i-hugeicons-add-01"></span>Add order</Button>
|
|
286
332
|
</div>
|
|
287
333
|
</PageHeader>
|
|
@@ -311,10 +357,10 @@ onMount(() => {
|
|
|
311
357
|
<p class="text-gray-500 text-sm dark:text-neutral-400">{{ matchingLabel() }}</p>
|
|
312
358
|
</div>
|
|
313
359
|
|
|
314
|
-
<CommerceOrdersTable :sort-reset-key="sort()" :page
|
|
360
|
+
<CommerceOrdersTable :sort-reset-key="sort()" :records="records()" :total="matchingTotal()" :current-page="page()" :per-page="perPage()" :loading="loading()" @view="openDetails" @edit="openEdit" @delete="openDelete" @page-change="changePage" @page-size-change="changePageSize" @sort="changeColumnSort" />
|
|
315
361
|
</section>
|
|
316
362
|
</div>
|
|
317
363
|
|
|
318
|
-
<CommerceOrderDialog :open="dialogOpen()" :mode="dialogMode()" :record="editingRecord()" :
|
|
364
|
+
<CommerceOrderDialog :open="dialogOpen()" :mode="dialogMode()" :record="editingRecord()" :statuses="statuses()" :order-types="orderTypes()" :default-currency="defaultCurrency()" :busy="saving()" :errors="validationErrors()" @submit="saveOrder" @close="closeDialog()" />
|
|
319
365
|
<CommerceOrderDetailsDialog :open="Boolean(detailsRecord())" :record="detailsRecord()" @edit="openEdit" @delete="openDelete" @close="closeDetails()" />
|
|
320
366
|
<CommerceOrderDeleteDialog :open="Boolean(deletingRecord())" :record="deletingRecord()" :busy="deleting()" @confirm="deleteOrder()" @close="closeDelete()" />
|
|
@@ -9,7 +9,13 @@ const loading = useReactiveProp('loading', false)
|
|
|
9
9
|
const sortResetKey = useReactiveProp<unknown>('sortResetKey', '')
|
|
10
10
|
/** The parent's search and filters: a change returns to the first page. */
|
|
11
11
|
const pageResetKey = useReactiveProp<unknown>('pageResetKey', '')
|
|
12
|
-
|
|
12
|
+
// One page the server chose (stacksjs/stacks#3218): it searches, filters, sorts
|
|
13
|
+
// and pages the orders, so this shows them as given and hands paging and
|
|
14
|
+
// column sorting back to the parent.
|
|
15
|
+
const total = useReactiveProp('total', 0)
|
|
16
|
+
const currentPage = useReactiveProp('currentPage', 1)
|
|
17
|
+
const perPage = useReactiveProp('perPage', 25)
|
|
18
|
+
const emit = defineEmits(['view', 'edit', 'delete', 'page-change', 'page-size-change', 'sort'])
|
|
13
19
|
|
|
14
20
|
function label(value: string): string {
|
|
15
21
|
return value.replaceAll('_', ' ').toLowerCase().replace(/\b\w/g, letter => letter.toUpperCase())
|
|
@@ -71,11 +77,23 @@ const rows = derived(() => records().map(record => ({
|
|
|
71
77
|
function handleRowAction(payload: { action: string, row: CommerceOrderRecord }): void {
|
|
72
78
|
emit(payload.action, payload.row)
|
|
73
79
|
}
|
|
80
|
+
|
|
81
|
+
function changePage(page: number): void {
|
|
82
|
+
emit('page-change', page)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function changePageSize(size: number): void {
|
|
86
|
+
emit('page-size-change', size)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function changeSort(sort: { key: string, direction: string }): void {
|
|
90
|
+
emit('sort', sort)
|
|
91
|
+
}
|
|
74
92
|
</script>
|
|
75
93
|
|
|
76
94
|
{{--
|
|
77
95
|
No `searchable` or `filterable`: the parent dashboard owns the search box
|
|
78
|
-
and the filter selects
|
|
96
|
+
and the filter selects, and the server pages and sorts what they match.
|
|
79
97
|
--}}
|
|
80
98
|
<Table
|
|
81
99
|
:sort-reset-key="sortResetKey()"
|
|
@@ -86,8 +104,15 @@ function handleRowAction(payload: { action: string, row: CommerceOrderRecord }):
|
|
|
86
104
|
:row-actions="ROW_ACTIONS"
|
|
87
105
|
action-label-key="id"
|
|
88
106
|
paginated
|
|
89
|
-
|
|
107
|
+
manual-pagination
|
|
108
|
+
manual-sort
|
|
109
|
+
:total="total()"
|
|
110
|
+
:current-page="currentPage()"
|
|
111
|
+
:page-size="perPage()"
|
|
90
112
|
empty-title="No orders found"
|
|
91
113
|
empty-description="Adjust the filters or add a native Order record."
|
|
92
114
|
@row-action="handleRowAction"
|
|
115
|
+
@page-change="changePage"
|
|
116
|
+
@page-size-change="changePageSize"
|
|
117
|
+
@sort="changeSort"
|
|
93
118
|
/>
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
<script client>
|
|
2
|
-
import type {
|
|
3
|
-
PaymentRecord,
|
|
4
|
-
} from '../../../../app/Actions/Dashboard/Commerce/payment-records'
|
|
5
|
-
import { isSuccessfulPayment } from '../../../../app/Actions/Dashboard/Commerce/payment-records'
|
|
2
|
+
import type { PaymentBreakdown } from '../../../../app/Actions/Dashboard/Commerce/commerce-payment-list'
|
|
6
3
|
import { formatCurrency } from '@stacksjs/commerce/money'
|
|
7
4
|
|
|
8
5
|
interface CountRow {
|
|
@@ -17,38 +14,24 @@ interface CurrencyRow {
|
|
|
17
14
|
refunded: number
|
|
18
15
|
}
|
|
19
16
|
|
|
20
|
-
|
|
17
|
+
// Counted by the server over every matching payment (stacksjs/stacks#3218);
|
|
18
|
+
// this used to count whichever of the newest 500 matched.
|
|
19
|
+
const breakdown = useReactiveProp('breakdown', { statuses: [], methods: [], currencies: [] } as PaymentBreakdown)
|
|
21
20
|
|
|
22
21
|
function countRows(field: 'status' | 'method'): CountRow[] {
|
|
23
|
-
const counts =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
.map(([key, count]) => ({
|
|
31
|
-
key,
|
|
32
|
-
count,
|
|
33
|
-
percentage: total ? Math.round((count / total) * 1000) / 10 : 0,
|
|
22
|
+
const counts = field === 'status' ? breakdown().statuses : breakdown().methods
|
|
23
|
+
const total = counts.reduce((sum, row) => sum + row.count, 0)
|
|
24
|
+
return counts
|
|
25
|
+
.map(row => ({
|
|
26
|
+
key: row.key,
|
|
27
|
+
count: row.count,
|
|
28
|
+
percentage: total ? Math.round((row.count / total) * 1000) / 10 : 0,
|
|
34
29
|
}))
|
|
35
30
|
.sort((left, right) => right.count - left.count || left.key.localeCompare(right.key))
|
|
36
31
|
}
|
|
37
32
|
|
|
38
33
|
function currencyRows(): CurrencyRow[] {
|
|
39
|
-
|
|
40
|
-
for (const record of records()) {
|
|
41
|
-
const row = currencies.get(record.currency) ?? {
|
|
42
|
-
currency: record.currency,
|
|
43
|
-
captured: 0,
|
|
44
|
-
refunded: 0,
|
|
45
|
-
}
|
|
46
|
-
if (isSuccessfulPayment(record))
|
|
47
|
-
row.captured += record.amount
|
|
48
|
-
row.refunded += record.refundAmount
|
|
49
|
-
currencies.set(record.currency, row)
|
|
50
|
-
}
|
|
51
|
-
return [...currencies.values()].sort((left, right) => right.captured - left.captured)
|
|
34
|
+
return [...breakdown().currencies].sort((left, right) => right.captured - left.captured)
|
|
52
35
|
}
|
|
53
36
|
|
|
54
37
|
function label(value: string): string {
|