@develemit/commerce-admin 0.0.0-stage → 0.3.0
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/README.md +136 -2
- package/dist/client/admin-client.d.ts +31 -0
- package/dist/client/errors.d.ts +41 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.js +1 -0
- package/dist/client/map-error.d.ts +2 -0
- package/dist/client/transport.d.ts +19 -0
- package/dist/client-n_IYb4iK.js +146 -0
- package/dist/client-n_IYb4iK.js.map +1 -0
- package/dist/components/admin-layout/admin-layout.d.ts +13 -0
- package/dist/components/admin-table/admin-table.d.ts +13 -0
- package/dist/components/confirm-dialog/confirm-dialog.d.ts +12 -0
- package/dist/components/error-message/error-message.d.ts +5 -0
- package/dist/components/money/money.d.ts +5 -0
- package/dist/components/notice/notice.d.ts +9 -0
- package/dist/components/status-badge/status-badge.d.ts +3 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +2346 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/image-labels.d.ts +24 -0
- package/dist/lib/image-rules.d.ts +4 -0
- package/dist/lib/money-input.d.ts +2 -0
- package/dist/lib/order-action-labels.d.ts +28 -0
- package/dist/lib/order-labels.d.ts +66 -0
- package/dist/lib/product-filter.d.ts +6 -0
- package/dist/lib/product-form.d.ts +29 -0
- package/dist/lib/product-labels.d.ts +52 -0
- package/dist/lib/provider.d.ts +73 -0
- package/dist/lib/refund-rules.d.ts +7 -0
- package/dist/lib/shipping-labels.d.ts +33 -0
- package/dist/lib/shipping-rates.d.ts +31 -0
- package/dist/lib/use-admin-mutation.d.ts +7 -0
- package/dist/lib/use-admin-query.d.ts +7 -0
- package/dist/lib/use-debounced.d.ts +1 -0
- package/dist/lib/use-image-upload.d.ts +18 -0
- package/dist/lib/use-order-pages.d.ts +17 -0
- package/dist/lib/use-product-pages.d.ts +30 -0
- package/dist/styles.css +405 -0
- package/dist/views/orders/admin-order-detail.d.ts +10 -0
- package/dist/views/orders/admin-order-list.d.ts +1 -0
- package/dist/views/orders/order-actions.d.ts +7 -0
- package/dist/views/orders/order-fulfillment.d.ts +4 -0
- package/dist/views/orders/order-items.d.ts +4 -0
- package/dist/views/orders/order-refunds.d.ts +4 -0
- package/dist/views/orders/refund-dialog.d.ts +8 -0
- package/dist/views/orders/resolve-button.d.ts +7 -0
- package/dist/views/orders/ship-form.d.ts +7 -0
- package/dist/views/orders/test-helpers.d.ts +3 -0
- package/dist/views/products/admin-product-editor.d.ts +9 -0
- package/dist/views/products/admin-product-images.d.ts +6 -0
- package/dist/views/products/admin-product-list.d.ts +1 -0
- package/dist/views/products/image-tile.d.ts +14 -0
- package/dist/views/products/product-fields.d.ts +12 -0
- package/dist/views/products/test-helpers.d.ts +6 -0
- package/dist/views/products/upload-picker.d.ts +7 -0
- package/dist/views/shipping/admin-shipping-rates.d.ts +4 -0
- package/dist/views/shipping/shipping-rate-row.d.ts +15 -0
- package/package.json +44 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,2346 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { a as e, c as t, d as n, f as r, i, l as a, o, r as s, s as c, u as l } from "./client-n_IYb4iK.js";
|
|
3
|
+
import { createContext as u, useCallback as d, useContext as f, useEffect as p, useRef as m, useState as h } from "react";
|
|
4
|
+
import { Fragment as g, jsx as _, jsxs as v } from "react/jsx-runtime";
|
|
5
|
+
import { adminProductInputSchema as y, shippingRatesInputSchema as b } from "@develemit/commerce-contracts";
|
|
6
|
+
// src/lib/order-labels.ts
|
|
7
|
+
var x = {
|
|
8
|
+
title: "Orders",
|
|
9
|
+
searchLabel: "Search orders",
|
|
10
|
+
searchPlaceholder: "Search by email or order id",
|
|
11
|
+
tabs: {
|
|
12
|
+
paid: "To ship",
|
|
13
|
+
shipped: "Shipped",
|
|
14
|
+
needs_attention: "Needs attention",
|
|
15
|
+
pending_refund: "Pending refund",
|
|
16
|
+
all: "All"
|
|
17
|
+
},
|
|
18
|
+
empty: {
|
|
19
|
+
paid: "Nothing waiting to ship.",
|
|
20
|
+
shipped: "No shipped orders yet.",
|
|
21
|
+
needs_attention: "No orders need attention.",
|
|
22
|
+
pending_refund: "No refunds are pending.",
|
|
23
|
+
all: "No orders yet."
|
|
24
|
+
},
|
|
25
|
+
noMatches: "No orders match that search.",
|
|
26
|
+
loadMore: "Load more",
|
|
27
|
+
columns: {
|
|
28
|
+
order: "Order",
|
|
29
|
+
status: "Status",
|
|
30
|
+
email: "Buyer",
|
|
31
|
+
items: "Items",
|
|
32
|
+
total: "Total",
|
|
33
|
+
date: "Placed"
|
|
34
|
+
},
|
|
35
|
+
noEmail: "No email",
|
|
36
|
+
detailTitle: "Order",
|
|
37
|
+
back: "Back to orders",
|
|
38
|
+
placed: "Placed",
|
|
39
|
+
buyer: "Buyer",
|
|
40
|
+
itemsHeading: "Items",
|
|
41
|
+
itemColumns: {
|
|
42
|
+
name: "Item",
|
|
43
|
+
price: "Price",
|
|
44
|
+
quantity: "Qty",
|
|
45
|
+
line: "Subtotal"
|
|
46
|
+
},
|
|
47
|
+
subtotal: "Subtotal",
|
|
48
|
+
shipping: "Shipping",
|
|
49
|
+
total: "Total",
|
|
50
|
+
shippingAddress: "Shipping address",
|
|
51
|
+
noAddress: "No shipping address.",
|
|
52
|
+
fulfillment: "Fulfillment",
|
|
53
|
+
notShipped: "Not shipped",
|
|
54
|
+
shippedOn: "Shipped",
|
|
55
|
+
carrier: "Carrier",
|
|
56
|
+
tracking: "Tracking",
|
|
57
|
+
trackShipment: "Track shipment",
|
|
58
|
+
refunds: "Refunds",
|
|
59
|
+
noRefunds: "No refunds.",
|
|
60
|
+
refundColumns: {
|
|
61
|
+
amount: "Amount",
|
|
62
|
+
reason: "Reason",
|
|
63
|
+
source: "Source",
|
|
64
|
+
status: "Status",
|
|
65
|
+
restocked: "Restocked",
|
|
66
|
+
date: "Date"
|
|
67
|
+
},
|
|
68
|
+
refundSources: {
|
|
69
|
+
admin: "Admin",
|
|
70
|
+
gateway: "Payment provider"
|
|
71
|
+
},
|
|
72
|
+
refundStatuses: {
|
|
73
|
+
pending: "Pending",
|
|
74
|
+
succeeded: "Refunded"
|
|
75
|
+
},
|
|
76
|
+
yes: "Yes",
|
|
77
|
+
no: "No",
|
|
78
|
+
refunded: "Refunded",
|
|
79
|
+
remaining: "Remaining balance",
|
|
80
|
+
actions: {
|
|
81
|
+
ship: "Mark as shipped",
|
|
82
|
+
reship: "Update tracking",
|
|
83
|
+
shipHeading: "Shipping",
|
|
84
|
+
carrier: "Carrier",
|
|
85
|
+
trackingNumber: "Tracking number",
|
|
86
|
+
trackingUrl: "Tracking URL",
|
|
87
|
+
trackingUrlInvalid: "Enter a full link starting with http:// or https://.",
|
|
88
|
+
shipped: "Shipping details saved.",
|
|
89
|
+
refund: "Refund…",
|
|
90
|
+
refundTitle: "Refund order",
|
|
91
|
+
refundAmount: "Amount",
|
|
92
|
+
refundAmountInvalid: "Enter an amount above zero and no more than the balance.",
|
|
93
|
+
refundReason: "Reason",
|
|
94
|
+
refundSubmit: "Refund",
|
|
95
|
+
refundRetry: "Retry refund",
|
|
96
|
+
restock: "Restock items",
|
|
97
|
+
restockWarning: "Only restock if the item came back.",
|
|
98
|
+
refundPending: "A refund is already pending on this order. Wait for it to finish or refresh before refunding again.",
|
|
99
|
+
refundUnknown: "We could not confirm whether this refund went through; it may have succeeded. Retrying is safe, it will not refund twice.",
|
|
100
|
+
refundGateway: "The payment provider rejected the refund. Retrying is safe, it will not refund twice.",
|
|
101
|
+
refundDone: "Refund sent.",
|
|
102
|
+
resolve: "Resolve order",
|
|
103
|
+
resolveHelp: "This order was paid but its stock ran out. Restock the items and resolve it, or refund it.",
|
|
104
|
+
resolved: "Order resolved.",
|
|
105
|
+
restockThenResolve: "Restock, then resolve"
|
|
106
|
+
}
|
|
107
|
+
}, S = {
|
|
108
|
+
title: "Shipping rates",
|
|
109
|
+
loading: "Loading shipping rates…",
|
|
110
|
+
empty: "No shipping rates yet. Add one so customers can check out.",
|
|
111
|
+
add: "Add a rate",
|
|
112
|
+
save: "Save changes",
|
|
113
|
+
saved: "Shipping rates saved.",
|
|
114
|
+
label: "Name",
|
|
115
|
+
amount: "Price",
|
|
116
|
+
currency: "Currency",
|
|
117
|
+
mixedCurrency: "These rates use more than one currency. Checkout needs them to match your shop currency ({currency}).",
|
|
118
|
+
minDays: "Fastest (days)",
|
|
119
|
+
maxDays: "Slowest (days)",
|
|
120
|
+
active: "Offered at checkout",
|
|
121
|
+
rowName: "Rate {n}",
|
|
122
|
+
moveEarlier: "Move earlier",
|
|
123
|
+
moveLater: "Move later",
|
|
124
|
+
remove: "Remove",
|
|
125
|
+
removeTitle: "Remove this rate?",
|
|
126
|
+
removeBody: "It disappears from checkout once you save. Past orders are not affected.",
|
|
127
|
+
newRateLabel: "New rate",
|
|
128
|
+
removalWarning: "Saving replaces all rates. Rates you removed will no longer appear at checkout.",
|
|
129
|
+
unsaved: "You have unsaved changes.",
|
|
130
|
+
noActive: "Keep at least one rate offered at checkout, or customers cannot pay.",
|
|
131
|
+
labelRequired: "Give this rate a name.",
|
|
132
|
+
labelDuplicate: "Another rate already has this name.",
|
|
133
|
+
amountInvalid: "Enter a price like 5.00.",
|
|
134
|
+
currencyInvalid: "Use a 3-letter currency code like USD.",
|
|
135
|
+
daysInvalid: "Use a whole number of days, or leave blank.",
|
|
136
|
+
daysOrder: "Fastest cannot be more than slowest.",
|
|
137
|
+
rowInvalid: "These details are not valid."
|
|
138
|
+
}, C = {
|
|
139
|
+
title: "Products",
|
|
140
|
+
newProduct: "New product",
|
|
141
|
+
searchLabel: "Search products",
|
|
142
|
+
searchPlaceholder: "Search by name",
|
|
143
|
+
filters: {
|
|
144
|
+
all: "All",
|
|
145
|
+
live: "Live",
|
|
146
|
+
sold: "Sold",
|
|
147
|
+
draft: "Drafts",
|
|
148
|
+
archived: "Archived"
|
|
149
|
+
},
|
|
150
|
+
empty: {
|
|
151
|
+
all: "No products yet. Add your first piece.",
|
|
152
|
+
live: "Nothing is live in the shop right now.",
|
|
153
|
+
sold: "Nothing has sold out yet.",
|
|
154
|
+
draft: "No drafts.",
|
|
155
|
+
archived: "No archived products."
|
|
156
|
+
},
|
|
157
|
+
noMatches: "No products match that search.",
|
|
158
|
+
loadMore: "Load more",
|
|
159
|
+
columns: {
|
|
160
|
+
image: "Image",
|
|
161
|
+
name: "Name",
|
|
162
|
+
price: "Price",
|
|
163
|
+
status: "Status",
|
|
164
|
+
quantity: "In stock",
|
|
165
|
+
actions: "Actions"
|
|
166
|
+
},
|
|
167
|
+
noImage: "No image",
|
|
168
|
+
viewInShop: "View in shop",
|
|
169
|
+
markSold: "Mark sold",
|
|
170
|
+
archive: "Archive",
|
|
171
|
+
markSoldTitle: "Mark as sold?",
|
|
172
|
+
markSoldBody: "This sets the stock to zero. Customers will see it as sold.",
|
|
173
|
+
archiveTitle: "Archive this product?",
|
|
174
|
+
archiveBody: "It will disappear from the shop. You can restore it later.",
|
|
175
|
+
updated: "Product updated.",
|
|
176
|
+
createTitle: "New product",
|
|
177
|
+
editTitle: "Edit product",
|
|
178
|
+
saved: "Saved.",
|
|
179
|
+
fields: {
|
|
180
|
+
name: "Name",
|
|
181
|
+
category: "Category",
|
|
182
|
+
description: "Description",
|
|
183
|
+
materials: "Materials",
|
|
184
|
+
dimensions: "Dimensions",
|
|
185
|
+
price: "Price",
|
|
186
|
+
quantity: "Quantity",
|
|
187
|
+
status: "Status",
|
|
188
|
+
featured: "Feature this product on the home page"
|
|
189
|
+
},
|
|
190
|
+
images: {
|
|
191
|
+
title: "Photos",
|
|
192
|
+
empty: "Add a photo so this can go live.",
|
|
193
|
+
add: "Add photos",
|
|
194
|
+
takePhoto: "Take photo",
|
|
195
|
+
dropHint: "Drop photos here, or use the buttons.",
|
|
196
|
+
altLabel: "Photo description",
|
|
197
|
+
altHelp: "Describe what the photo shows, for people who cannot see it.",
|
|
198
|
+
altWarning: "No description yet. Add one so everyone can enjoy this photo.",
|
|
199
|
+
cover: "Cover",
|
|
200
|
+
photoName: "Photo {n}",
|
|
201
|
+
moveEarlier: "Move earlier",
|
|
202
|
+
moveLater: "Move later",
|
|
203
|
+
remove: "Remove",
|
|
204
|
+
removeTitle: "Remove this photo?",
|
|
205
|
+
removeBody: "It will be deleted from this product.",
|
|
206
|
+
uploading: "Uploading…",
|
|
207
|
+
working: "Working…",
|
|
208
|
+
tooLarge: "{name} is larger than 8 MB.",
|
|
209
|
+
wrongType: "{name} must be a JPEG, PNG, WebP or HEIC image.",
|
|
210
|
+
reorderFailed: "The photos could not be reordered. The old order is back.",
|
|
211
|
+
dismiss: "Dismiss"
|
|
212
|
+
},
|
|
213
|
+
statusHelp: "Draft is hidden. Active is live in the shop. Archived is hidden and kept. Mark a piece sold from the product list.",
|
|
214
|
+
priceHelp: "In dollars, for example 48.00.",
|
|
215
|
+
validation: {
|
|
216
|
+
required: "This field is required.",
|
|
217
|
+
price: "Enter a price like 48 or 48.50.",
|
|
218
|
+
quantity: "Enter a whole number, zero or more."
|
|
219
|
+
}
|
|
220
|
+
}, w = {
|
|
221
|
+
renderLink: ({ href: e, children: t, className: n }) => /* @__PURE__ */ _("a", {
|
|
222
|
+
href: e,
|
|
223
|
+
className: n,
|
|
224
|
+
children: t
|
|
225
|
+
}),
|
|
226
|
+
renderImage: ({ src: e, alt: t, sizes: n, className: r, priority: i }) => /* @__PURE__ */ _("img", {
|
|
227
|
+
src: e,
|
|
228
|
+
alt: t,
|
|
229
|
+
sizes: n,
|
|
230
|
+
className: r,
|
|
231
|
+
loading: i ? "eager" : "lazy",
|
|
232
|
+
decoding: "async",
|
|
233
|
+
fetchPriority: i ? "high" : void 0
|
|
234
|
+
}),
|
|
235
|
+
locale: "en-US",
|
|
236
|
+
currency: "USD",
|
|
237
|
+
hrefs: {
|
|
238
|
+
products: "/admin/products",
|
|
239
|
+
product: (e) => `/admin/products/${e}`,
|
|
240
|
+
newProduct: "/admin/products/new",
|
|
241
|
+
orders: "/admin/orders",
|
|
242
|
+
order: (e) => `/admin/orders/${e}`,
|
|
243
|
+
shippingRates: "/admin/shipping-rates"
|
|
244
|
+
},
|
|
245
|
+
client: null,
|
|
246
|
+
labels: {
|
|
247
|
+
loading: "Loading…",
|
|
248
|
+
empty: "Nothing here yet.",
|
|
249
|
+
save: "Save",
|
|
250
|
+
cancel: "Cancel",
|
|
251
|
+
confirm: "Confirm",
|
|
252
|
+
dismiss: "Dismiss",
|
|
253
|
+
navLabel: "Admin",
|
|
254
|
+
nav: {
|
|
255
|
+
products: "Products",
|
|
256
|
+
orders: "Orders",
|
|
257
|
+
shippingRates: "Shipping rates"
|
|
258
|
+
},
|
|
259
|
+
statuses: {
|
|
260
|
+
draft: "Draft",
|
|
261
|
+
active: "Active",
|
|
262
|
+
archived: "Archived",
|
|
263
|
+
pending: "Pending",
|
|
264
|
+
paid: "Paid",
|
|
265
|
+
shipped: "Shipped",
|
|
266
|
+
cancelled: "Cancelled",
|
|
267
|
+
expired: "Expired",
|
|
268
|
+
needs_attention: "Needs attention",
|
|
269
|
+
refunded: "Refunded",
|
|
270
|
+
sold: "Sold"
|
|
271
|
+
},
|
|
272
|
+
errors: {
|
|
273
|
+
unauthorized: "You are not signed in or not allowed to do this.",
|
|
274
|
+
notFound: "We could not find that.",
|
|
275
|
+
invalidInput: "Some of the details are not valid. Check them and try again.",
|
|
276
|
+
invalidOrderState: "This order cannot be changed that way in its current state.",
|
|
277
|
+
insufficientStock: "Not enough stock is available.",
|
|
278
|
+
refundExceedsBalance: "The refund is more than the remaining balance.",
|
|
279
|
+
refundGateway: "The payment provider rejected the refund. Try again shortly.",
|
|
280
|
+
refundOutcomeUnknown: "Refund outcome unknown — retry with the same request.",
|
|
281
|
+
imageInvalid: "That image could not be used. Try a different file.",
|
|
282
|
+
imageTooLarge: "That image is too large. Choose a smaller one.",
|
|
283
|
+
generic: "Something went wrong. Try again."
|
|
284
|
+
},
|
|
285
|
+
products: C,
|
|
286
|
+
orders: x,
|
|
287
|
+
shipping: S
|
|
288
|
+
}
|
|
289
|
+
}, T = u(w);
|
|
290
|
+
function E(e) {
|
|
291
|
+
let t = x;
|
|
292
|
+
return {
|
|
293
|
+
...t,
|
|
294
|
+
...e,
|
|
295
|
+
tabs: {
|
|
296
|
+
...t.tabs,
|
|
297
|
+
...e?.tabs
|
|
298
|
+
},
|
|
299
|
+
empty: {
|
|
300
|
+
...t.empty,
|
|
301
|
+
...e?.empty
|
|
302
|
+
},
|
|
303
|
+
columns: {
|
|
304
|
+
...t.columns,
|
|
305
|
+
...e?.columns
|
|
306
|
+
},
|
|
307
|
+
itemColumns: {
|
|
308
|
+
...t.itemColumns,
|
|
309
|
+
...e?.itemColumns
|
|
310
|
+
},
|
|
311
|
+
refundColumns: {
|
|
312
|
+
...t.refundColumns,
|
|
313
|
+
...e?.refundColumns
|
|
314
|
+
},
|
|
315
|
+
refundSources: {
|
|
316
|
+
...t.refundSources,
|
|
317
|
+
...e?.refundSources
|
|
318
|
+
},
|
|
319
|
+
refundStatuses: {
|
|
320
|
+
...t.refundStatuses,
|
|
321
|
+
...e?.refundStatuses
|
|
322
|
+
},
|
|
323
|
+
actions: {
|
|
324
|
+
...t.actions,
|
|
325
|
+
...e?.actions
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
function D(e) {
|
|
330
|
+
let t = C;
|
|
331
|
+
return {
|
|
332
|
+
...t,
|
|
333
|
+
...e,
|
|
334
|
+
filters: {
|
|
335
|
+
...t.filters,
|
|
336
|
+
...e?.filters
|
|
337
|
+
},
|
|
338
|
+
empty: {
|
|
339
|
+
...t.empty,
|
|
340
|
+
...e?.empty
|
|
341
|
+
},
|
|
342
|
+
columns: {
|
|
343
|
+
...t.columns,
|
|
344
|
+
...e?.columns
|
|
345
|
+
},
|
|
346
|
+
fields: {
|
|
347
|
+
...t.fields,
|
|
348
|
+
...e?.fields
|
|
349
|
+
},
|
|
350
|
+
validation: {
|
|
351
|
+
...t.validation,
|
|
352
|
+
...e?.validation
|
|
353
|
+
},
|
|
354
|
+
images: {
|
|
355
|
+
...t.images,
|
|
356
|
+
...e?.images
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
function O({ children: e, hrefs: t, labels: n, ...r }) {
|
|
361
|
+
let i = {
|
|
362
|
+
...w,
|
|
363
|
+
...r,
|
|
364
|
+
hrefs: {
|
|
365
|
+
...w.hrefs,
|
|
366
|
+
...t
|
|
367
|
+
},
|
|
368
|
+
labels: {
|
|
369
|
+
...w.labels,
|
|
370
|
+
...n,
|
|
371
|
+
nav: {
|
|
372
|
+
...w.labels.nav,
|
|
373
|
+
...n?.nav
|
|
374
|
+
},
|
|
375
|
+
statuses: {
|
|
376
|
+
...w.labels.statuses,
|
|
377
|
+
...n?.statuses
|
|
378
|
+
},
|
|
379
|
+
errors: {
|
|
380
|
+
...w.labels.errors,
|
|
381
|
+
...n?.errors
|
|
382
|
+
},
|
|
383
|
+
products: D(n?.products),
|
|
384
|
+
orders: E(n?.orders),
|
|
385
|
+
shipping: {
|
|
386
|
+
...S,
|
|
387
|
+
...n?.shipping
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
return /* @__PURE__ */ _(T.Provider, {
|
|
392
|
+
value: i,
|
|
393
|
+
children: e
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
function k() {
|
|
397
|
+
return f(T);
|
|
398
|
+
}
|
|
399
|
+
function A() {
|
|
400
|
+
let { client: e } = k();
|
|
401
|
+
if (!e) throw Error("AdminProvider needs a `client` to render this view.");
|
|
402
|
+
return e;
|
|
403
|
+
}
|
|
404
|
+
// src/lib/use-admin-query.ts
|
|
405
|
+
function j(e, t) {
|
|
406
|
+
let n = m(t);
|
|
407
|
+
p(() => {
|
|
408
|
+
n.current = t;
|
|
409
|
+
});
|
|
410
|
+
let [r, i] = h(0), [a, o] = h({
|
|
411
|
+
request: "",
|
|
412
|
+
data: void 0,
|
|
413
|
+
error: void 0
|
|
414
|
+
}), s = `${JSON.stringify(e)}#${r}`;
|
|
415
|
+
p(() => {
|
|
416
|
+
let e = new AbortController();
|
|
417
|
+
return n.current(e.signal).then((t) => {
|
|
418
|
+
e.signal.aborted || o({
|
|
419
|
+
request: s,
|
|
420
|
+
data: t,
|
|
421
|
+
error: void 0
|
|
422
|
+
});
|
|
423
|
+
}).catch((t) => {
|
|
424
|
+
e.signal.aborted || o((e) => ({
|
|
425
|
+
request: s,
|
|
426
|
+
data: e.data,
|
|
427
|
+
error: t
|
|
428
|
+
}));
|
|
429
|
+
}), () => e.abort();
|
|
430
|
+
}, [s]);
|
|
431
|
+
let c = d(() => i((e) => e + 1), []), l = a.request === s;
|
|
432
|
+
return {
|
|
433
|
+
data: a.data,
|
|
434
|
+
error: l ? a.error : void 0,
|
|
435
|
+
loading: !l,
|
|
436
|
+
reload: c
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
// src/lib/use-admin-mutation.ts
|
|
440
|
+
function M(e) {
|
|
441
|
+
let t = m(e);
|
|
442
|
+
p(() => {
|
|
443
|
+
t.current = e;
|
|
444
|
+
});
|
|
445
|
+
let [n, r] = h(!1), [i, a] = h(void 0);
|
|
446
|
+
return {
|
|
447
|
+
run: d(async (...e) => {
|
|
448
|
+
r(!0), a(void 0);
|
|
449
|
+
try {
|
|
450
|
+
return await t.current(...e);
|
|
451
|
+
} catch (e) {
|
|
452
|
+
a(e);
|
|
453
|
+
return;
|
|
454
|
+
} finally {
|
|
455
|
+
r(!1);
|
|
456
|
+
}
|
|
457
|
+
}, []),
|
|
458
|
+
pending: n,
|
|
459
|
+
error: i,
|
|
460
|
+
reset: d(() => a(void 0), [])
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
// src/components/admin-layout/admin-layout.tsx
|
|
464
|
+
function N({ children: e, extraNav: t = [], header: n, footer: r }) {
|
|
465
|
+
let { hrefs: i, labels: a, renderLink: o } = k(), s = [
|
|
466
|
+
{
|
|
467
|
+
href: i.products,
|
|
468
|
+
label: a.nav.products
|
|
469
|
+
},
|
|
470
|
+
{
|
|
471
|
+
href: i.orders,
|
|
472
|
+
label: a.nav.orders
|
|
473
|
+
},
|
|
474
|
+
{
|
|
475
|
+
href: i.shippingRates,
|
|
476
|
+
label: a.nav.shippingRates
|
|
477
|
+
}
|
|
478
|
+
], c = [
|
|
479
|
+
...t.filter((e) => e.position === "start"),
|
|
480
|
+
...s,
|
|
481
|
+
...t.filter((e) => e.position !== "start")
|
|
482
|
+
];
|
|
483
|
+
return /* @__PURE__ */ v("div", {
|
|
484
|
+
className: "sfa-root sfa-layout",
|
|
485
|
+
children: [
|
|
486
|
+
n ? /* @__PURE__ */ _("header", {
|
|
487
|
+
className: "sfa-layout__header",
|
|
488
|
+
children: n
|
|
489
|
+
}) : null,
|
|
490
|
+
/* @__PURE__ */ _("nav", {
|
|
491
|
+
className: "sfa-nav",
|
|
492
|
+
"aria-label": a.navLabel,
|
|
493
|
+
children: /* @__PURE__ */ _("ul", { children: c.map((e) => /* @__PURE__ */ _("li", { children: o({
|
|
494
|
+
href: e.href,
|
|
495
|
+
className: "sfa-nav__link",
|
|
496
|
+
children: e.label
|
|
497
|
+
}) }, e.href)) })
|
|
498
|
+
}),
|
|
499
|
+
/* @__PURE__ */ _("main", {
|
|
500
|
+
className: "sfa-layout__content",
|
|
501
|
+
children: e
|
|
502
|
+
}),
|
|
503
|
+
r ? /* @__PURE__ */ _("footer", {
|
|
504
|
+
className: "sfa-layout__footer",
|
|
505
|
+
children: r
|
|
506
|
+
}) : null
|
|
507
|
+
]
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
// src/components/admin-table/admin-table.tsx
|
|
511
|
+
function P({ columns: e, rows: t, rowKey: n, caption: r }) {
|
|
512
|
+
let { labels: i } = k();
|
|
513
|
+
return t.length === 0 ? /* @__PURE__ */ _("p", {
|
|
514
|
+
className: "sfa-empty",
|
|
515
|
+
children: i.empty
|
|
516
|
+
}) : /* @__PURE__ */ v("table", {
|
|
517
|
+
className: "sfa-table sfa-table--stacked",
|
|
518
|
+
children: [
|
|
519
|
+
r ? /* @__PURE__ */ _("caption", { children: r }) : null,
|
|
520
|
+
/* @__PURE__ */ _("thead", { children: /* @__PURE__ */ _("tr", { children: e.map((e) => /* @__PURE__ */ _("th", {
|
|
521
|
+
scope: "col",
|
|
522
|
+
children: e.header
|
|
523
|
+
}, e.key)) }) }),
|
|
524
|
+
/* @__PURE__ */ _("tbody", { children: t.map((t) => /* @__PURE__ */ _("tr", { children: e.map((e) => /* @__PURE__ */ _("td", {
|
|
525
|
+
"data-label": e.header,
|
|
526
|
+
children: e.render(t)
|
|
527
|
+
}, e.key)) }, n(t))) })
|
|
528
|
+
]
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
// src/components/status-badge/status-badge.tsx
|
|
532
|
+
function F({ status: e }) {
|
|
533
|
+
let { labels: t } = k();
|
|
534
|
+
return /* @__PURE__ */ _("span", {
|
|
535
|
+
className: `sfa-badge sfa-badge--${e.replace(/_/g, "-")}`,
|
|
536
|
+
children: t.statuses[e] ?? e
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
// src/components/money/money.tsx
|
|
540
|
+
function I({ cents: e, currency: t }) {
|
|
541
|
+
let { locale: n } = k(), r = new Intl.NumberFormat(n, {
|
|
542
|
+
style: "currency",
|
|
543
|
+
currency: t
|
|
544
|
+
}).format(e / 100);
|
|
545
|
+
return /* @__PURE__ */ _("span", {
|
|
546
|
+
className: "sfa-money",
|
|
547
|
+
children: r
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
// src/components/confirm-dialog/confirm-dialog.tsx
|
|
551
|
+
var L = "button:not([disabled]), [href], input:not([disabled]), select, textarea, [tabindex]:not([tabindex=\"-1\"])";
|
|
552
|
+
function R({ open: e, title: t, children: n, confirmLabel: r, destructive: i = !1, pending: a = !1, onConfirm: o, onCancel: s }) {
|
|
553
|
+
let { labels: c } = k(), l = m(null);
|
|
554
|
+
return p(() => {
|
|
555
|
+
if (!e) return;
|
|
556
|
+
let t = document.activeElement;
|
|
557
|
+
return l.current?.querySelector(L)?.focus(), () => t?.focus();
|
|
558
|
+
}, [e]), e ? /* @__PURE__ */ _("div", {
|
|
559
|
+
className: "sfa-dialog-backdrop",
|
|
560
|
+
onKeyDown: (e) => {
|
|
561
|
+
if (e.key === "Escape") {
|
|
562
|
+
e.stopPropagation(), s();
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
if (e.key !== "Tab") return;
|
|
566
|
+
let t = Array.from(l.current?.querySelectorAll(L) ?? []);
|
|
567
|
+
if (t.length === 0) return;
|
|
568
|
+
let n = t[0], r = t[t.length - 1];
|
|
569
|
+
e.shiftKey && document.activeElement === n ? (e.preventDefault(), r.focus()) : !e.shiftKey && document.activeElement === r && (e.preventDefault(), n.focus());
|
|
570
|
+
},
|
|
571
|
+
children: /* @__PURE__ */ v("div", {
|
|
572
|
+
ref: l,
|
|
573
|
+
role: "dialog",
|
|
574
|
+
"aria-modal": "true",
|
|
575
|
+
"aria-label": t,
|
|
576
|
+
className: "sfa-dialog",
|
|
577
|
+
children: [
|
|
578
|
+
/* @__PURE__ */ _("h2", {
|
|
579
|
+
className: "sfa-dialog__title",
|
|
580
|
+
children: t
|
|
581
|
+
}),
|
|
582
|
+
n,
|
|
583
|
+
/* @__PURE__ */ v("div", {
|
|
584
|
+
className: "sfa-dialog__actions",
|
|
585
|
+
children: [/* @__PURE__ */ _("button", {
|
|
586
|
+
type: "button",
|
|
587
|
+
className: "sfa-btn",
|
|
588
|
+
onClick: s,
|
|
589
|
+
children: c.cancel
|
|
590
|
+
}), /* @__PURE__ */ _("button", {
|
|
591
|
+
type: "button",
|
|
592
|
+
className: `sfa-btn ${i ? "sfa-btn--danger" : "sfa-btn--primary"}`,
|
|
593
|
+
disabled: a,
|
|
594
|
+
onClick: o,
|
|
595
|
+
children: r ?? c.confirm
|
|
596
|
+
})]
|
|
597
|
+
})
|
|
598
|
+
]
|
|
599
|
+
})
|
|
600
|
+
}) : null;
|
|
601
|
+
}
|
|
602
|
+
// src/components/notice/notice.tsx
|
|
603
|
+
function z({ variant: e, children: t, toast: n = !1, duration: r = 4e3, onDismiss: i }) {
|
|
604
|
+
let { labels: a } = k();
|
|
605
|
+
p(() => {
|
|
606
|
+
if (!n || !i) return;
|
|
607
|
+
let e = setTimeout(i, r);
|
|
608
|
+
return () => clearTimeout(e);
|
|
609
|
+
}, [
|
|
610
|
+
n,
|
|
611
|
+
r,
|
|
612
|
+
i
|
|
613
|
+
]);
|
|
614
|
+
let o = e === "error" ? "alert" : "status", s = `sfa-notice sfa-notice--${e}${n ? " sfa-notice--toast" : ""}`;
|
|
615
|
+
return /* @__PURE__ */ v("div", {
|
|
616
|
+
role: o,
|
|
617
|
+
className: s,
|
|
618
|
+
children: [/* @__PURE__ */ _("span", {
|
|
619
|
+
className: "sfa-notice__body",
|
|
620
|
+
children: t
|
|
621
|
+
}), i && !n ? /* @__PURE__ */ _("button", {
|
|
622
|
+
type: "button",
|
|
623
|
+
className: "sfa-btn",
|
|
624
|
+
onClick: i,
|
|
625
|
+
children: a.dismiss
|
|
626
|
+
}) : null]
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
// src/components/error-message/error-message.tsx
|
|
630
|
+
var B = [
|
|
631
|
+
[e, "unauthorized"],
|
|
632
|
+
[i, "notFound"],
|
|
633
|
+
[s, "invalidInput"],
|
|
634
|
+
[a, "invalidOrderState"],
|
|
635
|
+
[c, "insufficientStock"],
|
|
636
|
+
[l, "refundExceedsBalance"],
|
|
637
|
+
[n, "refundGateway"],
|
|
638
|
+
[r, "refundOutcomeUnknown"],
|
|
639
|
+
[o, "imageTooLarge"],
|
|
640
|
+
[t, "imageInvalid"]
|
|
641
|
+
];
|
|
642
|
+
function V(e) {
|
|
643
|
+
return B.find(([t]) => e instanceof t)?.[1] ?? "generic";
|
|
644
|
+
}
|
|
645
|
+
function H({ error: e }) {
|
|
646
|
+
let { labels: t } = k();
|
|
647
|
+
return e ? /* @__PURE__ */ _(z, {
|
|
648
|
+
variant: "error",
|
|
649
|
+
children: t.errors[V(e)]
|
|
650
|
+
}) : null;
|
|
651
|
+
}
|
|
652
|
+
// src/lib/product-filter.ts
|
|
653
|
+
function U(e) {
|
|
654
|
+
return e.status === "active" && e.quantity === 0;
|
|
655
|
+
}
|
|
656
|
+
function ee(e) {
|
|
657
|
+
return U(e) ? "sold" : e.status;
|
|
658
|
+
}
|
|
659
|
+
function te(e) {
|
|
660
|
+
switch (e) {
|
|
661
|
+
case "live":
|
|
662
|
+
case "sold": return "active";
|
|
663
|
+
case "draft":
|
|
664
|
+
case "archived": return e;
|
|
665
|
+
case "all": return;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
function ne(e) {
|
|
669
|
+
if (e === "live") return "in";
|
|
670
|
+
if (e === "sold") return "sold";
|
|
671
|
+
}
|
|
672
|
+
// src/lib/use-debounced.ts
|
|
673
|
+
function re(e, t) {
|
|
674
|
+
let [n, r] = h(e);
|
|
675
|
+
return p(() => {
|
|
676
|
+
let n = setTimeout(() => r(e), t);
|
|
677
|
+
return () => clearTimeout(n);
|
|
678
|
+
}, [e, t]), n;
|
|
679
|
+
}
|
|
680
|
+
// src/lib/use-product-pages.ts
|
|
681
|
+
function ie(e) {
|
|
682
|
+
let t = A(), n = j(["admin-products", e], () => t.listProducts(e)), [r, i] = h(null), a = M(async (n, r) => {
|
|
683
|
+
let a = await t.listProducts({
|
|
684
|
+
...e,
|
|
685
|
+
cursor: n
|
|
686
|
+
});
|
|
687
|
+
i((e) => ({
|
|
688
|
+
base: r,
|
|
689
|
+
items: [...e?.base === r ? e.items : [], ...a.items],
|
|
690
|
+
nextCursor: a.nextCursor
|
|
691
|
+
}));
|
|
692
|
+
}), o = n.data, s = r && r.base === o ? r : null, c = s ? s.nextCursor : o?.nextCursor ?? null;
|
|
693
|
+
return {
|
|
694
|
+
items: [...o?.items ?? [], ...s?.items ?? []],
|
|
695
|
+
loaded: o !== void 0,
|
|
696
|
+
loading: n.loading,
|
|
697
|
+
error: n.error ?? a.error,
|
|
698
|
+
hasMore: !n.loading && c !== null,
|
|
699
|
+
loadingMore: a.pending,
|
|
700
|
+
reload: n.reload,
|
|
701
|
+
loadMore: () => {
|
|
702
|
+
o && c && a.run(c, o);
|
|
703
|
+
}
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
// src/views/products/admin-product-list.tsx
|
|
707
|
+
var ae = [
|
|
708
|
+
"all",
|
|
709
|
+
"live",
|
|
710
|
+
"sold",
|
|
711
|
+
"draft",
|
|
712
|
+
"archived"
|
|
713
|
+
];
|
|
714
|
+
function oe() {
|
|
715
|
+
let e = A(), { labels: t, hrefs: n, renderLink: r } = k(), i = t.products, [a, o] = h("all"), [s, c] = h(""), l = re(s.trim(), 300), u = te(a), d = ne(a), f = ie({
|
|
716
|
+
...u ? { status: u } : {},
|
|
717
|
+
...d ? { stock: d } : {},
|
|
718
|
+
...l ? { q: l } : {}
|
|
719
|
+
}), [p, m] = h(null), [g, y] = h(!1), b = M(({ kind: t, product: n }) => e.updateProduct(n.id, t === "sold" ? { sold: !0 } : { status: "archived" })), x = async () => {
|
|
720
|
+
if (!p) return;
|
|
721
|
+
let e = await b.run(p);
|
|
722
|
+
m(null), e && (y(!0), f.reload());
|
|
723
|
+
}, S = [
|
|
724
|
+
{
|
|
725
|
+
key: "image",
|
|
726
|
+
header: i.columns.image,
|
|
727
|
+
render: (e) => e.images[0] ? /* @__PURE__ */ _("img", {
|
|
728
|
+
className: "sfa-thumb",
|
|
729
|
+
src: e.images[0].url,
|
|
730
|
+
alt: e.images[0].alt,
|
|
731
|
+
width: 48,
|
|
732
|
+
height: 48
|
|
733
|
+
}) : /* @__PURE__ */ _("span", {
|
|
734
|
+
className: "sfa-thumb sfa-thumb--empty",
|
|
735
|
+
children: i.noImage
|
|
736
|
+
})
|
|
737
|
+
},
|
|
738
|
+
{
|
|
739
|
+
key: "name",
|
|
740
|
+
header: i.columns.name,
|
|
741
|
+
render: (e) => r({
|
|
742
|
+
href: n.product(e.id),
|
|
743
|
+
children: e.name,
|
|
744
|
+
className: "sfa-link--tap"
|
|
745
|
+
})
|
|
746
|
+
},
|
|
747
|
+
{
|
|
748
|
+
key: "price",
|
|
749
|
+
header: i.columns.price,
|
|
750
|
+
render: (e) => /* @__PURE__ */ _(I, {
|
|
751
|
+
cents: e.priceCents,
|
|
752
|
+
currency: e.currency
|
|
753
|
+
})
|
|
754
|
+
},
|
|
755
|
+
{
|
|
756
|
+
key: "status",
|
|
757
|
+
header: i.columns.status,
|
|
758
|
+
render: (e) => /* @__PURE__ */ _(F, { status: ee(e) })
|
|
759
|
+
},
|
|
760
|
+
{
|
|
761
|
+
key: "quantity",
|
|
762
|
+
header: i.columns.quantity,
|
|
763
|
+
render: (e) => e.quantity
|
|
764
|
+
},
|
|
765
|
+
{
|
|
766
|
+
key: "actions",
|
|
767
|
+
header: i.columns.actions,
|
|
768
|
+
render: (e) => /* @__PURE__ */ v("div", {
|
|
769
|
+
className: "sfa-row-actions",
|
|
770
|
+
children: [
|
|
771
|
+
e.status === "active" && n.storefrontProduct ? r({
|
|
772
|
+
href: n.storefrontProduct(e.slug),
|
|
773
|
+
children: i.viewInShop,
|
|
774
|
+
className: "sfa-btn"
|
|
775
|
+
}) : null,
|
|
776
|
+
e.status !== "archived" && e.quantity > 0 ? /* @__PURE__ */ _("button", {
|
|
777
|
+
type: "button",
|
|
778
|
+
className: "sfa-btn",
|
|
779
|
+
onClick: () => m({
|
|
780
|
+
kind: "sold",
|
|
781
|
+
product: e
|
|
782
|
+
}),
|
|
783
|
+
children: i.markSold
|
|
784
|
+
}) : null,
|
|
785
|
+
e.status === "archived" ? null : /* @__PURE__ */ _("button", {
|
|
786
|
+
type: "button",
|
|
787
|
+
className: "sfa-btn",
|
|
788
|
+
onClick: () => m({
|
|
789
|
+
kind: "archive",
|
|
790
|
+
product: e
|
|
791
|
+
}),
|
|
792
|
+
children: i.archive
|
|
793
|
+
})
|
|
794
|
+
]
|
|
795
|
+
})
|
|
796
|
+
}
|
|
797
|
+
], C = f.items, w = l ? i.noMatches : i.empty[a];
|
|
798
|
+
return /* @__PURE__ */ v("section", {
|
|
799
|
+
className: "sfa-products",
|
|
800
|
+
children: [
|
|
801
|
+
/* @__PURE__ */ v("header", {
|
|
802
|
+
className: "sfa-products__header",
|
|
803
|
+
children: [/* @__PURE__ */ _("h1", { children: i.title }), r({
|
|
804
|
+
href: n.newProduct,
|
|
805
|
+
children: i.newProduct,
|
|
806
|
+
className: "sfa-btn sfa-btn--primary"
|
|
807
|
+
})]
|
|
808
|
+
}),
|
|
809
|
+
/* @__PURE__ */ v("div", {
|
|
810
|
+
className: "sfa-products__toolbar",
|
|
811
|
+
children: [/* @__PURE__ */ _("div", {
|
|
812
|
+
role: "group",
|
|
813
|
+
"aria-label": i.columns.status,
|
|
814
|
+
className: "sfa-filter-group",
|
|
815
|
+
children: ae.map((e) => /* @__PURE__ */ _("button", {
|
|
816
|
+
type: "button",
|
|
817
|
+
className: "sfa-btn sfa-filter",
|
|
818
|
+
"aria-pressed": a === e,
|
|
819
|
+
onClick: () => o(e),
|
|
820
|
+
children: i.filters[e]
|
|
821
|
+
}, e))
|
|
822
|
+
}), /* @__PURE__ */ _("input", {
|
|
823
|
+
type: "search",
|
|
824
|
+
"aria-label": i.searchLabel,
|
|
825
|
+
placeholder: i.searchPlaceholder,
|
|
826
|
+
value: s,
|
|
827
|
+
onChange: (e) => c(e.target.value)
|
|
828
|
+
})]
|
|
829
|
+
}),
|
|
830
|
+
/* @__PURE__ */ _(H, { error: f.error ?? b.error }),
|
|
831
|
+
f.loading && !f.loaded ? /* @__PURE__ */ _("p", { children: t.loading }) : C.length === 0 ? /* @__PURE__ */ _("p", {
|
|
832
|
+
className: "sfa-empty",
|
|
833
|
+
children: w
|
|
834
|
+
}) : /* @__PURE__ */ _(P, {
|
|
835
|
+
columns: S,
|
|
836
|
+
rows: C,
|
|
837
|
+
rowKey: (e) => e.id
|
|
838
|
+
}),
|
|
839
|
+
f.hasMore ? /* @__PURE__ */ _("button", {
|
|
840
|
+
type: "button",
|
|
841
|
+
className: "sfa-btn sfa-products__more",
|
|
842
|
+
disabled: f.loadingMore,
|
|
843
|
+
onClick: f.loadMore,
|
|
844
|
+
children: i.loadMore
|
|
845
|
+
}) : null,
|
|
846
|
+
/* @__PURE__ */ _(R, {
|
|
847
|
+
open: p !== null,
|
|
848
|
+
title: p?.kind === "archive" ? i.archiveTitle : i.markSoldTitle,
|
|
849
|
+
confirmLabel: p?.kind === "archive" ? i.archive : i.markSold,
|
|
850
|
+
pending: b.pending,
|
|
851
|
+
onConfirm: x,
|
|
852
|
+
onCancel: () => m(null),
|
|
853
|
+
children: /* @__PURE__ */ v("p", { children: [
|
|
854
|
+
p?.product.name,
|
|
855
|
+
" — ",
|
|
856
|
+
p?.kind === "archive" ? i.archiveBody : i.markSoldBody
|
|
857
|
+
] })
|
|
858
|
+
}),
|
|
859
|
+
g ? /* @__PURE__ */ _(z, {
|
|
860
|
+
variant: "success",
|
|
861
|
+
toast: !0,
|
|
862
|
+
onDismiss: () => y(!1),
|
|
863
|
+
children: i.updated
|
|
864
|
+
}) : null
|
|
865
|
+
]
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
// src/lib/money-input.ts
|
|
869
|
+
var se = /^\$?\s*(\d+|\d{1,3}(?:,\d{3})+)?(?:\.(\d{1,2}))?$/;
|
|
870
|
+
function W(e) {
|
|
871
|
+
let t = e.trim(), n = se.exec(t);
|
|
872
|
+
if (!n || !n[1] && !n[2]) return null;
|
|
873
|
+
let r = Number((n[1] ?? "0").replace(/,/g, "")), i = Number((n[2] ?? "").padEnd(2, "0")), a = r * 100 + i;
|
|
874
|
+
return Number.isSafeInteger(a) ? a : null;
|
|
875
|
+
}
|
|
876
|
+
function G(e) {
|
|
877
|
+
return `${Math.floor(e / 100)}.${String(e % 100).padStart(2, "0")}`;
|
|
878
|
+
}
|
|
879
|
+
// src/lib/product-form.ts
|
|
880
|
+
var K = [
|
|
881
|
+
"name",
|
|
882
|
+
"category",
|
|
883
|
+
"description",
|
|
884
|
+
"materials",
|
|
885
|
+
"dimensions",
|
|
886
|
+
"price",
|
|
887
|
+
"quantity",
|
|
888
|
+
"status",
|
|
889
|
+
"featured"
|
|
890
|
+
], ce = {
|
|
891
|
+
name: "",
|
|
892
|
+
category: "",
|
|
893
|
+
description: "",
|
|
894
|
+
materials: "",
|
|
895
|
+
dimensions: "",
|
|
896
|
+
price: "",
|
|
897
|
+
quantity: "1",
|
|
898
|
+
status: "draft",
|
|
899
|
+
featured: !1
|
|
900
|
+
};
|
|
901
|
+
function q(e) {
|
|
902
|
+
return {
|
|
903
|
+
name: e.name,
|
|
904
|
+
category: e.category,
|
|
905
|
+
description: e.description,
|
|
906
|
+
materials: e.materials ?? "",
|
|
907
|
+
dimensions: e.dimensions ?? "",
|
|
908
|
+
price: G(e.priceCents),
|
|
909
|
+
quantity: String(e.quantity),
|
|
910
|
+
status: e.status,
|
|
911
|
+
featured: e.featured
|
|
912
|
+
};
|
|
913
|
+
}
|
|
914
|
+
function le(e) {
|
|
915
|
+
let t = String(Array.isArray(e) ? e[0] ?? "" : e ?? ""), n = t === "priceCents" ? "price" : t;
|
|
916
|
+
return K.includes(n) ? n : void 0;
|
|
917
|
+
}
|
|
918
|
+
function ue(e) {
|
|
919
|
+
let t = {};
|
|
920
|
+
for (let n of e) {
|
|
921
|
+
let { path: e, message: r } = n ?? {}, i = le(e);
|
|
922
|
+
i && !t[i] && (t[i] = typeof r == "string" ? r : "Invalid value.");
|
|
923
|
+
}
|
|
924
|
+
return t;
|
|
925
|
+
}
|
|
926
|
+
function de(e) {
|
|
927
|
+
return K.find((t) => e[t]);
|
|
928
|
+
}
|
|
929
|
+
function fe(e) {
|
|
930
|
+
let t = e.trim();
|
|
931
|
+
return t === "" ? null : t;
|
|
932
|
+
}
|
|
933
|
+
function pe(e, t, n) {
|
|
934
|
+
let r = {}, i = W(e.price);
|
|
935
|
+
i === null && (r.price = t.validation.price);
|
|
936
|
+
let a = /^\d+$/.test(e.quantity.trim()) ? Number(e.quantity.trim()) : null;
|
|
937
|
+
a === null && (r.quantity = t.validation.quantity);
|
|
938
|
+
let o = y.safeParse({
|
|
939
|
+
name: e.name,
|
|
940
|
+
description: e.description,
|
|
941
|
+
materials: fe(e.materials),
|
|
942
|
+
dimensions: fe(e.dimensions),
|
|
943
|
+
priceCents: i ?? 0,
|
|
944
|
+
...n ? { currency: n } : {},
|
|
945
|
+
category: e.category,
|
|
946
|
+
quantity: a ?? 0,
|
|
947
|
+
status: e.status,
|
|
948
|
+
featured: e.featured
|
|
949
|
+
});
|
|
950
|
+
if (!o.success) for (let e of o.error.issues) {
|
|
951
|
+
let n = le(e.path);
|
|
952
|
+
n && !r[n] && (r[n] = t.validation.required);
|
|
953
|
+
}
|
|
954
|
+
return !o.success || Object.keys(r).length > 0 ? {
|
|
955
|
+
ok: !1,
|
|
956
|
+
errors: r
|
|
957
|
+
} : {
|
|
958
|
+
ok: !0,
|
|
959
|
+
input: o.data
|
|
960
|
+
};
|
|
961
|
+
}
|
|
962
|
+
var me = [
|
|
963
|
+
"name",
|
|
964
|
+
"description",
|
|
965
|
+
"materials",
|
|
966
|
+
"dimensions",
|
|
967
|
+
"priceCents",
|
|
968
|
+
"category",
|
|
969
|
+
"quantity",
|
|
970
|
+
"status",
|
|
971
|
+
"featured"
|
|
972
|
+
];
|
|
973
|
+
function he(e, t) {
|
|
974
|
+
let n = {};
|
|
975
|
+
for (let r of me) (t[r] ?? null) !== e[r] && (n[r] = t[r]);
|
|
976
|
+
return n;
|
|
977
|
+
}
|
|
978
|
+
var ge = [
|
|
979
|
+
"image/jpeg",
|
|
980
|
+
"image/png",
|
|
981
|
+
"image/webp",
|
|
982
|
+
"image/heic"
|
|
983
|
+
];
|
|
984
|
+
function J(e, t) {
|
|
985
|
+
return e.replace(/\{(\w+)\}/g, (e, n) => t[n] ?? "");
|
|
986
|
+
}
|
|
987
|
+
function _e(e, t) {
|
|
988
|
+
return ge.includes(e.type) ? e.size > 8388608 ? J(t.tooLarge, { name: e.name }) : null : J(t.wrongType, { name: e.name });
|
|
989
|
+
}
|
|
990
|
+
// src/lib/use-image-upload.ts
|
|
991
|
+
function ve({ productId: e, onUploaded: t }) {
|
|
992
|
+
let n = A(), { labels: r } = k(), [i, a] = h([]), o = m(0), s = m(Promise.resolve()), c = m(t);
|
|
993
|
+
p(() => {
|
|
994
|
+
c.current = t;
|
|
995
|
+
});
|
|
996
|
+
let l = (e, t) => a((n) => n.map((n) => n.id === e ? {
|
|
997
|
+
...n,
|
|
998
|
+
...t
|
|
999
|
+
} : n)), u = (e) => a((t) => t.filter((t) => t.id !== e)), f = async (t, r, i) => {
|
|
1000
|
+
l(t, { status: "uploading" });
|
|
1001
|
+
try {
|
|
1002
|
+
let a = await n.uploadProductImage(e, r, i);
|
|
1003
|
+
c.current(a), u(t);
|
|
1004
|
+
} catch (e) {
|
|
1005
|
+
l(t, {
|
|
1006
|
+
status: "error",
|
|
1007
|
+
error: e
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
};
|
|
1011
|
+
return {
|
|
1012
|
+
entries: i,
|
|
1013
|
+
upload: d((e, t) => {
|
|
1014
|
+
let n = e.map((e) => ({
|
|
1015
|
+
id: o.current++,
|
|
1016
|
+
file: e,
|
|
1017
|
+
reason: _e(e, r.products.images)
|
|
1018
|
+
}));
|
|
1019
|
+
a((e) => [...e, ...n.map(({ id: e, file: t, reason: n }) => ({
|
|
1020
|
+
id: e,
|
|
1021
|
+
name: t.name,
|
|
1022
|
+
status: n ? "error" : "queued",
|
|
1023
|
+
reason: n ?? void 0
|
|
1024
|
+
}))]);
|
|
1025
|
+
for (let { id: e, file: r, reason: i } of n) i || (s.current = s.current.then(() => f(e, r, t.trim())));
|
|
1026
|
+
}, [
|
|
1027
|
+
n,
|
|
1028
|
+
e,
|
|
1029
|
+
r
|
|
1030
|
+
]),
|
|
1031
|
+
dismiss: u
|
|
1032
|
+
};
|
|
1033
|
+
}
|
|
1034
|
+
// src/views/products/image-tile.tsx
|
|
1035
|
+
function ye({ image: e, index: t, total: n, busy: r, labels: i, onMove: a, onRemove: o }) {
|
|
1036
|
+
let { renderImage: s } = k(), c = e.alt || J(i.photoName, { n: String(t + 1) }), l = (t, n, r) => /* @__PURE__ */ _("button", {
|
|
1037
|
+
type: "button",
|
|
1038
|
+
className: "sfa-btn",
|
|
1039
|
+
"data-image-id": e.id,
|
|
1040
|
+
"data-move": t,
|
|
1041
|
+
"aria-label": `${n}: ${c}`,
|
|
1042
|
+
disabled: r,
|
|
1043
|
+
onClick: () => a(t),
|
|
1044
|
+
children: n
|
|
1045
|
+
});
|
|
1046
|
+
return /* @__PURE__ */ v("li", {
|
|
1047
|
+
className: "sfa-image-tile",
|
|
1048
|
+
"aria-busy": r,
|
|
1049
|
+
"data-image-id": e.id,
|
|
1050
|
+
children: [
|
|
1051
|
+
s({
|
|
1052
|
+
src: e.url,
|
|
1053
|
+
alt: e.alt,
|
|
1054
|
+
sizes: "160px",
|
|
1055
|
+
className: "sfa-image-tile__img"
|
|
1056
|
+
}),
|
|
1057
|
+
t === 0 ? /* @__PURE__ */ _("span", {
|
|
1058
|
+
className: "sfa-image-tile__cover",
|
|
1059
|
+
children: i.cover
|
|
1060
|
+
}) : null,
|
|
1061
|
+
r ? /* @__PURE__ */ _("span", {
|
|
1062
|
+
className: "sfa-spinner",
|
|
1063
|
+
role: "status",
|
|
1064
|
+
children: i.working
|
|
1065
|
+
}) : null,
|
|
1066
|
+
/* @__PURE__ */ v("div", {
|
|
1067
|
+
className: "sfa-image-tile__actions",
|
|
1068
|
+
children: [
|
|
1069
|
+
l("earlier", i.moveEarlier, t === 0),
|
|
1070
|
+
l("later", i.moveLater, t === n - 1),
|
|
1071
|
+
/* @__PURE__ */ _("button", {
|
|
1072
|
+
type: "button",
|
|
1073
|
+
className: "sfa-btn sfa-btn--danger",
|
|
1074
|
+
"aria-label": `${i.remove}: ${c}`,
|
|
1075
|
+
onClick: o,
|
|
1076
|
+
children: i.remove
|
|
1077
|
+
})
|
|
1078
|
+
]
|
|
1079
|
+
})
|
|
1080
|
+
]
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1083
|
+
// src/views/products/upload-picker.tsx
|
|
1084
|
+
function be({ labels: e, onFiles: t }) {
|
|
1085
|
+
let n = (e) => {
|
|
1086
|
+
t(Array.from(e.target.files ?? [])), e.target.value = "";
|
|
1087
|
+
};
|
|
1088
|
+
return /* @__PURE__ */ v("div", {
|
|
1089
|
+
className: "sfa-image-picker",
|
|
1090
|
+
children: [/* @__PURE__ */ v("label", {
|
|
1091
|
+
className: "sfa-btn sfa-image-picker__btn",
|
|
1092
|
+
children: [e.add, /* @__PURE__ */ _("input", {
|
|
1093
|
+
type: "file",
|
|
1094
|
+
accept: "image/*",
|
|
1095
|
+
multiple: !0,
|
|
1096
|
+
className: "sfa-sr-only",
|
|
1097
|
+
onChange: n
|
|
1098
|
+
})]
|
|
1099
|
+
}), /* @__PURE__ */ v("label", {
|
|
1100
|
+
className: "sfa-btn sfa-image-picker__btn",
|
|
1101
|
+
children: [e.takePhoto, /* @__PURE__ */ _("input", {
|
|
1102
|
+
type: "file",
|
|
1103
|
+
accept: "image/*",
|
|
1104
|
+
capture: "environment",
|
|
1105
|
+
className: "sfa-sr-only",
|
|
1106
|
+
onChange: n
|
|
1107
|
+
})]
|
|
1108
|
+
})]
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
// src/views/products/admin-product-images.tsx
|
|
1112
|
+
var Y = (e) => [...e].sort((e, t) => e.position - t.position);
|
|
1113
|
+
function xe({ productId: e, images: t }) {
|
|
1114
|
+
let n = A(), { labels: r } = k(), i = r.products.images, [a, o] = h(() => Y(t)), [s, c] = h(null), [l, u] = h(!1), [d, f] = h(""), [y, b] = h(void 0), [x, S] = h(!1), [C, w] = h(null), T = m(null), E = m(null), { entries: D, upload: O, dismiss: j } = ve({
|
|
1115
|
+
productId: e,
|
|
1116
|
+
onUploaded: (e) => o(Y(e.images))
|
|
1117
|
+
});
|
|
1118
|
+
p(() => {
|
|
1119
|
+
let e = T.current;
|
|
1120
|
+
if (!e) return;
|
|
1121
|
+
T.current = null;
|
|
1122
|
+
let t = (t) => E.current?.querySelector(`[data-image-id="${e.id}"][data-move="${t}"]:not(:disabled)`), n = e.direction === "earlier" ? "later" : "earlier";
|
|
1123
|
+
(t(e.direction) ?? t(n))?.focus();
|
|
1124
|
+
}, [a]);
|
|
1125
|
+
let M = async (t, r) => {
|
|
1126
|
+
let i = r === "earlier" ? t - 1 : t + 1;
|
|
1127
|
+
if (l || i < 0 || i >= a.length) return;
|
|
1128
|
+
let s = a, d = [...a];
|
|
1129
|
+
[d[t], d[i]] = [d[i], d[t]], T.current = {
|
|
1130
|
+
id: a[t].id,
|
|
1131
|
+
direction: r
|
|
1132
|
+
}, o(d), u(!0), c(a[t].id), b(void 0), S(!1);
|
|
1133
|
+
try {
|
|
1134
|
+
let t = await n.reorderProductImages(e, d.map((e) => e.id));
|
|
1135
|
+
o(Y(t.images));
|
|
1136
|
+
} catch (e) {
|
|
1137
|
+
T.current = {
|
|
1138
|
+
id: a[t].id,
|
|
1139
|
+
direction: r
|
|
1140
|
+
}, o(s), b(e), S(!0);
|
|
1141
|
+
} finally {
|
|
1142
|
+
u(!1), c(null);
|
|
1143
|
+
}
|
|
1144
|
+
};
|
|
1145
|
+
return /* @__PURE__ */ v("div", {
|
|
1146
|
+
className: "sfa-images",
|
|
1147
|
+
onDragOver: (e) => e.preventDefault(),
|
|
1148
|
+
onDrop: (e) => {
|
|
1149
|
+
e.preventDefault(), O(Array.from(e.dataTransfer.files), d);
|
|
1150
|
+
},
|
|
1151
|
+
children: [
|
|
1152
|
+
/* @__PURE__ */ _("h2", { children: i.title }),
|
|
1153
|
+
x ? /* @__PURE__ */ _(z, {
|
|
1154
|
+
variant: "error",
|
|
1155
|
+
onDismiss: () => S(!1),
|
|
1156
|
+
children: i.reorderFailed
|
|
1157
|
+
}) : /* @__PURE__ */ _(H, { error: y }),
|
|
1158
|
+
/* @__PURE__ */ v("div", {
|
|
1159
|
+
className: "sfa-field",
|
|
1160
|
+
children: [
|
|
1161
|
+
/* @__PURE__ */ _("label", {
|
|
1162
|
+
className: "sfa-field__label",
|
|
1163
|
+
htmlFor: `${e}-image-alt`,
|
|
1164
|
+
children: i.altLabel
|
|
1165
|
+
}),
|
|
1166
|
+
/* @__PURE__ */ _("input", {
|
|
1167
|
+
id: `${e}-image-alt`,
|
|
1168
|
+
value: d,
|
|
1169
|
+
onChange: (e) => f(e.target.value),
|
|
1170
|
+
onKeyDown: (e) => {
|
|
1171
|
+
e.key === "Enter" && e.preventDefault();
|
|
1172
|
+
}
|
|
1173
|
+
}),
|
|
1174
|
+
/* @__PURE__ */ _("p", {
|
|
1175
|
+
className: "sfa-field__help",
|
|
1176
|
+
children: i.altHelp
|
|
1177
|
+
}),
|
|
1178
|
+
d.trim() === "" ? /* @__PURE__ */ _("p", {
|
|
1179
|
+
className: "sfa-field__error",
|
|
1180
|
+
children: i.altWarning
|
|
1181
|
+
}) : null
|
|
1182
|
+
]
|
|
1183
|
+
}),
|
|
1184
|
+
/* @__PURE__ */ _(be, {
|
|
1185
|
+
labels: i,
|
|
1186
|
+
onFiles: (e) => O(e, d)
|
|
1187
|
+
}),
|
|
1188
|
+
/* @__PURE__ */ _("p", {
|
|
1189
|
+
className: "sfa-field__help",
|
|
1190
|
+
children: i.dropHint
|
|
1191
|
+
}),
|
|
1192
|
+
a.length === 0 && D.length === 0 ? /* @__PURE__ */ _("p", { children: i.empty }) : null,
|
|
1193
|
+
/* @__PURE__ */ v("ul", {
|
|
1194
|
+
ref: E,
|
|
1195
|
+
className: "sfa-image-grid",
|
|
1196
|
+
children: [a.map((e, t) => /* @__PURE__ */ _(ye, {
|
|
1197
|
+
image: e,
|
|
1198
|
+
index: t,
|
|
1199
|
+
total: a.length,
|
|
1200
|
+
busy: s === e.id,
|
|
1201
|
+
labels: i,
|
|
1202
|
+
onMove: (e) => M(t, e),
|
|
1203
|
+
onRemove: () => w(e)
|
|
1204
|
+
}, e.id)), D.map((e) => /* @__PURE__ */ v("li", {
|
|
1205
|
+
className: "sfa-image-tile",
|
|
1206
|
+
"aria-busy": e.status !== "error",
|
|
1207
|
+
children: [/* @__PURE__ */ _("span", { children: e.name }), e.status === "error" ? /* @__PURE__ */ v(g, { children: [e.reason ? /* @__PURE__ */ _(z, {
|
|
1208
|
+
variant: "error",
|
|
1209
|
+
children: e.reason
|
|
1210
|
+
}) : /* @__PURE__ */ _(H, { error: e.error }), /* @__PURE__ */ _("button", {
|
|
1211
|
+
type: "button",
|
|
1212
|
+
className: "sfa-btn",
|
|
1213
|
+
onClick: () => j(e.id),
|
|
1214
|
+
children: i.dismiss
|
|
1215
|
+
})] }) : /* @__PURE__ */ _("span", {
|
|
1216
|
+
className: "sfa-spinner",
|
|
1217
|
+
role: "status",
|
|
1218
|
+
children: e.status === "uploading" ? i.uploading : i.working
|
|
1219
|
+
})]
|
|
1220
|
+
}, e.id))]
|
|
1221
|
+
}),
|
|
1222
|
+
/* @__PURE__ */ _(R, {
|
|
1223
|
+
open: C !== null,
|
|
1224
|
+
title: i.removeTitle,
|
|
1225
|
+
destructive: !0,
|
|
1226
|
+
confirmLabel: i.remove,
|
|
1227
|
+
onConfirm: async () => {
|
|
1228
|
+
if (!C) return;
|
|
1229
|
+
let t = C;
|
|
1230
|
+
w(null), c(t.id), b(void 0), S(!1);
|
|
1231
|
+
try {
|
|
1232
|
+
let r = await n.deleteProductImage(e, t.id);
|
|
1233
|
+
o(Y(r.images));
|
|
1234
|
+
} catch (e) {
|
|
1235
|
+
b(e);
|
|
1236
|
+
} finally {
|
|
1237
|
+
c(null);
|
|
1238
|
+
}
|
|
1239
|
+
},
|
|
1240
|
+
onCancel: () => w(null),
|
|
1241
|
+
children: /* @__PURE__ */ _("p", { children: i.removeBody })
|
|
1242
|
+
})
|
|
1243
|
+
]
|
|
1244
|
+
});
|
|
1245
|
+
}
|
|
1246
|
+
// src/views/products/product-fields.tsx
|
|
1247
|
+
function X({ name: e, label: t, error: n, help: r, children: i }) {
|
|
1248
|
+
let a = `sfa-field-${e}`, o = [r ? `${a}-help` : "", n ? `${a}-error` : ""].filter(Boolean).join(" ");
|
|
1249
|
+
return /* @__PURE__ */ v("div", {
|
|
1250
|
+
className: "sfa-field",
|
|
1251
|
+
children: [
|
|
1252
|
+
/* @__PURE__ */ _("label", {
|
|
1253
|
+
htmlFor: a,
|
|
1254
|
+
className: "sfa-field__label",
|
|
1255
|
+
children: t
|
|
1256
|
+
}),
|
|
1257
|
+
i({
|
|
1258
|
+
id: a,
|
|
1259
|
+
name: e,
|
|
1260
|
+
"aria-invalid": !!n,
|
|
1261
|
+
"aria-describedby": o || void 0
|
|
1262
|
+
}),
|
|
1263
|
+
r ? /* @__PURE__ */ _("p", {
|
|
1264
|
+
id: `${a}-help`,
|
|
1265
|
+
className: "sfa-field__help",
|
|
1266
|
+
children: r
|
|
1267
|
+
}) : null,
|
|
1268
|
+
n ? /* @__PURE__ */ _("p", {
|
|
1269
|
+
id: `${a}-error`,
|
|
1270
|
+
className: "sfa-field__error",
|
|
1271
|
+
children: n
|
|
1272
|
+
}) : null
|
|
1273
|
+
]
|
|
1274
|
+
});
|
|
1275
|
+
}
|
|
1276
|
+
var Se = "sfa-field-category-options";
|
|
1277
|
+
function Ce({ form: e, errors: t, labels: n, categories: r, onChange: i }) {
|
|
1278
|
+
let a = !!r?.length, o = (r) => /* @__PURE__ */ _(X, {
|
|
1279
|
+
name: r,
|
|
1280
|
+
label: n.fields[r],
|
|
1281
|
+
error: t[r],
|
|
1282
|
+
children: (t) => /* @__PURE__ */ _("input", {
|
|
1283
|
+
...t,
|
|
1284
|
+
type: "text",
|
|
1285
|
+
list: r === "category" && a ? Se : void 0,
|
|
1286
|
+
value: e[r],
|
|
1287
|
+
onChange: (e) => i(r, e.target.value)
|
|
1288
|
+
})
|
|
1289
|
+
});
|
|
1290
|
+
return /* @__PURE__ */ v(g, { children: [
|
|
1291
|
+
o("name"),
|
|
1292
|
+
o("category"),
|
|
1293
|
+
a ? /* @__PURE__ */ _("datalist", {
|
|
1294
|
+
id: Se,
|
|
1295
|
+
children: r?.map((e) => /* @__PURE__ */ _("option", { value: e }, e))
|
|
1296
|
+
}) : null,
|
|
1297
|
+
/* @__PURE__ */ _(X, {
|
|
1298
|
+
name: "description",
|
|
1299
|
+
label: n.fields.description,
|
|
1300
|
+
error: t.description,
|
|
1301
|
+
children: (t) => /* @__PURE__ */ _("textarea", {
|
|
1302
|
+
...t,
|
|
1303
|
+
rows: 5,
|
|
1304
|
+
value: e.description,
|
|
1305
|
+
onChange: (e) => i("description", e.target.value)
|
|
1306
|
+
})
|
|
1307
|
+
}),
|
|
1308
|
+
o("materials"),
|
|
1309
|
+
o("dimensions")
|
|
1310
|
+
] });
|
|
1311
|
+
}
|
|
1312
|
+
var we = [
|
|
1313
|
+
"draft",
|
|
1314
|
+
"active",
|
|
1315
|
+
"archived"
|
|
1316
|
+
];
|
|
1317
|
+
function Te({ form: e, errors: t, labels: n, statusLabels: r, onChange: i }) {
|
|
1318
|
+
return /* @__PURE__ */ v(g, { children: [
|
|
1319
|
+
/* @__PURE__ */ _(X, {
|
|
1320
|
+
name: "price",
|
|
1321
|
+
label: n.fields.price,
|
|
1322
|
+
error: t.price,
|
|
1323
|
+
help: n.priceHelp,
|
|
1324
|
+
children: (t) => /* @__PURE__ */ _("input", {
|
|
1325
|
+
...t,
|
|
1326
|
+
type: "text",
|
|
1327
|
+
inputMode: "decimal",
|
|
1328
|
+
value: e.price,
|
|
1329
|
+
onChange: (e) => i("price", e.target.value)
|
|
1330
|
+
})
|
|
1331
|
+
}),
|
|
1332
|
+
/* @__PURE__ */ _(X, {
|
|
1333
|
+
name: "quantity",
|
|
1334
|
+
label: n.fields.quantity,
|
|
1335
|
+
error: t.quantity,
|
|
1336
|
+
children: (t) => /* @__PURE__ */ _("input", {
|
|
1337
|
+
...t,
|
|
1338
|
+
type: "text",
|
|
1339
|
+
inputMode: "numeric",
|
|
1340
|
+
value: e.quantity,
|
|
1341
|
+
onChange: (e) => i("quantity", e.target.value)
|
|
1342
|
+
})
|
|
1343
|
+
}),
|
|
1344
|
+
/* @__PURE__ */ _(X, {
|
|
1345
|
+
name: "status",
|
|
1346
|
+
label: n.fields.status,
|
|
1347
|
+
error: t.status,
|
|
1348
|
+
help: n.statusHelp,
|
|
1349
|
+
children: (t) => /* @__PURE__ */ _("select", {
|
|
1350
|
+
...t,
|
|
1351
|
+
value: e.status,
|
|
1352
|
+
onChange: (e) => i("status", e.target.value),
|
|
1353
|
+
children: we.map((e) => /* @__PURE__ */ _("option", {
|
|
1354
|
+
value: e,
|
|
1355
|
+
children: r[e] ?? e
|
|
1356
|
+
}, e))
|
|
1357
|
+
})
|
|
1358
|
+
}),
|
|
1359
|
+
/* @__PURE__ */ _("div", {
|
|
1360
|
+
className: "sfa-field",
|
|
1361
|
+
children: /* @__PURE__ */ v("label", {
|
|
1362
|
+
className: "sfa-check",
|
|
1363
|
+
htmlFor: "sfa-field-featured",
|
|
1364
|
+
children: [/* @__PURE__ */ _("input", {
|
|
1365
|
+
id: "sfa-field-featured",
|
|
1366
|
+
name: "featured",
|
|
1367
|
+
type: "checkbox",
|
|
1368
|
+
checked: e.featured,
|
|
1369
|
+
onChange: (e) => i("featured", e.target.checked)
|
|
1370
|
+
}), /* @__PURE__ */ _("span", { children: n.fields.featured })]
|
|
1371
|
+
})
|
|
1372
|
+
})
|
|
1373
|
+
] });
|
|
1374
|
+
}
|
|
1375
|
+
// src/views/products/admin-product-editor.tsx
|
|
1376
|
+
function Ee({ productId: e, onSaved: t, imagesSlot: n, categories: r }) {
|
|
1377
|
+
return e ? /* @__PURE__ */ _(De, {
|
|
1378
|
+
productId: e,
|
|
1379
|
+
onSaved: t,
|
|
1380
|
+
imagesSlot: n,
|
|
1381
|
+
categories: r
|
|
1382
|
+
}) : /* @__PURE__ */ _(Oe, {
|
|
1383
|
+
product: void 0,
|
|
1384
|
+
onSaved: t,
|
|
1385
|
+
imagesSlot: null,
|
|
1386
|
+
categories: r
|
|
1387
|
+
});
|
|
1388
|
+
}
|
|
1389
|
+
function De({ productId: e, onSaved: t, imagesSlot: n, categories: r }) {
|
|
1390
|
+
let i = A(), { labels: a } = k(), o = j(["admin-product", e], () => i.getProduct(e));
|
|
1391
|
+
return o.error ? /* @__PURE__ */ _(H, { error: o.error }) : o.data ? /* @__PURE__ */ _(Oe, {
|
|
1392
|
+
product: o.data,
|
|
1393
|
+
onSaved: t,
|
|
1394
|
+
imagesSlot: n,
|
|
1395
|
+
categories: r
|
|
1396
|
+
}, o.data.id) : /* @__PURE__ */ _("p", { children: a.loading });
|
|
1397
|
+
}
|
|
1398
|
+
function Oe({ product: e, onSaved: t, imagesSlot: n, categories: r }) {
|
|
1399
|
+
let i = A(), { labels: a } = k(), o = a.products, [c, l] = h(e), [u, d] = h(e ? q(e) : ce), [f, p] = h({}), [m, g] = h(!1), y = (e, t) => {
|
|
1400
|
+
p(t);
|
|
1401
|
+
let n = de(t);
|
|
1402
|
+
n && e.elements.namedItem(n)?.focus();
|
|
1403
|
+
}, b = M(async (e) => {
|
|
1404
|
+
let t = pe(u, o, c?.currency);
|
|
1405
|
+
if (!t.ok) y(e, t.errors);
|
|
1406
|
+
else try {
|
|
1407
|
+
if (!c) return await i.createProduct(t.input);
|
|
1408
|
+
let e = he(c, t.input);
|
|
1409
|
+
return Object.keys(e).length === 0 ? c : await i.updateProduct(c.id, e);
|
|
1410
|
+
} catch (t) {
|
|
1411
|
+
if (!(t instanceof s)) throw t;
|
|
1412
|
+
y(e, ue(t.issues));
|
|
1413
|
+
return;
|
|
1414
|
+
}
|
|
1415
|
+
}), x = (e, t) => {
|
|
1416
|
+
d((n) => ({
|
|
1417
|
+
...n,
|
|
1418
|
+
[e]: t
|
|
1419
|
+
})), p((t) => ({
|
|
1420
|
+
...t,
|
|
1421
|
+
[e]: void 0
|
|
1422
|
+
}));
|
|
1423
|
+
}, S = async (e) => {
|
|
1424
|
+
e.preventDefault(), g(!1), p({}), b.reset();
|
|
1425
|
+
let n = await b.run(e.currentTarget);
|
|
1426
|
+
n && (l(n), d(q(n)), g(!0), t?.(n));
|
|
1427
|
+
}, C = e ? n ?? /* @__PURE__ */ _(xe, {
|
|
1428
|
+
productId: e.id,
|
|
1429
|
+
images: e.images
|
|
1430
|
+
}) : null, w = {
|
|
1431
|
+
form: u,
|
|
1432
|
+
errors: f,
|
|
1433
|
+
labels: o,
|
|
1434
|
+
statusLabels: a.statuses,
|
|
1435
|
+
categories: r,
|
|
1436
|
+
onChange: x
|
|
1437
|
+
};
|
|
1438
|
+
return /* @__PURE__ */ v("form", {
|
|
1439
|
+
noValidate: !0,
|
|
1440
|
+
className: "sfa-form",
|
|
1441
|
+
onSubmit: S,
|
|
1442
|
+
children: [
|
|
1443
|
+
/* @__PURE__ */ _("h1", { children: e ? o.editTitle : o.createTitle }),
|
|
1444
|
+
/* @__PURE__ */ _(H, { error: b.error }),
|
|
1445
|
+
/* @__PURE__ */ _(Ce, { ...w }),
|
|
1446
|
+
/* @__PURE__ */ _(Te, { ...w }),
|
|
1447
|
+
C ? /* @__PURE__ */ _("section", {
|
|
1448
|
+
"data-slot": "images",
|
|
1449
|
+
className: "sfa-form__images",
|
|
1450
|
+
children: C
|
|
1451
|
+
}) : null,
|
|
1452
|
+
/* @__PURE__ */ _("button", {
|
|
1453
|
+
type: "submit",
|
|
1454
|
+
className: "sfa-btn sfa-btn--primary",
|
|
1455
|
+
disabled: b.pending,
|
|
1456
|
+
children: a.save
|
|
1457
|
+
}),
|
|
1458
|
+
m ? /* @__PURE__ */ _(z, {
|
|
1459
|
+
variant: "success",
|
|
1460
|
+
toast: !0,
|
|
1461
|
+
onDismiss: () => g(!1),
|
|
1462
|
+
children: o.saved
|
|
1463
|
+
}) : null
|
|
1464
|
+
]
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1467
|
+
// src/lib/use-order-pages.ts
|
|
1468
|
+
function ke(e) {
|
|
1469
|
+
let t = A(), n = j(["admin-orders", e], () => t.listOrders(e)), [r, i] = h(null), a = M(async (n, r) => {
|
|
1470
|
+
let a = await t.listOrders({
|
|
1471
|
+
...e,
|
|
1472
|
+
cursor: n
|
|
1473
|
+
});
|
|
1474
|
+
i((e) => ({
|
|
1475
|
+
base: r,
|
|
1476
|
+
items: [...e?.base === r ? e.items : [], ...a.items],
|
|
1477
|
+
nextCursor: a.nextCursor
|
|
1478
|
+
}));
|
|
1479
|
+
}), o = n.data, s = r && r.base === o ? r : null, c = s ? s.nextCursor : o?.nextCursor ?? null;
|
|
1480
|
+
return {
|
|
1481
|
+
items: [...o?.items ?? [], ...s?.items ?? []],
|
|
1482
|
+
loading: n.loading,
|
|
1483
|
+
error: n.error ?? a.error,
|
|
1484
|
+
hasMore: !n.loading && c !== null,
|
|
1485
|
+
loadingMore: a.pending,
|
|
1486
|
+
loadMore: () => {
|
|
1487
|
+
o && c && a.run(c, o);
|
|
1488
|
+
}
|
|
1489
|
+
};
|
|
1490
|
+
}
|
|
1491
|
+
// src/views/orders/admin-order-list.tsx
|
|
1492
|
+
var Ae = [
|
|
1493
|
+
"paid",
|
|
1494
|
+
"shipped",
|
|
1495
|
+
"needs_attention",
|
|
1496
|
+
"pending_refund",
|
|
1497
|
+
"all"
|
|
1498
|
+
];
|
|
1499
|
+
function je(e) {
|
|
1500
|
+
return e === "pending_refund" ? { hasPendingRefund: !0 } : e === "all" ? {} : { status: e };
|
|
1501
|
+
}
|
|
1502
|
+
function Me() {
|
|
1503
|
+
let { labels: e, locale: t, hrefs: n, renderLink: r } = k(), i = e.orders, [a, o] = h("paid"), [s, c] = h(""), l = re(s.trim(), 300), u = ke({
|
|
1504
|
+
...je(a),
|
|
1505
|
+
...l ? { q: l } : {}
|
|
1506
|
+
}), d = new Intl.DateTimeFormat(t), f = [
|
|
1507
|
+
{
|
|
1508
|
+
key: "order",
|
|
1509
|
+
header: i.columns.order,
|
|
1510
|
+
render: (e) => r({
|
|
1511
|
+
href: n.order(e.id),
|
|
1512
|
+
children: e.id,
|
|
1513
|
+
className: "sfa-link--tap"
|
|
1514
|
+
})
|
|
1515
|
+
},
|
|
1516
|
+
{
|
|
1517
|
+
key: "status",
|
|
1518
|
+
header: i.columns.status,
|
|
1519
|
+
render: (e) => /* @__PURE__ */ _(F, { status: e.status })
|
|
1520
|
+
},
|
|
1521
|
+
{
|
|
1522
|
+
key: "email",
|
|
1523
|
+
header: i.columns.email,
|
|
1524
|
+
render: (e) => e.email ?? i.noEmail
|
|
1525
|
+
},
|
|
1526
|
+
{
|
|
1527
|
+
key: "items",
|
|
1528
|
+
header: i.columns.items,
|
|
1529
|
+
render: (e) => e.itemCount
|
|
1530
|
+
},
|
|
1531
|
+
{
|
|
1532
|
+
key: "total",
|
|
1533
|
+
header: i.columns.total,
|
|
1534
|
+
render: (e) => /* @__PURE__ */ _(I, {
|
|
1535
|
+
cents: e.totalCents,
|
|
1536
|
+
currency: e.currency
|
|
1537
|
+
})
|
|
1538
|
+
},
|
|
1539
|
+
{
|
|
1540
|
+
key: "date",
|
|
1541
|
+
header: i.columns.date,
|
|
1542
|
+
render: (e) => d.format(new Date(e.createdAt))
|
|
1543
|
+
}
|
|
1544
|
+
];
|
|
1545
|
+
return /* @__PURE__ */ v("section", {
|
|
1546
|
+
className: "sfa-orders",
|
|
1547
|
+
children: [
|
|
1548
|
+
/* @__PURE__ */ _("h1", { children: i.title }),
|
|
1549
|
+
/* @__PURE__ */ v("div", {
|
|
1550
|
+
className: "sfa-orders__toolbar",
|
|
1551
|
+
children: [/* @__PURE__ */ _("div", {
|
|
1552
|
+
role: "group",
|
|
1553
|
+
"aria-label": i.columns.status,
|
|
1554
|
+
className: "sfa-filter-group",
|
|
1555
|
+
children: Ae.map((e) => /* @__PURE__ */ _("button", {
|
|
1556
|
+
type: "button",
|
|
1557
|
+
className: "sfa-btn sfa-filter",
|
|
1558
|
+
"aria-pressed": a === e,
|
|
1559
|
+
onClick: () => o(e),
|
|
1560
|
+
children: i.tabs[e]
|
|
1561
|
+
}, e))
|
|
1562
|
+
}), /* @__PURE__ */ _("input", {
|
|
1563
|
+
type: "search",
|
|
1564
|
+
"aria-label": i.searchLabel,
|
|
1565
|
+
placeholder: i.searchPlaceholder,
|
|
1566
|
+
value: s,
|
|
1567
|
+
onChange: (e) => c(e.target.value)
|
|
1568
|
+
})]
|
|
1569
|
+
}),
|
|
1570
|
+
/* @__PURE__ */ _(H, { error: u.error }),
|
|
1571
|
+
u.loading ? /* @__PURE__ */ _("p", { children: e.loading }) : u.items.length === 0 ? /* @__PURE__ */ _("p", {
|
|
1572
|
+
className: "sfa-empty",
|
|
1573
|
+
children: l ? i.noMatches : i.empty[a]
|
|
1574
|
+
}) : /* @__PURE__ */ _(P, {
|
|
1575
|
+
columns: f,
|
|
1576
|
+
rows: u.items,
|
|
1577
|
+
rowKey: (e) => e.id
|
|
1578
|
+
}),
|
|
1579
|
+
u.hasMore ? /* @__PURE__ */ _("button", {
|
|
1580
|
+
type: "button",
|
|
1581
|
+
className: "sfa-btn sfa-orders__more",
|
|
1582
|
+
disabled: u.loadingMore,
|
|
1583
|
+
onClick: u.loadMore,
|
|
1584
|
+
children: i.loadMore
|
|
1585
|
+
}) : null
|
|
1586
|
+
]
|
|
1587
|
+
});
|
|
1588
|
+
}
|
|
1589
|
+
// src/lib/refund-rules.ts
|
|
1590
|
+
function Ne(e) {
|
|
1591
|
+
return e.refunds.filter((e) => e.status === "pending").reduce((e, t) => e + t.amountCents, 0);
|
|
1592
|
+
}
|
|
1593
|
+
function Z(e) {
|
|
1594
|
+
return e.totalCents - e.refundedCents - Ne(e);
|
|
1595
|
+
}
|
|
1596
|
+
function Pe(e) {
|
|
1597
|
+
return e.refunds.some((e) => e.status === "pending");
|
|
1598
|
+
}
|
|
1599
|
+
function Fe(e, t) {
|
|
1600
|
+
return e.status !== "needs_attention" && t !== null && t === Z(e);
|
|
1601
|
+
}
|
|
1602
|
+
function Ie(e) {
|
|
1603
|
+
return e.status === "paid" || e.status === "shipped";
|
|
1604
|
+
}
|
|
1605
|
+
function Le(e) {
|
|
1606
|
+
return (Ie(e) || e.status === "needs_attention") && Z(e) > 0;
|
|
1607
|
+
}
|
|
1608
|
+
// src/views/orders/refund-dialog.tsx
|
|
1609
|
+
function Re({ order: e, onClose: t, onDone: i }) {
|
|
1610
|
+
let a = A(), o = k().labels.orders.actions, s = m(crypto.randomUUID()), c = Z(e), [l, u] = h(G(c)), [d, f] = h(""), [p, g] = h(!1), [y, b] = h(!1), x = M(a.refundOrder), S = W(l), C = S !== null && S > 0 && S <= c, w = Fe(e, S), T = x.error instanceof n || x.error instanceof r;
|
|
1611
|
+
return /* @__PURE__ */ v(R, {
|
|
1612
|
+
open: !0,
|
|
1613
|
+
title: o.refundTitle,
|
|
1614
|
+
confirmLabel: T ? o.refundRetry : o.refundSubmit,
|
|
1615
|
+
destructive: !0,
|
|
1616
|
+
pending: x.pending,
|
|
1617
|
+
onConfirm: async () => {
|
|
1618
|
+
C ? (b(!1), await x.run(e.id, {
|
|
1619
|
+
amountCents: S,
|
|
1620
|
+
reason: d.trim() || void 0,
|
|
1621
|
+
restock: p && w
|
|
1622
|
+
}, { idempotencyKey: s.current }) && i(o.refundDone)) : b(!0);
|
|
1623
|
+
},
|
|
1624
|
+
onCancel: t,
|
|
1625
|
+
children: [
|
|
1626
|
+
Pe(e) ? /* @__PURE__ */ _(z, {
|
|
1627
|
+
variant: "warning",
|
|
1628
|
+
children: o.refundPending
|
|
1629
|
+
}) : null,
|
|
1630
|
+
/* @__PURE__ */ v("div", {
|
|
1631
|
+
className: "sfa-field",
|
|
1632
|
+
children: [
|
|
1633
|
+
/* @__PURE__ */ _("label", {
|
|
1634
|
+
htmlFor: "sfa-refund-amount",
|
|
1635
|
+
className: "sfa-field__label",
|
|
1636
|
+
children: o.refundAmount
|
|
1637
|
+
}),
|
|
1638
|
+
/* @__PURE__ */ _("input", {
|
|
1639
|
+
id: "sfa-refund-amount",
|
|
1640
|
+
inputMode: "decimal",
|
|
1641
|
+
value: l,
|
|
1642
|
+
disabled: T,
|
|
1643
|
+
"aria-invalid": y && !C,
|
|
1644
|
+
onChange: (e) => u(e.target.value)
|
|
1645
|
+
}),
|
|
1646
|
+
y && !C ? /* @__PURE__ */ _("p", {
|
|
1647
|
+
className: "sfa-field__error",
|
|
1648
|
+
children: o.refundAmountInvalid
|
|
1649
|
+
}) : null
|
|
1650
|
+
]
|
|
1651
|
+
}),
|
|
1652
|
+
/* @__PURE__ */ v("div", {
|
|
1653
|
+
className: "sfa-field",
|
|
1654
|
+
children: [/* @__PURE__ */ _("label", {
|
|
1655
|
+
htmlFor: "sfa-refund-reason",
|
|
1656
|
+
className: "sfa-field__label",
|
|
1657
|
+
children: o.refundReason
|
|
1658
|
+
}), /* @__PURE__ */ _("textarea", {
|
|
1659
|
+
id: "sfa-refund-reason",
|
|
1660
|
+
maxLength: 500,
|
|
1661
|
+
value: d,
|
|
1662
|
+
disabled: T,
|
|
1663
|
+
onChange: (e) => f(e.target.value)
|
|
1664
|
+
})]
|
|
1665
|
+
}),
|
|
1666
|
+
w ? /* @__PURE__ */ v("div", {
|
|
1667
|
+
className: "sfa-field",
|
|
1668
|
+
children: [/* @__PURE__ */ v("label", { children: [
|
|
1669
|
+
/* @__PURE__ */ _("input", {
|
|
1670
|
+
type: "checkbox",
|
|
1671
|
+
checked: p,
|
|
1672
|
+
disabled: T,
|
|
1673
|
+
onChange: (e) => g(e.target.checked)
|
|
1674
|
+
}),
|
|
1675
|
+
" ",
|
|
1676
|
+
o.restock
|
|
1677
|
+
] }), /* @__PURE__ */ _("p", {
|
|
1678
|
+
className: "sfa-field__help",
|
|
1679
|
+
children: o.restockWarning
|
|
1680
|
+
})]
|
|
1681
|
+
}) : null,
|
|
1682
|
+
x.error instanceof r ? /* @__PURE__ */ _(z, {
|
|
1683
|
+
variant: "warning",
|
|
1684
|
+
children: o.refundUnknown
|
|
1685
|
+
}) : x.error instanceof n ? /* @__PURE__ */ _(z, {
|
|
1686
|
+
variant: "warning",
|
|
1687
|
+
children: o.refundGateway
|
|
1688
|
+
}) : /* @__PURE__ */ _(H, { error: x.error })
|
|
1689
|
+
]
|
|
1690
|
+
});
|
|
1691
|
+
}
|
|
1692
|
+
// src/views/orders/resolve-button.tsx
|
|
1693
|
+
function ze({ order: e, onDone: t }) {
|
|
1694
|
+
let n = A(), { labels: r, hrefs: i, renderLink: a } = k(), o = r.orders.actions, s = M(n.resolveOrder), l = async () => {
|
|
1695
|
+
await s.run(e.id) && t(o.resolved);
|
|
1696
|
+
}, u = s.error instanceof c ? s.error : null, d = new Map(e.items.map((e) => [e.productId, e.name]));
|
|
1697
|
+
return /* @__PURE__ */ v("div", {
|
|
1698
|
+
className: "sfa-order__action",
|
|
1699
|
+
children: [
|
|
1700
|
+
/* @__PURE__ */ _("p", { children: o.resolveHelp }),
|
|
1701
|
+
u ? /* @__PURE__ */ v(z, {
|
|
1702
|
+
variant: "error",
|
|
1703
|
+
children: [r.errors.insufficientStock, /* @__PURE__ */ _("ul", { children: u.productIds.map((e) => /* @__PURE__ */ _("li", { children: a({
|
|
1704
|
+
href: i.product(e),
|
|
1705
|
+
children: `${o.restockThenResolve}: ${d.get(e) ?? e}`,
|
|
1706
|
+
className: "sfa-link--tap"
|
|
1707
|
+
}) }, e)) })]
|
|
1708
|
+
}) : /* @__PURE__ */ _(H, { error: s.error }),
|
|
1709
|
+
/* @__PURE__ */ _("button", {
|
|
1710
|
+
type: "button",
|
|
1711
|
+
className: "sfa-btn sfa-btn--primary",
|
|
1712
|
+
disabled: s.pending,
|
|
1713
|
+
onClick: l,
|
|
1714
|
+
children: o.resolve
|
|
1715
|
+
})
|
|
1716
|
+
]
|
|
1717
|
+
});
|
|
1718
|
+
}
|
|
1719
|
+
// src/views/orders/ship-form.tsx
|
|
1720
|
+
function Be(e) {
|
|
1721
|
+
try {
|
|
1722
|
+
let { protocol: t } = new URL(e);
|
|
1723
|
+
return t === "http:" || t === "https:";
|
|
1724
|
+
} catch {
|
|
1725
|
+
return !1;
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
function Ve({ order: e, onDone: t }) {
|
|
1729
|
+
let n = A(), r = k().labels.orders.actions, i = e.fulfillment, [a, o] = h(i?.carrier ?? ""), [s, c] = h(i?.trackingNumber ?? ""), [l, u] = h(i?.trackingUrl ?? ""), [d, f] = h(!1), p = M(n.shipOrder), m = e.status === "shipped";
|
|
1730
|
+
return /* @__PURE__ */ v("form", {
|
|
1731
|
+
className: "sfa-order__action",
|
|
1732
|
+
onSubmit: async (n) => {
|
|
1733
|
+
n.preventDefault();
|
|
1734
|
+
let i = l.trim();
|
|
1735
|
+
i && !Be(i) ? f(!0) : (f(!1), await p.run(e.id, {
|
|
1736
|
+
carrier: a.trim() || void 0,
|
|
1737
|
+
trackingNumber: s.trim() || void 0,
|
|
1738
|
+
trackingUrl: i || void 0
|
|
1739
|
+
}) && t(r.shipped));
|
|
1740
|
+
},
|
|
1741
|
+
children: [
|
|
1742
|
+
/* @__PURE__ */ _("h3", { children: r.shipHeading }),
|
|
1743
|
+
/* @__PURE__ */ v("div", {
|
|
1744
|
+
className: "sfa-field",
|
|
1745
|
+
children: [/* @__PURE__ */ _("label", {
|
|
1746
|
+
htmlFor: "sfa-ship-carrier",
|
|
1747
|
+
className: "sfa-field__label",
|
|
1748
|
+
children: r.carrier
|
|
1749
|
+
}), /* @__PURE__ */ _("input", {
|
|
1750
|
+
id: "sfa-ship-carrier",
|
|
1751
|
+
value: a,
|
|
1752
|
+
onChange: (e) => o(e.target.value)
|
|
1753
|
+
})]
|
|
1754
|
+
}),
|
|
1755
|
+
/* @__PURE__ */ v("div", {
|
|
1756
|
+
className: "sfa-field",
|
|
1757
|
+
children: [/* @__PURE__ */ _("label", {
|
|
1758
|
+
htmlFor: "sfa-ship-number",
|
|
1759
|
+
className: "sfa-field__label",
|
|
1760
|
+
children: r.trackingNumber
|
|
1761
|
+
}), /* @__PURE__ */ _("input", {
|
|
1762
|
+
id: "sfa-ship-number",
|
|
1763
|
+
value: s,
|
|
1764
|
+
onChange: (e) => c(e.target.value)
|
|
1765
|
+
})]
|
|
1766
|
+
}),
|
|
1767
|
+
/* @__PURE__ */ v("div", {
|
|
1768
|
+
className: "sfa-field",
|
|
1769
|
+
children: [
|
|
1770
|
+
/* @__PURE__ */ _("label", {
|
|
1771
|
+
htmlFor: "sfa-ship-url",
|
|
1772
|
+
className: "sfa-field__label",
|
|
1773
|
+
children: r.trackingUrl
|
|
1774
|
+
}),
|
|
1775
|
+
/* @__PURE__ */ _("input", {
|
|
1776
|
+
id: "sfa-ship-url",
|
|
1777
|
+
value: l,
|
|
1778
|
+
"aria-invalid": d,
|
|
1779
|
+
"aria-describedby": d ? "sfa-ship-url-error" : void 0,
|
|
1780
|
+
onChange: (e) => u(e.target.value)
|
|
1781
|
+
}),
|
|
1782
|
+
d ? /* @__PURE__ */ _("p", {
|
|
1783
|
+
id: "sfa-ship-url-error",
|
|
1784
|
+
className: "sfa-field__error",
|
|
1785
|
+
children: r.trackingUrlInvalid
|
|
1786
|
+
}) : null
|
|
1787
|
+
]
|
|
1788
|
+
}),
|
|
1789
|
+
/* @__PURE__ */ _(H, { error: p.error }),
|
|
1790
|
+
/* @__PURE__ */ _("button", {
|
|
1791
|
+
type: "submit",
|
|
1792
|
+
className: "sfa-btn sfa-btn--primary",
|
|
1793
|
+
disabled: p.pending,
|
|
1794
|
+
children: m ? r.reship : r.ship
|
|
1795
|
+
})
|
|
1796
|
+
]
|
|
1797
|
+
});
|
|
1798
|
+
}
|
|
1799
|
+
// src/views/orders/order-actions.tsx
|
|
1800
|
+
function He({ order: e, reload: t }) {
|
|
1801
|
+
let n = k().labels.orders.actions, [r, i] = h(!1), [a, o] = h(null), s = (e) => {
|
|
1802
|
+
i(!1), o(e), t();
|
|
1803
|
+
};
|
|
1804
|
+
return /* @__PURE__ */ v("div", {
|
|
1805
|
+
className: "sfa-order__actions",
|
|
1806
|
+
children: [
|
|
1807
|
+
a ? /* @__PURE__ */ _(z, {
|
|
1808
|
+
variant: "success",
|
|
1809
|
+
onDismiss: () => o(null),
|
|
1810
|
+
children: a
|
|
1811
|
+
}) : null,
|
|
1812
|
+
Ie(e) ? /* @__PURE__ */ _(Ve, {
|
|
1813
|
+
order: e,
|
|
1814
|
+
onDone: s
|
|
1815
|
+
}) : null,
|
|
1816
|
+
e.status === "needs_attention" ? /* @__PURE__ */ _(ze, {
|
|
1817
|
+
order: e,
|
|
1818
|
+
onDone: s
|
|
1819
|
+
}) : null,
|
|
1820
|
+
Le(e) ? /* @__PURE__ */ _("button", {
|
|
1821
|
+
type: "button",
|
|
1822
|
+
className: "sfa-btn sfa-btn--danger",
|
|
1823
|
+
onClick: () => i(!0),
|
|
1824
|
+
children: n.refund
|
|
1825
|
+
}) : null,
|
|
1826
|
+
r ? /* @__PURE__ */ _(Re, {
|
|
1827
|
+
order: e,
|
|
1828
|
+
onClose: () => {
|
|
1829
|
+
i(!1), t();
|
|
1830
|
+
},
|
|
1831
|
+
onDone: s
|
|
1832
|
+
}) : null
|
|
1833
|
+
]
|
|
1834
|
+
});
|
|
1835
|
+
}
|
|
1836
|
+
// src/views/orders/order-fulfillment.tsx
|
|
1837
|
+
function Ue({ order: e }) {
|
|
1838
|
+
let { labels: t, locale: n, renderLink: r } = k(), i = t.orders, a = e.fulfillment;
|
|
1839
|
+
return /* @__PURE__ */ v("section", {
|
|
1840
|
+
className: "sfa-order__section",
|
|
1841
|
+
children: [/* @__PURE__ */ _("h2", { children: i.fulfillment }), a ? /* @__PURE__ */ v("dl", { children: [
|
|
1842
|
+
/* @__PURE__ */ _("dt", { children: i.shippedOn }),
|
|
1843
|
+
/* @__PURE__ */ _("dd", { children: new Intl.DateTimeFormat(n).format(new Date(a.shippedAt)) }),
|
|
1844
|
+
a.carrier ? /* @__PURE__ */ v(g, { children: [/* @__PURE__ */ _("dt", { children: i.carrier }), /* @__PURE__ */ _("dd", { children: a.carrier })] }) : null,
|
|
1845
|
+
a.trackingNumber ? /* @__PURE__ */ v(g, { children: [/* @__PURE__ */ _("dt", { children: i.tracking }), /* @__PURE__ */ _("dd", { children: a.trackingNumber })] }) : null,
|
|
1846
|
+
a.trackingUrl ? /* @__PURE__ */ _("dd", { children: r({
|
|
1847
|
+
href: a.trackingUrl,
|
|
1848
|
+
children: i.trackShipment,
|
|
1849
|
+
className: "sfa-link--tap"
|
|
1850
|
+
}) }) : null
|
|
1851
|
+
] }) : /* @__PURE__ */ _("p", { children: i.notShipped })]
|
|
1852
|
+
});
|
|
1853
|
+
}
|
|
1854
|
+
// src/views/orders/order-items.tsx
|
|
1855
|
+
function We({ order: e }) {
|
|
1856
|
+
let { labels: t } = k(), n = t.orders, { currency: r } = e, i = [
|
|
1857
|
+
{
|
|
1858
|
+
key: "name",
|
|
1859
|
+
header: n.itemColumns.name,
|
|
1860
|
+
render: (e) => e.name
|
|
1861
|
+
},
|
|
1862
|
+
{
|
|
1863
|
+
key: "price",
|
|
1864
|
+
header: n.itemColumns.price,
|
|
1865
|
+
render: (e) => /* @__PURE__ */ _(I, {
|
|
1866
|
+
cents: e.priceCents,
|
|
1867
|
+
currency: r
|
|
1868
|
+
})
|
|
1869
|
+
},
|
|
1870
|
+
{
|
|
1871
|
+
key: "quantity",
|
|
1872
|
+
header: n.itemColumns.quantity,
|
|
1873
|
+
render: (e) => e.quantity
|
|
1874
|
+
},
|
|
1875
|
+
{
|
|
1876
|
+
key: "line",
|
|
1877
|
+
header: n.itemColumns.line,
|
|
1878
|
+
render: (e) => /* @__PURE__ */ _(I, {
|
|
1879
|
+
cents: e.priceCents * e.quantity,
|
|
1880
|
+
currency: r
|
|
1881
|
+
})
|
|
1882
|
+
}
|
|
1883
|
+
];
|
|
1884
|
+
return /* @__PURE__ */ v("section", {
|
|
1885
|
+
className: "sfa-order__section",
|
|
1886
|
+
children: [
|
|
1887
|
+
/* @__PURE__ */ _("h2", { children: n.itemsHeading }),
|
|
1888
|
+
/* @__PURE__ */ _(P, {
|
|
1889
|
+
columns: i,
|
|
1890
|
+
rows: e.items,
|
|
1891
|
+
rowKey: (e) => e.productId
|
|
1892
|
+
}),
|
|
1893
|
+
/* @__PURE__ */ v("dl", {
|
|
1894
|
+
className: "sfa-order__totals",
|
|
1895
|
+
children: [
|
|
1896
|
+
/* @__PURE__ */ _("dt", { children: n.subtotal }),
|
|
1897
|
+
/* @__PURE__ */ _("dd", { children: /* @__PURE__ */ _(I, {
|
|
1898
|
+
cents: e.subtotalCents,
|
|
1899
|
+
currency: r
|
|
1900
|
+
}) }),
|
|
1901
|
+
/* @__PURE__ */ _("dt", { children: e.shippingLabel ?? n.shipping }),
|
|
1902
|
+
/* @__PURE__ */ _("dd", { children: /* @__PURE__ */ _(I, {
|
|
1903
|
+
cents: e.shippingCents,
|
|
1904
|
+
currency: r
|
|
1905
|
+
}) }),
|
|
1906
|
+
/* @__PURE__ */ _("dt", { children: n.total }),
|
|
1907
|
+
/* @__PURE__ */ _("dd", { children: /* @__PURE__ */ _(I, {
|
|
1908
|
+
cents: e.totalCents,
|
|
1909
|
+
currency: r
|
|
1910
|
+
}) })
|
|
1911
|
+
]
|
|
1912
|
+
})
|
|
1913
|
+
]
|
|
1914
|
+
});
|
|
1915
|
+
}
|
|
1916
|
+
// src/views/orders/order-refunds.tsx
|
|
1917
|
+
function Ge({ order: e }) {
|
|
1918
|
+
let { labels: t, locale: n } = k(), r = t.orders, { currency: i } = e, a = new Intl.DateTimeFormat(n), o = [
|
|
1919
|
+
{
|
|
1920
|
+
key: "amount",
|
|
1921
|
+
header: r.refundColumns.amount,
|
|
1922
|
+
render: (e) => /* @__PURE__ */ _(I, {
|
|
1923
|
+
cents: e.amountCents,
|
|
1924
|
+
currency: i
|
|
1925
|
+
})
|
|
1926
|
+
},
|
|
1927
|
+
{
|
|
1928
|
+
key: "reason",
|
|
1929
|
+
header: r.refundColumns.reason,
|
|
1930
|
+
render: (e) => e.reason ?? "—"
|
|
1931
|
+
},
|
|
1932
|
+
{
|
|
1933
|
+
key: "source",
|
|
1934
|
+
header: r.refundColumns.source,
|
|
1935
|
+
render: (e) => r.refundSources[e.source]
|
|
1936
|
+
},
|
|
1937
|
+
{
|
|
1938
|
+
key: "status",
|
|
1939
|
+
header: r.refundColumns.status,
|
|
1940
|
+
render: (e) => /* @__PURE__ */ _("span", {
|
|
1941
|
+
className: `sfa-badge sfa-badge--refund-${e.status}`,
|
|
1942
|
+
"data-refund-status": e.status,
|
|
1943
|
+
children: r.refundStatuses[e.status]
|
|
1944
|
+
})
|
|
1945
|
+
},
|
|
1946
|
+
{
|
|
1947
|
+
key: "restocked",
|
|
1948
|
+
header: r.refundColumns.restocked,
|
|
1949
|
+
render: (e) => e.restocked ? r.yes : r.no
|
|
1950
|
+
},
|
|
1951
|
+
{
|
|
1952
|
+
key: "date",
|
|
1953
|
+
header: r.refundColumns.date,
|
|
1954
|
+
render: (e) => a.format(new Date(e.createdAt))
|
|
1955
|
+
}
|
|
1956
|
+
], s = e.totalCents - e.refundedCents;
|
|
1957
|
+
return /* @__PURE__ */ v("section", {
|
|
1958
|
+
className: "sfa-order__section",
|
|
1959
|
+
children: [/* @__PURE__ */ _("h2", { children: r.refunds }), e.refunds.length === 0 ? /* @__PURE__ */ _("p", { children: r.noRefunds }) : /* @__PURE__ */ v(g, { children: [/* @__PURE__ */ _(P, {
|
|
1960
|
+
columns: o,
|
|
1961
|
+
rows: e.refunds,
|
|
1962
|
+
rowKey: (e) => e.id
|
|
1963
|
+
}), /* @__PURE__ */ v("dl", {
|
|
1964
|
+
className: "sfa-order__totals",
|
|
1965
|
+
children: [
|
|
1966
|
+
/* @__PURE__ */ _("dt", { children: r.refunded }),
|
|
1967
|
+
/* @__PURE__ */ _("dd", { children: /* @__PURE__ */ _(I, {
|
|
1968
|
+
cents: e.refundedCents,
|
|
1969
|
+
currency: i
|
|
1970
|
+
}) }),
|
|
1971
|
+
/* @__PURE__ */ _("dt", { children: r.remaining }),
|
|
1972
|
+
/* @__PURE__ */ _("dd", { children: /* @__PURE__ */ _(I, {
|
|
1973
|
+
cents: s,
|
|
1974
|
+
currency: i
|
|
1975
|
+
}) })
|
|
1976
|
+
]
|
|
1977
|
+
})] })]
|
|
1978
|
+
});
|
|
1979
|
+
}
|
|
1980
|
+
// src/views/orders/admin-order-detail.tsx
|
|
1981
|
+
function Ke(e) {
|
|
1982
|
+
let t = e.shippingAddress;
|
|
1983
|
+
if (!t) return [];
|
|
1984
|
+
let n = [
|
|
1985
|
+
t.city,
|
|
1986
|
+
t.state,
|
|
1987
|
+
t.postalCode
|
|
1988
|
+
].filter(Boolean).join(" ");
|
|
1989
|
+
return [
|
|
1990
|
+
t.name,
|
|
1991
|
+
t.line1,
|
|
1992
|
+
t.line2,
|
|
1993
|
+
n,
|
|
1994
|
+
t.country
|
|
1995
|
+
].filter((e) => !!e);
|
|
1996
|
+
}
|
|
1997
|
+
function qe({ orderId: e, actions: t }) {
|
|
1998
|
+
let n = A(), { labels: r, locale: i, hrefs: a, renderLink: o } = k(), s = r.orders, c = j(["admin-order", e], () => n.getOrder(e));
|
|
1999
|
+
if (c.error) return /* @__PURE__ */ _(H, { error: c.error });
|
|
2000
|
+
let l = c.data;
|
|
2001
|
+
if (!l) return /* @__PURE__ */ _("p", { children: r.loading });
|
|
2002
|
+
let u = Ke(l);
|
|
2003
|
+
return /* @__PURE__ */ v("article", {
|
|
2004
|
+
className: "sfa-order",
|
|
2005
|
+
children: [
|
|
2006
|
+
o({
|
|
2007
|
+
href: a.orders,
|
|
2008
|
+
children: s.back,
|
|
2009
|
+
className: "sfa-link--tap"
|
|
2010
|
+
}),
|
|
2011
|
+
/* @__PURE__ */ v("header", {
|
|
2012
|
+
className: "sfa-order__header",
|
|
2013
|
+
children: [
|
|
2014
|
+
/* @__PURE__ */ v("h1", { children: [
|
|
2015
|
+
s.detailTitle,
|
|
2016
|
+
" ",
|
|
2017
|
+
l.id
|
|
2018
|
+
] }),
|
|
2019
|
+
/* @__PURE__ */ _(F, { status: l.status }),
|
|
2020
|
+
/* @__PURE__ */ v("span", { children: [
|
|
2021
|
+
s.placed,
|
|
2022
|
+
" ",
|
|
2023
|
+
new Intl.DateTimeFormat(i).format(new Date(l.createdAt))
|
|
2024
|
+
] }),
|
|
2025
|
+
/* @__PURE__ */ _(I, {
|
|
2026
|
+
cents: l.totalCents,
|
|
2027
|
+
currency: l.currency
|
|
2028
|
+
})
|
|
2029
|
+
]
|
|
2030
|
+
}),
|
|
2031
|
+
/* @__PURE__ */ v("section", {
|
|
2032
|
+
className: "sfa-order__section",
|
|
2033
|
+
children: [/* @__PURE__ */ _("h2", { children: s.buyer }), /* @__PURE__ */ _("p", { children: l.email ?? r.orders.noEmail })]
|
|
2034
|
+
}),
|
|
2035
|
+
/* @__PURE__ */ _(We, { order: l }),
|
|
2036
|
+
/* @__PURE__ */ v("section", {
|
|
2037
|
+
className: "sfa-order__section",
|
|
2038
|
+
children: [/* @__PURE__ */ _("h2", { children: s.shippingAddress }), u.length === 0 ? /* @__PURE__ */ _("p", { children: s.noAddress }) : /* @__PURE__ */ _("address", {
|
|
2039
|
+
className: "sfa-order__address",
|
|
2040
|
+
children: u.map((e) => /* @__PURE__ */ _("div", { children: e }, e))
|
|
2041
|
+
})]
|
|
2042
|
+
}),
|
|
2043
|
+
/* @__PURE__ */ _(Ue, { order: l }),
|
|
2044
|
+
/* @__PURE__ */ _(Ge, { order: l }),
|
|
2045
|
+
/* @__PURE__ */ _("section", {
|
|
2046
|
+
className: "sfa-order__section",
|
|
2047
|
+
children: t ? t({
|
|
2048
|
+
order: l,
|
|
2049
|
+
reload: c.reload
|
|
2050
|
+
}) : /* @__PURE__ */ _(He, {
|
|
2051
|
+
order: l,
|
|
2052
|
+
reload: c.reload
|
|
2053
|
+
})
|
|
2054
|
+
})
|
|
2055
|
+
]
|
|
2056
|
+
});
|
|
2057
|
+
}
|
|
2058
|
+
// src/lib/shipping-rates.ts
|
|
2059
|
+
var Je = 0, Ye = () => `rate-${++Je}`;
|
|
2060
|
+
function Xe(e) {
|
|
2061
|
+
return [...e].sort((e, t) => e.sort - t.sort).map((e) => ({
|
|
2062
|
+
key: Ye(),
|
|
2063
|
+
label: e.label,
|
|
2064
|
+
amount: G(e.amountCents),
|
|
2065
|
+
currency: e.currency,
|
|
2066
|
+
minDays: e.minDays == null ? "" : String(e.minDays),
|
|
2067
|
+
maxDays: e.maxDays == null ? "" : String(e.maxDays),
|
|
2068
|
+
active: e.active
|
|
2069
|
+
}));
|
|
2070
|
+
}
|
|
2071
|
+
function Ze(e, t) {
|
|
2072
|
+
return {
|
|
2073
|
+
key: Ye(),
|
|
2074
|
+
label: t,
|
|
2075
|
+
amount: "",
|
|
2076
|
+
currency: e,
|
|
2077
|
+
minDays: "",
|
|
2078
|
+
maxDays: "",
|
|
2079
|
+
active: !0
|
|
2080
|
+
};
|
|
2081
|
+
}
|
|
2082
|
+
var Q = (e) => JSON.stringify(e.map(({ key: e, ...t }) => t));
|
|
2083
|
+
function $(e) {
|
|
2084
|
+
let t = e.trim();
|
|
2085
|
+
return t === "" ? null : /^\d+$/.test(t) ? Number(t) : void 0;
|
|
2086
|
+
}
|
|
2087
|
+
function Qe(e, t) {
|
|
2088
|
+
let n = {}, r = [], i = /* @__PURE__ */ new Map();
|
|
2089
|
+
if (e.forEach((e) => {
|
|
2090
|
+
let t = e.label.trim();
|
|
2091
|
+
i.set(t, (i.get(t) ?? 0) + 1);
|
|
2092
|
+
}), e.forEach((e, a) => {
|
|
2093
|
+
let o = {}, s = e.label.trim(), c = W(e.amount), l = $(e.minDays), u = $(e.maxDays);
|
|
2094
|
+
s === "" ? o.label = t.labelRequired : (i.get(s) ?? 0) > 1 && (o.label = t.labelDuplicate), /^[A-Z]{3}$/.test(e.currency) || (o.currency = t.currencyInvalid), c === null && (o.amount = t.amountInvalid), l === void 0 && (o.minDays = t.daysInvalid), u === void 0 && (o.maxDays = t.daysInvalid), typeof l == "number" && typeof u == "number" && l > u && (o.minDays = t.daysOrder), Object.keys(o).length > 0 && (n[e.key] = o), r.push({
|
|
2095
|
+
label: s,
|
|
2096
|
+
amountCents: c ?? 0,
|
|
2097
|
+
currency: e.currency,
|
|
2098
|
+
minDays: l ?? null,
|
|
2099
|
+
maxDays: u ?? null,
|
|
2100
|
+
active: e.active,
|
|
2101
|
+
sort: a
|
|
2102
|
+
});
|
|
2103
|
+
}), Object.keys(n).length === 0) {
|
|
2104
|
+
let i = b.safeParse(r);
|
|
2105
|
+
if (!i.success) for (let r of i.error.issues) {
|
|
2106
|
+
let i = typeof r.path[0] == "number" ? e[r.path[0]]?.key : void 0;
|
|
2107
|
+
i && (n[i] = { row: t.rowInvalid });
|
|
2108
|
+
}
|
|
2109
|
+
}
|
|
2110
|
+
let a = !e.some((e) => e.active);
|
|
2111
|
+
return {
|
|
2112
|
+
rates: r,
|
|
2113
|
+
rowErrors: n,
|
|
2114
|
+
noActive: a,
|
|
2115
|
+
valid: Object.keys(n).length === 0 && !a
|
|
2116
|
+
};
|
|
2117
|
+
}
|
|
2118
|
+
var $e = {
|
|
2119
|
+
label: "label",
|
|
2120
|
+
amountCents: "amount",
|
|
2121
|
+
currency: "currency",
|
|
2122
|
+
minDays: "minDays",
|
|
2123
|
+
maxDays: "maxDays"
|
|
2124
|
+
};
|
|
2125
|
+
function et(e, t, n) {
|
|
2126
|
+
let r = {};
|
|
2127
|
+
for (let i of e) {
|
|
2128
|
+
let e = i?.path ?? [], a = e.findIndex((e) => typeof e == "number"), o = a >= 0 ? t[e[a]]?.key : void 0;
|
|
2129
|
+
if (!o) continue;
|
|
2130
|
+
let s = e[e.length - 1], c = e.length - 1 > a && typeof s == "string" ? $e[s] : void 0;
|
|
2131
|
+
r[o] = {
|
|
2132
|
+
...r[o],
|
|
2133
|
+
[c ?? "row"]: n.rowInvalid
|
|
2134
|
+
};
|
|
2135
|
+
}
|
|
2136
|
+
return r;
|
|
2137
|
+
}
|
|
2138
|
+
// src/views/shipping/shipping-rate-row.tsx
|
|
2139
|
+
function tt({ draft: e, index: t, total: n, errors: r, disabled: i, labels: a, onChange: o, onMove: s, onRemove: c }) {
|
|
2140
|
+
let l = e.label.trim() || J(a.rowName, { n: String(t + 1) }), u = (t, n, a, s, c) => {
|
|
2141
|
+
let l = r[s], u = `${e.key}-${t}`;
|
|
2142
|
+
return /* @__PURE__ */ v("div", {
|
|
2143
|
+
className: "sfa-field",
|
|
2144
|
+
children: [
|
|
2145
|
+
/* @__PURE__ */ _("label", {
|
|
2146
|
+
className: "sfa-field__label",
|
|
2147
|
+
htmlFor: u,
|
|
2148
|
+
children: n
|
|
2149
|
+
}),
|
|
2150
|
+
/* @__PURE__ */ _("input", {
|
|
2151
|
+
id: u,
|
|
2152
|
+
value: a,
|
|
2153
|
+
inputMode: c,
|
|
2154
|
+
disabled: i,
|
|
2155
|
+
"aria-invalid": !!l,
|
|
2156
|
+
"aria-describedby": l ? `${u}-error` : void 0,
|
|
2157
|
+
onChange: (e) => o({ [s]: e.target.value })
|
|
2158
|
+
}),
|
|
2159
|
+
l ? /* @__PURE__ */ _("p", {
|
|
2160
|
+
id: `${u}-error`,
|
|
2161
|
+
className: "sfa-field__error",
|
|
2162
|
+
children: l
|
|
2163
|
+
}) : null
|
|
2164
|
+
]
|
|
2165
|
+
});
|
|
2166
|
+
};
|
|
2167
|
+
return /* @__PURE__ */ v("li", {
|
|
2168
|
+
className: "sfa-rate",
|
|
2169
|
+
"data-rate-key": e.key,
|
|
2170
|
+
children: [
|
|
2171
|
+
u("label", a.label, e.label, "label"),
|
|
2172
|
+
u("amount", a.amount, e.amount, "amount", "decimal"),
|
|
2173
|
+
/* @__PURE__ */ v("div", {
|
|
2174
|
+
className: "sfa-field",
|
|
2175
|
+
children: [
|
|
2176
|
+
/* @__PURE__ */ _("span", {
|
|
2177
|
+
className: "sfa-field__label",
|
|
2178
|
+
children: a.currency
|
|
2179
|
+
}),
|
|
2180
|
+
/* @__PURE__ */ _("span", {
|
|
2181
|
+
className: "sfa-rate__currency",
|
|
2182
|
+
"aria-invalid": !!r.currency,
|
|
2183
|
+
children: e.currency
|
|
2184
|
+
}),
|
|
2185
|
+
r.currency ? /* @__PURE__ */ _("p", {
|
|
2186
|
+
className: "sfa-field__error",
|
|
2187
|
+
children: r.currency
|
|
2188
|
+
}) : null
|
|
2189
|
+
]
|
|
2190
|
+
}),
|
|
2191
|
+
u("min", a.minDays, e.minDays, "minDays", "numeric"),
|
|
2192
|
+
u("max", a.maxDays, e.maxDays, "maxDays", "numeric"),
|
|
2193
|
+
/* @__PURE__ */ v("label", {
|
|
2194
|
+
className: "sfa-rate__active",
|
|
2195
|
+
children: [/* @__PURE__ */ _("input", {
|
|
2196
|
+
type: "checkbox",
|
|
2197
|
+
checked: e.active,
|
|
2198
|
+
disabled: i,
|
|
2199
|
+
onChange: (e) => o({ active: e.target.checked })
|
|
2200
|
+
}), a.active]
|
|
2201
|
+
}),
|
|
2202
|
+
r.row ? /* @__PURE__ */ _("p", {
|
|
2203
|
+
className: "sfa-field__error",
|
|
2204
|
+
children: r.row
|
|
2205
|
+
}) : null,
|
|
2206
|
+
/* @__PURE__ */ v("div", {
|
|
2207
|
+
className: "sfa-rate__actions",
|
|
2208
|
+
children: [
|
|
2209
|
+
/* @__PURE__ */ _("button", {
|
|
2210
|
+
type: "button",
|
|
2211
|
+
className: "sfa-btn",
|
|
2212
|
+
"aria-label": `${a.moveEarlier}: ${l}`,
|
|
2213
|
+
disabled: i || t === 0,
|
|
2214
|
+
onClick: () => s("earlier"),
|
|
2215
|
+
children: a.moveEarlier
|
|
2216
|
+
}),
|
|
2217
|
+
/* @__PURE__ */ _("button", {
|
|
2218
|
+
type: "button",
|
|
2219
|
+
className: "sfa-btn",
|
|
2220
|
+
"aria-label": `${a.moveLater}: ${l}`,
|
|
2221
|
+
disabled: i || t === n - 1,
|
|
2222
|
+
onClick: () => s("later"),
|
|
2223
|
+
children: a.moveLater
|
|
2224
|
+
}),
|
|
2225
|
+
/* @__PURE__ */ _("button", {
|
|
2226
|
+
type: "button",
|
|
2227
|
+
className: "sfa-btn sfa-btn--danger",
|
|
2228
|
+
"aria-label": `${a.remove}: ${l}`,
|
|
2229
|
+
disabled: i,
|
|
2230
|
+
onClick: c,
|
|
2231
|
+
children: a.remove
|
|
2232
|
+
})
|
|
2233
|
+
]
|
|
2234
|
+
})
|
|
2235
|
+
]
|
|
2236
|
+
});
|
|
2237
|
+
}
|
|
2238
|
+
// src/views/shipping/admin-shipping-rates.tsx
|
|
2239
|
+
function nt({ onDirtyChange: e }) {
|
|
2240
|
+
let t = A(), { labels: n, currency: r } = k(), i = n.shipping, a = j(["shipping-rates"], () => t.listShippingRates()), [o, c] = h([]), [l, u] = h("[]"), [d, f] = h(void 0), [g, y] = h(null), [b, x] = h({}), [S, C] = h(!1), [w, T] = h(!1), [E, D] = h(!1), O = M((e) => t.replaceShippingRates(e)), N = m(void 0);
|
|
2241
|
+
if (a.data && a.data !== d) {
|
|
2242
|
+
let e = Xe(a.data);
|
|
2243
|
+
f(a.data), c(e), u(Q(e));
|
|
2244
|
+
}
|
|
2245
|
+
let P = d !== void 0 && Q(o) !== l;
|
|
2246
|
+
p(() => {
|
|
2247
|
+
N.current !== P && (N.current = P, e?.(P));
|
|
2248
|
+
}, [P, e]);
|
|
2249
|
+
let F = (e) => {
|
|
2250
|
+
c(e), T(!1), C(!1);
|
|
2251
|
+
}, I = (e, t) => {
|
|
2252
|
+
F(o.map((n) => n.key === e ? {
|
|
2253
|
+
...n,
|
|
2254
|
+
...t
|
|
2255
|
+
} : n)), x(({ [e]: t, ...n }) => n);
|
|
2256
|
+
}, L = (e, t) => {
|
|
2257
|
+
let n = t === "earlier" ? e - 1 : e + 1;
|
|
2258
|
+
if (n < 0 || n >= o.length) return;
|
|
2259
|
+
let r = [...o];
|
|
2260
|
+
[r[e], r[n]] = [r[n], r[e]], F(r);
|
|
2261
|
+
}, B = () => F([...o, Ze(r, i.newRateLabel)]), V = () => {
|
|
2262
|
+
g && (F(o.filter((e) => e.key !== g.key)), D(!0), y(null));
|
|
2263
|
+
}, U = async () => {
|
|
2264
|
+
let e = Qe(o, i);
|
|
2265
|
+
if (x(e.rowErrors), C(e.noActive), !e.valid) return;
|
|
2266
|
+
let t = await O.run(e.rates);
|
|
2267
|
+
if (!t) return;
|
|
2268
|
+
let n = Xe(t);
|
|
2269
|
+
c(n), u(Q(n)), x({}), D(!1), T(!0);
|
|
2270
|
+
}, ee = o.some((e) => e.currency !== r), te = O.error instanceof s ? et(O.error.issues, o, i) : {};
|
|
2271
|
+
return a.loading && !a.data ? /* @__PURE__ */ _("p", {
|
|
2272
|
+
role: "status",
|
|
2273
|
+
children: i.loading
|
|
2274
|
+
}) : a.data ? /* @__PURE__ */ v("div", {
|
|
2275
|
+
className: "sfa-shipping",
|
|
2276
|
+
children: [
|
|
2277
|
+
/* @__PURE__ */ _("h2", { children: i.title }),
|
|
2278
|
+
E ? /* @__PURE__ */ _(z, {
|
|
2279
|
+
variant: "warning",
|
|
2280
|
+
children: i.removalWarning
|
|
2281
|
+
}) : null,
|
|
2282
|
+
ee ? /* @__PURE__ */ _(z, {
|
|
2283
|
+
variant: "warning",
|
|
2284
|
+
children: J(i.mixedCurrency, { currency: r })
|
|
2285
|
+
}) : null,
|
|
2286
|
+
S ? /* @__PURE__ */ _(z, {
|
|
2287
|
+
variant: "error",
|
|
2288
|
+
children: i.noActive
|
|
2289
|
+
}) : null,
|
|
2290
|
+
/* @__PURE__ */ _(H, { error: O.error }),
|
|
2291
|
+
w ? /* @__PURE__ */ _(z, {
|
|
2292
|
+
variant: "success",
|
|
2293
|
+
children: i.saved
|
|
2294
|
+
}) : null,
|
|
2295
|
+
P ? /* @__PURE__ */ _("p", {
|
|
2296
|
+
className: "sfa-field__help",
|
|
2297
|
+
children: i.unsaved
|
|
2298
|
+
}) : null,
|
|
2299
|
+
o.length === 0 ? /* @__PURE__ */ _("p", { children: i.empty }) : null,
|
|
2300
|
+
/* @__PURE__ */ _("ul", {
|
|
2301
|
+
className: "sfa-rates",
|
|
2302
|
+
children: o.map((e, t) => /* @__PURE__ */ _(tt, {
|
|
2303
|
+
draft: e,
|
|
2304
|
+
index: t,
|
|
2305
|
+
total: o.length,
|
|
2306
|
+
errors: {
|
|
2307
|
+
...te[e.key],
|
|
2308
|
+
...b[e.key]
|
|
2309
|
+
},
|
|
2310
|
+
disabled: O.pending,
|
|
2311
|
+
labels: i,
|
|
2312
|
+
onChange: (t) => I(e.key, t),
|
|
2313
|
+
onMove: (e) => L(t, e),
|
|
2314
|
+
onRemove: () => y(e)
|
|
2315
|
+
}, e.key))
|
|
2316
|
+
}),
|
|
2317
|
+
/* @__PURE__ */ v("div", {
|
|
2318
|
+
className: "sfa-shipping__actions",
|
|
2319
|
+
children: [/* @__PURE__ */ _("button", {
|
|
2320
|
+
type: "button",
|
|
2321
|
+
className: "sfa-btn",
|
|
2322
|
+
onClick: B,
|
|
2323
|
+
children: i.add
|
|
2324
|
+
}), /* @__PURE__ */ _("button", {
|
|
2325
|
+
type: "button",
|
|
2326
|
+
className: "sfa-btn sfa-btn--primary",
|
|
2327
|
+
disabled: O.pending,
|
|
2328
|
+
onClick: U,
|
|
2329
|
+
children: i.save
|
|
2330
|
+
})]
|
|
2331
|
+
}),
|
|
2332
|
+
/* @__PURE__ */ _(R, {
|
|
2333
|
+
open: g !== null,
|
|
2334
|
+
title: i.removeTitle,
|
|
2335
|
+
destructive: !0,
|
|
2336
|
+
confirmLabel: i.remove,
|
|
2337
|
+
onConfirm: V,
|
|
2338
|
+
onCancel: () => y(null),
|
|
2339
|
+
children: /* @__PURE__ */ _("p", { children: i.removeBody })
|
|
2340
|
+
})
|
|
2341
|
+
]
|
|
2342
|
+
}) : /* @__PURE__ */ _(H, { error: a.error });
|
|
2343
|
+
}
|
|
2344
|
+
export { N as AdminLayout, qe as AdminOrderDetail, Me as AdminOrderList, Ee as AdminProductEditor, xe as AdminProductImages, oe as AdminProductList, O as AdminProvider, nt as AdminShippingRates, P as AdminTable, R as ConfirmDialog, H as ErrorMessage, I as Money, z as Notice, He as OrderActions, F as StatusBadge, V as errorKey, G as formatMoneyInput, W as parseMoneyInput, k as useAdmin, A as useAdminClient, M as useAdminMutation, j as useAdminQuery };
|
|
2345
|
+
|
|
2346
|
+
//# sourceMappingURL=index.js.map
|