@stacksjs/defaults 0.75.487 → 0.75.490
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 +27 -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/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-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-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 +9 -6
- package/app/Actions/Dashboard/Queue/QueueWorkersAction.ts +3 -2
- package/app/Actions/Dashboard/Queue/queue-stats.ts +10 -0
- 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/QueueWorker.ts +1 -0
- package/app/Models/Request.ts +4 -2
- package/bootstrap.ts +6 -1
- 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 +132 -1
- package/functions/dashboard-list.ts +198 -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/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 +8 -2
- package/resources/functions/dashboard/sidebar.ts +26 -1
- package/routes/dashboard-api.ts +11 -0
- package/views/dashboard/stores/kanban.ts +38 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script client>
|
|
2
2
|
import { dashboardApi } from '../../../../../functions/dashboard-api'
|
|
3
|
-
import { useRecordsDashboard } from '../../../../../functions/dashboard-list'
|
|
3
|
+
import { useRecordsDashboard, useServerList } from '../../../../../functions/dashboard-list'
|
|
4
4
|
import { pushToast } from '../../../../../functions/toasts'
|
|
5
5
|
|
|
6
6
|
interface CourierRecord {
|
|
@@ -32,23 +32,25 @@ interface DeliveryRoutePayload {
|
|
|
32
32
|
lastActive: number
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
]
|
|
35
|
+
interface DeliveryRouteSummary {
|
|
36
|
+
total: number
|
|
37
|
+
linked: number
|
|
38
|
+
stops: number
|
|
39
|
+
distance: number
|
|
40
|
+
active: number
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface DeliveryRoutePage {
|
|
44
|
+
records: DeliveryRouteRecord[]
|
|
45
|
+
total: number
|
|
46
|
+
page: number
|
|
47
|
+
summary?: DeliveryRouteSummary
|
|
45
48
|
}
|
|
46
49
|
|
|
50
|
+
// The dialog and the delete confirmation. The list itself is the server's
|
|
51
|
+
// (stacksjs/stacks#3218): this page used to read the 500 most recently
|
|
52
|
+
// active routes and search, page and count them in the browser.
|
|
47
53
|
const {
|
|
48
|
-
records,
|
|
49
|
-
loading,
|
|
50
|
-
loadError,
|
|
51
|
-
search,
|
|
52
54
|
editorOpen,
|
|
53
55
|
editorMode,
|
|
54
56
|
editing,
|
|
@@ -57,18 +59,43 @@ const {
|
|
|
57
59
|
deleting,
|
|
58
60
|
deleteBusy,
|
|
59
61
|
deleteError,
|
|
60
|
-
filteredRecords,
|
|
61
|
-
handleSearch,
|
|
62
62
|
openCreate,
|
|
63
63
|
openEdit,
|
|
64
64
|
closeEditor,
|
|
65
65
|
requestDelete,
|
|
66
66
|
closeDelete,
|
|
67
|
-
|
|
68
|
-
remove,
|
|
69
|
-
} = useRecordsDashboard<DeliveryRouteRecord>({ filter: matchesQuery })
|
|
67
|
+
} = useRecordsDashboard<DeliveryRouteRecord>({ filter: records => records })
|
|
70
68
|
|
|
71
69
|
const couriers = state<CourierRecord[]>([])
|
|
70
|
+
const summary = state<DeliveryRouteSummary>({ total: 0, linked: 0, stops: 0, distance: 0, active: 0 })
|
|
71
|
+
|
|
72
|
+
const {
|
|
73
|
+
records,
|
|
74
|
+
total,
|
|
75
|
+
page,
|
|
76
|
+
perPage,
|
|
77
|
+
search,
|
|
78
|
+
loading,
|
|
79
|
+
loadError,
|
|
80
|
+
load,
|
|
81
|
+
changePage,
|
|
82
|
+
changePageSize,
|
|
83
|
+
changeSort,
|
|
84
|
+
} = useServerList<DeliveryRouteRecord>({
|
|
85
|
+
fetch: params => dashboardApi<DeliveryRoutePage>(`/api/dashboard/commerce/delivery-routes?${params}`),
|
|
86
|
+
defaultSort: { sort: 'active', direction: 'desc' },
|
|
87
|
+
columnSorts: {
|
|
88
|
+
routeLabel: 'id',
|
|
89
|
+
courierLabel: 'courier',
|
|
90
|
+
vehicle: 'vehicle',
|
|
91
|
+
stops: 'stops',
|
|
92
|
+
delivery_time: 'time',
|
|
93
|
+
total_distance: 'distance',
|
|
94
|
+
last_active: 'active',
|
|
95
|
+
},
|
|
96
|
+
onLoad: result => summary.set((result as DeliveryRoutePage).summary ?? { total: 0, linked: 0, stops: 0, distance: 0, active: 0 }),
|
|
97
|
+
onError: error => pushToast('error', 'Could not load delivery routes', { detail: error instanceof Error ? error.message : String(error) }),
|
|
98
|
+
})
|
|
72
99
|
|
|
73
100
|
function courierFor(id?: number | null): CourierRecord | undefined {
|
|
74
101
|
return id ? couriers().find(courier => courier.id === id) : undefined
|
|
@@ -81,47 +108,47 @@ function withCourier(record: DeliveryRouteRecord): DeliveryRouteRecord {
|
|
|
81
108
|
}
|
|
82
109
|
}
|
|
83
110
|
|
|
84
|
-
function
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
111
|
+
function rows(): DeliveryRouteRecord[] {
|
|
112
|
+
return records().map(withCourier)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function handleSearch(value: string): void {
|
|
116
|
+
search.set(value)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function matchingLabel(): string {
|
|
120
|
+
const count = total()
|
|
121
|
+
return `${count.toLocaleString()} matching ${count === 1 ? 'record' : 'records'}`
|
|
88
122
|
}
|
|
89
123
|
|
|
90
124
|
function metricCards(): Array<{ label: string, value: string, detail: string }> {
|
|
91
|
-
const
|
|
92
|
-
const totalDistance = records().reduce((sum, record) => sum + record.total_distance, 0)
|
|
93
|
-
const activeCutoff = Date.now() - (24 * 60 * 60 * 1000)
|
|
94
|
-
const activeRoutes = records().filter(record => routeTime(record.last_active) >= activeCutoff).length
|
|
125
|
+
const current = summary()
|
|
95
126
|
return [
|
|
96
|
-
{ label: 'Routes', value:
|
|
97
|
-
{ label: 'Stops', value:
|
|
98
|
-
{ label: 'Distance', value: `${
|
|
99
|
-
{ label: 'Active in 24h', value:
|
|
127
|
+
{ label: 'Routes', value: current.total.toLocaleString(), detail: `${current.linked.toLocaleString()} linked to couriers` },
|
|
128
|
+
{ label: 'Stops', value: current.stops.toLocaleString(), detail: 'Across the current route plan' },
|
|
129
|
+
{ label: 'Distance', value: `${current.distance.toLocaleString()} mi`, detail: 'Planned route distance' },
|
|
130
|
+
{ label: 'Active in 24h', value: current.active.toLocaleString(), detail: 'Based on persisted activity time' },
|
|
100
131
|
]
|
|
101
132
|
}
|
|
102
133
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
loadError.set('')
|
|
134
|
+
/** The couriers the dialog offers and the rows show; store configuration, read whole. */
|
|
135
|
+
async function loadCouriers(): Promise<void> {
|
|
106
136
|
try {
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
])
|
|
111
|
-
if (!Array.isArray(routeData) || !Array.isArray(courierData))
|
|
112
|
-
throw new TypeError('Delivery route resources were not returned in the expected shape.')
|
|
137
|
+
const courierData = await dashboardApi<CourierRecord[]>('/api/dashboard/commerce/couriers')
|
|
138
|
+
if (!Array.isArray(courierData))
|
|
139
|
+
throw new TypeError('Couriers were not returned in the expected shape.')
|
|
113
140
|
couriers.set(courierData)
|
|
114
|
-
records.set(routeData.map(withCourier))
|
|
115
141
|
}
|
|
116
142
|
catch (error) {
|
|
117
|
-
|
|
118
|
-
pushToast('error', 'Could not load delivery routes', { detail: loadError() })
|
|
119
|
-
}
|
|
120
|
-
finally {
|
|
121
|
-
loading.set(false)
|
|
143
|
+
pushToast('error', 'Could not load couriers', { detail: error instanceof Error ? error.message : String(error) })
|
|
122
144
|
}
|
|
123
145
|
}
|
|
124
146
|
|
|
147
|
+
function loadRoutes(): void {
|
|
148
|
+
void load()
|
|
149
|
+
void loadCouriers()
|
|
150
|
+
}
|
|
151
|
+
|
|
125
152
|
function setEditorError(message: string): void {
|
|
126
153
|
editorError.set(message)
|
|
127
154
|
}
|
|
@@ -141,10 +168,10 @@ async function saveRoute(payload: DeliveryRoutePayload): Promise<void> {
|
|
|
141
168
|
},
|
|
142
169
|
)
|
|
143
170
|
const hydrated = withCourier(updated)
|
|
144
|
-
upsert(hydrated, current)
|
|
145
171
|
editorOpen.set(false)
|
|
146
172
|
editing.set(null)
|
|
147
173
|
pushToast('success', current ? 'Delivery route updated' : 'Delivery route added', { detail: `Route #${hydrated.id}` })
|
|
174
|
+
await load()
|
|
148
175
|
}
|
|
149
176
|
catch (error) {
|
|
150
177
|
editorError.set(error instanceof Error ? error.message : String(error))
|
|
@@ -164,9 +191,9 @@ async function confirmDelete(): Promise<void> {
|
|
|
164
191
|
await dashboardApi(`/api/dashboard/commerce/delivery-routes/${current.id}`, {
|
|
165
192
|
method: 'DELETE',
|
|
166
193
|
})
|
|
167
|
-
remove(current)
|
|
168
194
|
deleting.set(null)
|
|
169
195
|
pushToast('success', 'Delivery route deleted', { detail: `Route #${current.id}` })
|
|
196
|
+
await load()
|
|
170
197
|
}
|
|
171
198
|
catch (error) {
|
|
172
199
|
deleteError.set(error instanceof Error ? error.message : String(error))
|
|
@@ -177,7 +204,7 @@ async function confirmDelete(): Promise<void> {
|
|
|
177
204
|
}
|
|
178
205
|
|
|
179
206
|
onMount(() => {
|
|
180
|
-
|
|
207
|
+
loadRoutes()
|
|
181
208
|
})
|
|
182
209
|
</script>
|
|
183
210
|
|
|
@@ -198,10 +225,10 @@ onMount(() => {
|
|
|
198
225
|
|
|
199
226
|
<section class="overflow-hidden bg-white dark:bg-neutral-800 border border-gray-200 rounded-xl dark:border-neutral-700">
|
|
200
227
|
<div class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between px-4 py-4 border-b border-gray-200 dark:border-neutral-700">
|
|
201
|
-
<div><h2 class="font-semibold text-gray-900 dark:text-white">Route plan</h2><p class="mt-0.5 text-gray-500 text-xs dark:text-neutral-400">{{
|
|
228
|
+
<div><h2 class="font-semibold text-gray-900 dark:text-white">Route plan</h2><p class="mt-0.5 text-gray-500 text-xs dark:text-neutral-400">{{ matchingLabel() }}</p></div>
|
|
202
229
|
<SearchFilter placeholder="Search delivery routes" class="w-full sm:w-80" @search="handleSearch" />
|
|
203
230
|
</div>
|
|
204
|
-
<DeliveryRoutesTable :routes="
|
|
231
|
+
<DeliveryRoutesTable :routes="rows()" :total="total()" :current-page="page()" :per-page="perPage()" :loading="loading()" @edit="openEdit" @delete="requestDelete" @page-change="changePage" @page-size-change="changePageSize" @sort="changeSort" />
|
|
205
232
|
</section>
|
|
206
233
|
</div>
|
|
207
234
|
|
|
@@ -15,9 +15,14 @@ interface DeliveryRouteRow {
|
|
|
15
15
|
|
|
16
16
|
const routes = useReactiveProp('routes', [] as DeliveryRouteRow[])
|
|
17
17
|
const loading = useReactiveProp('loading', false)
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
/**
|
|
19
|
+
* The server pages and sorts what the parent's search matches
|
|
20
|
+
* (stacksjs/stacks#3218): how many routes match, the page shown and its size.
|
|
21
|
+
*/
|
|
22
|
+
const total = useReactiveProp('total', 0)
|
|
23
|
+
const currentPage = useReactiveProp('currentPage', 1)
|
|
24
|
+
const perPage = useReactiveProp('perPage', 25)
|
|
25
|
+
const emit = defineEmits(['edit', 'delete', 'page-change', 'page-size-change', 'sort'])
|
|
21
26
|
|
|
22
27
|
function formatNumber(value: number): string {
|
|
23
28
|
return new Intl.NumberFormat('en-US', { maximumFractionDigits: 2 }).format(value)
|
|
@@ -52,25 +57,43 @@ const rows = derived(() => routes().map(route => ({
|
|
|
52
57
|
function handleRowAction(payload: { action: string, row: DeliveryRouteRow }): void {
|
|
53
58
|
emit(payload.action, payload.row)
|
|
54
59
|
}
|
|
60
|
+
|
|
61
|
+
function changePage(page: number): void {
|
|
62
|
+
emit('page-change', page)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function changePageSize(size: number): void {
|
|
66
|
+
emit('page-size-change', size)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function changeSort(sort: { key: string, direction: string }): void {
|
|
70
|
+
emit('sort', sort)
|
|
71
|
+
}
|
|
55
72
|
</script>
|
|
56
73
|
|
|
57
74
|
{{--
|
|
58
|
-
No `searchable` or `filterable`: the parent dashboard owns the search box
|
|
59
|
-
|
|
60
|
-
while
|
|
75
|
+
No `searchable` or `filterable`: the parent dashboard owns the search box,
|
|
76
|
+
and the server pages and sorts what it matches. The table stays mounted
|
|
77
|
+
while a page loads.
|
|
61
78
|
--}}
|
|
62
79
|
<Table
|
|
63
|
-
:page-reset-key="pageResetKey()"
|
|
64
80
|
:columns="COLUMNS"
|
|
65
81
|
:data="rows()"
|
|
66
82
|
:loading="loading()"
|
|
67
83
|
:row-actions="ROW_ACTIONS"
|
|
68
84
|
action-label-key="actionName"
|
|
69
85
|
paginated
|
|
70
|
-
|
|
86
|
+
manual-pagination
|
|
87
|
+
manual-sort
|
|
88
|
+
:total="total()"
|
|
89
|
+
:current-page="currentPage()"
|
|
90
|
+
:page-size="perPage()"
|
|
71
91
|
empty-title="No delivery routes found"
|
|
72
92
|
empty-description="Add a route, or adjust the search."
|
|
73
93
|
@row-action="handleRowAction"
|
|
94
|
+
@page-change="changePage"
|
|
95
|
+
@page-size-change="changePageSize"
|
|
96
|
+
@sort="changeSort"
|
|
74
97
|
>
|
|
75
98
|
<template #cell="{ row, column }">
|
|
76
99
|
<span :if="column.key === 'delivery_time'" class="tabular-nums whitespace-nowrap" x-text="row.timeLabel"></span>
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
<script client>
|
|
2
|
+
import { dashboardApi } from '../../../../../functions/dashboard-api'
|
|
3
|
+
|
|
2
4
|
type LicenseKeyStatus = 'active' | 'inactive' | 'unassigned'
|
|
3
5
|
|
|
4
6
|
interface LicenseKeyOption {
|
|
@@ -7,11 +9,7 @@ interface LicenseKeyOption {
|
|
|
7
9
|
detail?: string
|
|
8
10
|
}
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
customers: LicenseKeyOption[]
|
|
12
|
-
products: LicenseKeyOption[]
|
|
13
|
-
orders: LicenseKeyOption[]
|
|
14
|
-
}
|
|
12
|
+
type ChoiceKind = 'customers' | 'products' | 'orders'
|
|
15
13
|
|
|
16
14
|
interface LicenseKeyRecord {
|
|
17
15
|
id: number
|
|
@@ -22,16 +20,14 @@ interface LicenseKeyRecord {
|
|
|
22
20
|
order_id?: number | null
|
|
23
21
|
expiry_date: string
|
|
24
22
|
status: LicenseKeyStatus
|
|
23
|
+
customer?: LicenseKeyOption | null
|
|
24
|
+
product?: LicenseKeyOption | null
|
|
25
|
+
order?: LicenseKeyOption | null
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
const open = useReactiveProp('open', false)
|
|
28
29
|
const mode = useReactiveProp('mode', 'create')
|
|
29
30
|
const record = useReactiveProp('record', null as LicenseKeyRecord | null)
|
|
30
|
-
const options = useReactiveProp('options', {
|
|
31
|
-
customers: [],
|
|
32
|
-
products: [],
|
|
33
|
-
orders: [],
|
|
34
|
-
} as LicenseKeyOptions)
|
|
35
31
|
const busy = useReactiveProp('busy', false)
|
|
36
32
|
const error = useReactiveProp('error', '')
|
|
37
33
|
const emit = defineEmits(['invalid', 'submit', 'close'])
|
|
@@ -44,6 +40,62 @@ const expiryDate = state('')
|
|
|
44
40
|
const status = state<LicenseKeyStatus>('unassigned')
|
|
45
41
|
let hydrationKey = ''
|
|
46
42
|
|
|
43
|
+
// The customer, product and order choices are server searches
|
|
44
|
+
// (stacksjs/stacks#3218): this used to be handed the first 500 of each, so a
|
|
45
|
+
// key could not be linked to any later one.
|
|
46
|
+
const choices = state<Record<ChoiceKind, LicenseKeyOption[]>>({ customers: [], products: [], orders: [] })
|
|
47
|
+
const matches = state<Record<ChoiceKind, number>>({ customers: 0, products: 0, orders: 0 })
|
|
48
|
+
const customerQuery = state('')
|
|
49
|
+
const productQuery = state('')
|
|
50
|
+
const orderQuery = state('')
|
|
51
|
+
const requests: Record<ChoiceKind, number> = { customers: 0, products: 0, orders: 0 }
|
|
52
|
+
const timers: Record<ChoiceKind, ReturnType<typeof setTimeout> | null> = { customers: null, products: null, orders: null }
|
|
53
|
+
|
|
54
|
+
async function loadChoices(kind: ChoiceKind, term: string): Promise<void> {
|
|
55
|
+
const request = ++requests[kind]
|
|
56
|
+
const params = new URLSearchParams({ kind })
|
|
57
|
+
if (term)
|
|
58
|
+
params.set('q', term)
|
|
59
|
+
let found: LicenseKeyOption[] = []
|
|
60
|
+
let count = 0
|
|
61
|
+
try {
|
|
62
|
+
const data = await dashboardApi<{ choices?: LicenseKeyOption[], total?: number }>(`/api/dashboard/commerce/license-key-options?${params}`)
|
|
63
|
+
found = Array.isArray(data.choices) ? data.choices : []
|
|
64
|
+
count = Number(data.total) || found.length
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
// Soft-fail: the key's own links stay selectable.
|
|
68
|
+
}
|
|
69
|
+
if (request !== requests[kind])
|
|
70
|
+
return
|
|
71
|
+
choices.set({ ...choices(), [kind]: found })
|
|
72
|
+
matches.set({ ...matches(), [kind]: count })
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function searchSoon(kind: ChoiceKind): void {
|
|
76
|
+
const timer = timers[kind]
|
|
77
|
+
if (timer)
|
|
78
|
+
clearTimeout(timer)
|
|
79
|
+
const query = kind === 'customers' ? customerQuery : kind === 'products' ? productQuery : orderQuery
|
|
80
|
+
timers[kind] = setTimeout(() => { void loadChoices(kind, query().trim()) }, 250)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The choices to show for one link: the search results, with the key's own kept in. */
|
|
84
|
+
function optionsFor(kind: ChoiceKind): LicenseKeyOption[] {
|
|
85
|
+
const found = choices()[kind]
|
|
86
|
+
const current = record()
|
|
87
|
+
const own = kind === 'customers' ? current?.customer : kind === 'products' ? current?.product : current?.order
|
|
88
|
+
if (!own || found.some(option => option.id === own.id))
|
|
89
|
+
return found
|
|
90
|
+
return [own, ...found]
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function moreLabel(kind: ChoiceKind, noun: string): string {
|
|
94
|
+
const shown = choices()[kind].length
|
|
95
|
+
const total = matches()[kind]
|
|
96
|
+
return total > shown ? `Showing ${shown} of ${total.toLocaleString()} matching ${noun}. Search to narrow it down.` : ''
|
|
97
|
+
}
|
|
98
|
+
|
|
47
99
|
function toDateTimeLocal(value?: string): string {
|
|
48
100
|
if (!value)
|
|
49
101
|
return ''
|
|
@@ -83,6 +135,12 @@ effect(() => {
|
|
|
83
135
|
orderId.set(current?.order_id ? String(current.order_id) : '')
|
|
84
136
|
expiryDate.set(toDateTimeLocal(current?.expiry_date) || defaultExpiry())
|
|
85
137
|
status.set(current?.status || 'unassigned')
|
|
138
|
+
customerQuery.set('')
|
|
139
|
+
productQuery.set('')
|
|
140
|
+
orderQuery.set('')
|
|
141
|
+
void loadChoices('customers', '')
|
|
142
|
+
void loadChoices('products', '')
|
|
143
|
+
void loadChoices('orders', '')
|
|
86
144
|
})
|
|
87
145
|
|
|
88
146
|
function relationId(value: string): number | null {
|
|
@@ -141,11 +199,11 @@ function submit(): void {
|
|
|
141
199
|
</div>
|
|
142
200
|
<label class="block"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Template</span><select x-model="templateValue" class="mt-1 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700"><option value="Standard License">Standard License</option><option value="Premium License">Premium License</option><option value="Enterprise License">Enterprise License</option></select></label>
|
|
143
201
|
<div class="grid gap-4 grid-cols-1 sm:grid-cols-2">
|
|
144
|
-
<label class="block"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Customer</span><select x-model="customerId" class="mt-
|
|
145
|
-
<label class="block"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Product</span><select x-model="productId" class="mt-
|
|
202
|
+
<div><label class="block"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Customer</span><input x-model="customerQuery" @input="searchSoon('customers')" type="search" name="customer_search" aria-label="Search customers by name or email" placeholder="Search by name or email" class="mt-1 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700" /></label><select x-model="customerId" aria-label="Customer" class="mt-2 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700"><option value="">Unassigned</option><template :for="option in optionsFor('customers')" :key="option.id"><option :value="option.id" :selected="String(option.id) === customerId()">{{ option.label }}{{ option.detail ? ' - ' + option.detail : '' }}</option></template></select><p :if="moreLabel('customers', 'customers')" class="mt-1 text-gray-500 text-xs dark:text-neutral-400" :text="moreLabel('customers', 'customers')"></p></div>
|
|
203
|
+
<div><label class="block"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Product</span><input x-model="productQuery" @input="searchSoon('products')" type="search" name="product_search" aria-label="Search products by name or id" placeholder="Search by name or id" class="mt-1 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700" /></label><select x-model="productId" aria-label="Product" class="mt-2 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700"><option value="">Unassigned</option><template :for="option in optionsFor('products')" :key="option.id"><option :value="option.id" :selected="String(option.id) === productId()">{{ option.label }}</option></template></select><p :if="moreLabel('products', 'products')" class="mt-1 text-gray-500 text-xs dark:text-neutral-400" :text="moreLabel('products', 'products')"></p></div>
|
|
146
204
|
</div>
|
|
147
205
|
<div class="grid gap-4 grid-cols-1 sm:grid-cols-2">
|
|
148
|
-
<label class="block"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Order</span><select x-model="orderId" class="mt-
|
|
206
|
+
<div><label class="block"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Order</span><input x-model="orderQuery" @input="searchSoon('orders')" type="search" name="order_search" aria-label="Search orders by number or status" placeholder="Search by number or status" class="mt-1 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700" /></label><select x-model="orderId" aria-label="Order" class="mt-2 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700"><option value="">Unassigned</option><template :for="option in optionsFor('orders')" :key="option.id"><option :value="option.id" :selected="String(option.id) === orderId()">{{ option.label }}{{ option.detail ? ' - ' + option.detail : '' }}</option></template></select><p :if="moreLabel('orders', 'orders')" class="mt-1 text-gray-500 text-xs dark:text-neutral-400" :text="moreLabel('orders', 'orders')"></p></div>
|
|
149
207
|
<label class="block"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Expiry date</span><input x-model="expiryDate" type="datetime-local" required class="mt-1 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700" /></label>
|
|
150
208
|
</div>
|
|
151
209
|
<label class="block"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Status</span><select x-model="status" class="mt-1 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700"><option value="unassigned">Unassigned</option><option value="active">Active</option><option value="inactive">Inactive</option></select></label>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script client>
|
|
2
2
|
import { dashboardApi } from '../../../../../functions/dashboard-api'
|
|
3
|
-
import { useRecordsDashboard } from '../../../../../functions/dashboard-list'
|
|
3
|
+
import { useRecordsDashboard, useServerList } from '../../../../../functions/dashboard-list'
|
|
4
4
|
import { pushToast } from '../../../../../functions/toasts'
|
|
5
5
|
|
|
6
6
|
type LicenseKeyStatus = 'active' | 'inactive' | 'unassigned'
|
|
@@ -11,12 +11,6 @@ interface RelatedSummary {
|
|
|
11
11
|
detail?: string
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
interface LicenseKeyOptions {
|
|
15
|
-
customers: RelatedSummary[]
|
|
16
|
-
products: RelatedSummary[]
|
|
17
|
-
orders: RelatedSummary[]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
14
|
interface LicenseKeyRecord {
|
|
21
15
|
id: number
|
|
22
16
|
key: string
|
|
@@ -42,24 +36,27 @@ interface LicenseKeyPayload {
|
|
|
42
36
|
status: LicenseKeyStatus
|
|
43
37
|
}
|
|
44
38
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
39
|
+
interface LicenseKeySummary {
|
|
40
|
+
total: number
|
|
41
|
+
active: number
|
|
42
|
+
assigned: number
|
|
43
|
+
expiring: number
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface LicenseKeyPage {
|
|
47
|
+
records: LicenseKeyRecord[]
|
|
48
|
+
total: number
|
|
49
|
+
page: number
|
|
50
|
+
summary?: LicenseKeySummary
|
|
56
51
|
}
|
|
57
52
|
|
|
53
|
+
const emptySummary: LicenseKeySummary = { total: 0, active: 0, assigned: 0, expiring: 0 }
|
|
54
|
+
|
|
55
|
+
// The dialog and the delete confirmation. The list itself is the server's
|
|
56
|
+
// (stacksjs/stacks#3218), and so is each key's customer, product and order:
|
|
57
|
+
// this page used to read the newest 500 keys and label their links from the
|
|
58
|
+
// first 500 customers, products and orders.
|
|
58
59
|
const {
|
|
59
|
-
records,
|
|
60
|
-
loading,
|
|
61
|
-
loadError,
|
|
62
|
-
search,
|
|
63
60
|
editorOpen,
|
|
64
61
|
editorMode,
|
|
65
62
|
editing,
|
|
@@ -68,75 +65,67 @@ const {
|
|
|
68
65
|
deleting,
|
|
69
66
|
deleteBusy,
|
|
70
67
|
deleteError,
|
|
71
|
-
filteredRecords,
|
|
72
|
-
handleSearch,
|
|
73
68
|
openCreate,
|
|
74
69
|
openEdit,
|
|
75
70
|
closeEditor,
|
|
76
71
|
requestDelete,
|
|
77
72
|
closeDelete,
|
|
78
|
-
|
|
79
|
-
remove,
|
|
80
|
-
} = useRecordsDashboard<LicenseKeyRecord>({ filter: matchesQuery })
|
|
73
|
+
} = useRecordsDashboard<LicenseKeyRecord>({ filter: records => records })
|
|
81
74
|
|
|
82
|
-
const
|
|
75
|
+
const summary = state<LicenseKeySummary>({ ...emptySummary })
|
|
83
76
|
|
|
84
|
-
|
|
85
|
-
|
|
77
|
+
const {
|
|
78
|
+
records,
|
|
79
|
+
total,
|
|
80
|
+
page,
|
|
81
|
+
perPage,
|
|
82
|
+
search,
|
|
83
|
+
loading,
|
|
84
|
+
loadError,
|
|
85
|
+
load,
|
|
86
|
+
changePage,
|
|
87
|
+
changePageSize,
|
|
88
|
+
changeSort,
|
|
89
|
+
} = useServerList<LicenseKeyRecord>({
|
|
90
|
+
fetch: params => dashboardApi<LicenseKeyPage>(`/api/dashboard/commerce/license-keys?${params}`),
|
|
91
|
+
defaultSort: { sort: 'created', direction: 'desc' },
|
|
92
|
+
columnSorts: {
|
|
93
|
+
key: 'key',
|
|
94
|
+
template: 'template',
|
|
95
|
+
customerLabel: 'customer',
|
|
96
|
+
productLabel: 'product',
|
|
97
|
+
orderLabel: 'order',
|
|
98
|
+
created_at: 'created',
|
|
99
|
+
expiry_date: 'expiry',
|
|
100
|
+
status: 'status',
|
|
101
|
+
},
|
|
102
|
+
onLoad: result => summary.set((result as LicenseKeyPage).summary ?? { ...emptySummary }),
|
|
103
|
+
onError: error => pushToast('error', 'Could not load license keys', { detail: error instanceof Error ? error.message : String(error) }),
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
function loadKeys(): void {
|
|
107
|
+
void load()
|
|
86
108
|
}
|
|
87
109
|
|
|
88
|
-
function
|
|
89
|
-
|
|
90
|
-
return {
|
|
91
|
-
...record,
|
|
92
|
-
customer: optionFor(currentOptions.customers, record.customer_id),
|
|
93
|
-
product: optionFor(currentOptions.products, record.product_id),
|
|
94
|
-
order: optionFor(currentOptions.orders, record.order_id),
|
|
95
|
-
}
|
|
110
|
+
function handleSearch(value: string): void {
|
|
111
|
+
search.set(value)
|
|
96
112
|
}
|
|
97
113
|
|
|
98
|
-
function
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return new Date(value.replace(' ', 'T')).getTime()
|
|
114
|
+
function matchingLabel(): string {
|
|
115
|
+
const count = total()
|
|
116
|
+
return `${count.toLocaleString()} matching ${count === 1 ? 'record' : 'records'}`
|
|
102
117
|
}
|
|
103
118
|
|
|
104
119
|
function metricCards(): Array<{ label: string, value: string, detail: string }> {
|
|
105
|
-
const
|
|
106
|
-
const expiring = records().filter((record) => {
|
|
107
|
-
const expiry = dateTime(record.expiry_date)
|
|
108
|
-
return expiry >= Date.now() && expiry <= expiryCutoff
|
|
109
|
-
}).length
|
|
120
|
+
const current = summary()
|
|
110
121
|
return [
|
|
111
|
-
{ label: 'License keys', value:
|
|
112
|
-
{ label: 'Active', value:
|
|
113
|
-
{ label: 'Assigned', value:
|
|
114
|
-
{ label: 'Expiring in 30d', value: expiring.toLocaleString(), detail: 'Future expiry within 30 days' },
|
|
122
|
+
{ label: 'License keys', value: current.total.toLocaleString(), detail: 'Unique persisted keys' },
|
|
123
|
+
{ label: 'Active', value: current.active.toLocaleString(), detail: 'Currently enabled' },
|
|
124
|
+
{ label: 'Assigned', value: current.assigned.toLocaleString(), detail: 'Linked to commerce records' },
|
|
125
|
+
{ label: 'Expiring in 30d', value: current.expiring.toLocaleString(), detail: 'Future expiry within 30 days' },
|
|
115
126
|
]
|
|
116
127
|
}
|
|
117
128
|
|
|
118
|
-
async function loadKeys(): Promise<void> {
|
|
119
|
-
loading.set(true)
|
|
120
|
-
loadError.set('')
|
|
121
|
-
try {
|
|
122
|
-
const [keyData, optionData] = await Promise.all([
|
|
123
|
-
dashboardApi<LicenseKeyRecord[]>('/api/dashboard/commerce/license-keys'),
|
|
124
|
-
dashboardApi<LicenseKeyOptions>('/api/dashboard/commerce/license-key-options'),
|
|
125
|
-
])
|
|
126
|
-
if (!Array.isArray(keyData) || !Array.isArray(optionData?.customers) || !Array.isArray(optionData?.products) || !Array.isArray(optionData?.orders))
|
|
127
|
-
throw new TypeError('License key resources were not returned in the expected shape.')
|
|
128
|
-
options.set(optionData)
|
|
129
|
-
records.set(keyData.map(withRelationships))
|
|
130
|
-
}
|
|
131
|
-
catch (error) {
|
|
132
|
-
loadError.set(error instanceof Error ? error.message : String(error))
|
|
133
|
-
pushToast('error', 'Could not load license keys', { detail: loadError() })
|
|
134
|
-
}
|
|
135
|
-
finally {
|
|
136
|
-
loading.set(false)
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
129
|
function setEditorError(message: string): void {
|
|
141
130
|
editorError.set(message)
|
|
142
131
|
}
|
|
@@ -155,11 +144,10 @@ async function saveKey(payload: LicenseKeyPayload): Promise<void> {
|
|
|
155
144
|
body: payload,
|
|
156
145
|
},
|
|
157
146
|
)
|
|
158
|
-
const hydrated = withRelationships(updated)
|
|
159
|
-
upsert(hydrated, current)
|
|
160
147
|
editorOpen.set(false)
|
|
161
148
|
editing.set(null)
|
|
162
|
-
pushToast('success', current ? 'License key updated' : 'License key added', { detail:
|
|
149
|
+
pushToast('success', current ? 'License key updated' : 'License key added', { detail: updated.key })
|
|
150
|
+
await load()
|
|
163
151
|
}
|
|
164
152
|
catch (error) {
|
|
165
153
|
editorError.set(error instanceof Error ? error.message : String(error))
|
|
@@ -179,9 +167,9 @@ async function confirmDelete(): Promise<void> {
|
|
|
179
167
|
await dashboardApi(`/api/dashboard/commerce/license-keys/${current.id}`, {
|
|
180
168
|
method: 'DELETE',
|
|
181
169
|
})
|
|
182
|
-
remove(current)
|
|
183
170
|
deleting.set(null)
|
|
184
171
|
pushToast('success', 'License key deleted', { detail: current.key })
|
|
172
|
+
await load()
|
|
185
173
|
}
|
|
186
174
|
catch (error) {
|
|
187
175
|
deleteError.set(error instanceof Error ? error.message : String(error))
|
|
@@ -192,7 +180,7 @@ async function confirmDelete(): Promise<void> {
|
|
|
192
180
|
}
|
|
193
181
|
|
|
194
182
|
onMount(() => {
|
|
195
|
-
|
|
183
|
+
loadKeys()
|
|
196
184
|
})
|
|
197
185
|
</script>
|
|
198
186
|
|
|
@@ -212,12 +200,12 @@ onMount(() => {
|
|
|
212
200
|
|
|
213
201
|
<section class="overflow-hidden bg-white dark:bg-neutral-800 border border-gray-200 rounded-xl dark:border-neutral-700">
|
|
214
202
|
<div class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between px-4 py-4 border-b border-gray-200 dark:border-neutral-700">
|
|
215
|
-
<div><h2 class="font-semibold text-gray-900 dark:text-white">Key inventory</h2><p class="mt-0.5 text-gray-500 text-xs dark:text-neutral-400">{{
|
|
203
|
+
<div><h2 class="font-semibold text-gray-900 dark:text-white">Key inventory</h2><p class="mt-0.5 text-gray-500 text-xs dark:text-neutral-400">{{ matchingLabel() }}</p></div>
|
|
216
204
|
<SearchFilter placeholder="Search license keys" class="w-full sm:w-80" @search="handleSearch" />
|
|
217
205
|
</div>
|
|
218
|
-
<LicenseKeysTable :license-keys="
|
|
206
|
+
<LicenseKeysTable :license-keys="records()" :total="total()" :current-page="page()" :per-page="perPage()" :loading="loading()" @edit="openEdit" @delete="requestDelete" @page-change="changePage" @page-size-change="changePageSize" @sort="changeSort" />
|
|
219
207
|
</section>
|
|
220
208
|
</div>
|
|
221
209
|
|
|
222
|
-
<LicenseKeyDialog :open="editorOpen()" :mode="editorMode()" :record="editing()" :
|
|
210
|
+
<LicenseKeyDialog :open="editorOpen()" :mode="editorMode()" :record="editing()" :busy="saving()" :error="editorError()" @submit="saveKey" @invalid="setEditorError" @close="closeEditor()" />
|
|
223
211
|
<LicenseKeyDeleteDialog :open="Boolean(deleting())" :record="deleting()" :busy="deleteBusy()" :error="deleteError()" @confirm="confirmDelete()" @close="closeDelete()" />
|