@develemit/commerce-admin 0.0.0-stage → 0.4.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 +147 -2
- package/dist/client/admin-client.d.ts +37 -0
- package/dist/client/errors.d.ts +47 -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--_j5r8ag.js +168 -0
- package/dist/client--_j5r8ag.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 +27 -0
- package/dist/index.js +2977 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/admin-labels.d.ts +26 -0
- package/dist/lib/discount-form.d.ts +28 -0
- package/dist/lib/discount-labels.d.ts +56 -0
- package/dist/lib/discount-status.d.ts +5 -0
- package/dist/lib/image-labels.d.ts +27 -0
- package/dist/lib/image-rules.d.ts +4 -0
- package/dist/lib/merge-labels.d.ts +19 -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 +45 -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-discount-pages.d.ts +26 -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 +418 -0
- package/dist/views/discounts/admin-discount-editor.d.ts +6 -0
- package/dist/views/discounts/admin-discount-list.d.ts +1 -0
- package/dist/views/discounts/discount-fields.d.ts +10 -0
- package/dist/views/discounts/discount-value.d.ts +4 -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/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-alt-editor.d.ts +9 -0
- package/dist/views/products/image-tile.d.ts +15 -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,2977 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { a as e, c as t, d as n, f as r, i, l as a, m as o, o as s, p as c, r as l, s as u, u as d } from "./client--_j5r8ag.js";
|
|
3
|
+
import { createContext as f, useCallback as p, useContext as m, useEffect as h, useRef as g, useState as _ } from "react";
|
|
4
|
+
import { Fragment as v, jsx as y, jsxs as b } from "react/jsx-runtime";
|
|
5
|
+
import { adminProductInputSchema as x, shippingRatesInputSchema as S } from "@develemit/commerce-contracts";
|
|
6
|
+
// src/lib/order-labels.ts
|
|
7
|
+
var C = {
|
|
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
|
+
}, w = {
|
|
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
|
+
}, T = {
|
|
139
|
+
title: "Discounts",
|
|
140
|
+
newDiscount: "New discount",
|
|
141
|
+
searchLabel: "Search discounts",
|
|
142
|
+
searchPlaceholder: "Search by code",
|
|
143
|
+
tabs: {
|
|
144
|
+
active: "Active",
|
|
145
|
+
scheduled: "Scheduled",
|
|
146
|
+
expired: "Expired",
|
|
147
|
+
inactive: "Inactive"
|
|
148
|
+
},
|
|
149
|
+
empty: {
|
|
150
|
+
active: "No active discounts.",
|
|
151
|
+
scheduled: "No scheduled discounts.",
|
|
152
|
+
expired: "No expired discounts.",
|
|
153
|
+
inactive: "No inactive discounts."
|
|
154
|
+
},
|
|
155
|
+
noMatches: "No discounts match your search.",
|
|
156
|
+
loadMore: "Load more",
|
|
157
|
+
columns: {
|
|
158
|
+
code: "Code",
|
|
159
|
+
value: "Discount",
|
|
160
|
+
status: "Status",
|
|
161
|
+
usage: "Used"
|
|
162
|
+
},
|
|
163
|
+
usage: "{used} / {max} used",
|
|
164
|
+
usageUnlimited: "{used} used",
|
|
165
|
+
createTitle: "New discount",
|
|
166
|
+
editTitle: "Edit discount",
|
|
167
|
+
saved: "Discount saved.",
|
|
168
|
+
fields: {
|
|
169
|
+
code: "Code",
|
|
170
|
+
type: "Type",
|
|
171
|
+
percentOff: "Percent off",
|
|
172
|
+
amountOff: "Amount off",
|
|
173
|
+
minSubtotal: "Minimum subtotal",
|
|
174
|
+
startsAt: "Starts",
|
|
175
|
+
endsAt: "Ends",
|
|
176
|
+
maxRedemptions: "Usage limit"
|
|
177
|
+
},
|
|
178
|
+
types: {
|
|
179
|
+
percent: "Percent",
|
|
180
|
+
fixed: "Fixed amount"
|
|
181
|
+
},
|
|
182
|
+
optionalHelp: "Optional",
|
|
183
|
+
lockedHelp: "Used on {count} orders; create a new code instead.",
|
|
184
|
+
deactivate: "Deactivate",
|
|
185
|
+
deactivateTitle: "Deactivate this discount?",
|
|
186
|
+
deactivateBody: "Buyers can no longer use this code. Past orders keep it. You can reactivate it later.",
|
|
187
|
+
reactivate: "Reactivate",
|
|
188
|
+
validation: {
|
|
189
|
+
code: "Use letters, numbers, dashes or underscores (up to 40).",
|
|
190
|
+
percentOff: "Enter a whole number from 1 to 100.",
|
|
191
|
+
amountOff: "Enter an amount greater than zero, like 5.00.",
|
|
192
|
+
minSubtotal: "Enter an amount greater than zero, like 25.00.",
|
|
193
|
+
maxRedemptions: "Enter a whole number greater than zero.",
|
|
194
|
+
maxRedemptionsBelowUsage: "The limit cannot be lower than the times used.",
|
|
195
|
+
endsBeforeStart: "The end must be after the start.",
|
|
196
|
+
date: "Enter a valid date and time.",
|
|
197
|
+
codeTaken: "That code is already in use.",
|
|
198
|
+
invalid: "This value is not valid."
|
|
199
|
+
},
|
|
200
|
+
orderRow: "Discount"
|
|
201
|
+
}, E = {
|
|
202
|
+
title: "Products",
|
|
203
|
+
newProduct: "New product",
|
|
204
|
+
searchLabel: "Search products",
|
|
205
|
+
searchPlaceholder: "Search by name",
|
|
206
|
+
filters: {
|
|
207
|
+
all: "All",
|
|
208
|
+
live: "Live",
|
|
209
|
+
sold: "Sold",
|
|
210
|
+
draft: "Drafts",
|
|
211
|
+
archived: "Archived"
|
|
212
|
+
},
|
|
213
|
+
empty: {
|
|
214
|
+
all: "No products yet. Add your first piece.",
|
|
215
|
+
live: "Nothing is live in the shop right now.",
|
|
216
|
+
sold: "Nothing has sold out yet.",
|
|
217
|
+
draft: "No drafts.",
|
|
218
|
+
archived: "No archived products."
|
|
219
|
+
},
|
|
220
|
+
noMatches: "No products match that search.",
|
|
221
|
+
loadMore: "Load more",
|
|
222
|
+
columns: {
|
|
223
|
+
image: "Image",
|
|
224
|
+
name: "Name",
|
|
225
|
+
price: "Price",
|
|
226
|
+
status: "Status",
|
|
227
|
+
quantity: "In stock",
|
|
228
|
+
actions: "Actions"
|
|
229
|
+
},
|
|
230
|
+
noImage: "No image",
|
|
231
|
+
viewInShop: "View in shop",
|
|
232
|
+
markSold: "Mark sold",
|
|
233
|
+
archive: "Archive",
|
|
234
|
+
markSoldTitle: "Mark as sold?",
|
|
235
|
+
markSoldBody: "This sets the stock to zero. Customers will see it as sold.",
|
|
236
|
+
archiveTitle: "Archive this product?",
|
|
237
|
+
archiveBody: "It will disappear from the shop. You can restore it later.",
|
|
238
|
+
updated: "Product updated.",
|
|
239
|
+
createTitle: "New product",
|
|
240
|
+
editTitle: "Edit product",
|
|
241
|
+
saved: "Saved.",
|
|
242
|
+
fields: {
|
|
243
|
+
name: "Name",
|
|
244
|
+
category: "Category",
|
|
245
|
+
description: "Description",
|
|
246
|
+
materials: "Materials",
|
|
247
|
+
dimensions: "Dimensions",
|
|
248
|
+
price: "Price",
|
|
249
|
+
quantity: "Quantity",
|
|
250
|
+
status: "Status",
|
|
251
|
+
featured: "Feature this product on the home page"
|
|
252
|
+
},
|
|
253
|
+
images: {
|
|
254
|
+
title: "Photos",
|
|
255
|
+
empty: "Add a photo so this can go live.",
|
|
256
|
+
add: "Add photos",
|
|
257
|
+
takePhoto: "Take photo",
|
|
258
|
+
dropHint: "Drop photos here, or use the buttons.",
|
|
259
|
+
altLabel: "Photo description",
|
|
260
|
+
altHelp: "Describe what the photo shows, for people who cannot see it.",
|
|
261
|
+
altWarning: "No description yet. Add one so everyone can enjoy this photo.",
|
|
262
|
+
cover: "Cover",
|
|
263
|
+
photoName: "Photo {n}",
|
|
264
|
+
editAlt: "Edit description",
|
|
265
|
+
saveAlt: "Save",
|
|
266
|
+
cancelAlt: "Cancel",
|
|
267
|
+
moveEarlier: "Move earlier",
|
|
268
|
+
moveLater: "Move later",
|
|
269
|
+
remove: "Remove",
|
|
270
|
+
removeTitle: "Remove this photo?",
|
|
271
|
+
removeBody: "It will be deleted from this product.",
|
|
272
|
+
uploading: "Uploading…",
|
|
273
|
+
working: "Working…",
|
|
274
|
+
tooLarge: "{name} is larger than 8 MB.",
|
|
275
|
+
wrongType: "{name} must be a JPEG, PNG, WebP or HEIC image.",
|
|
276
|
+
reorderFailed: "The photos could not be reordered. The old order is back.",
|
|
277
|
+
dismiss: "Dismiss"
|
|
278
|
+
},
|
|
279
|
+
statusHelp: "Draft is hidden. Active is live in the shop. Archived is hidden and kept. Mark a piece sold from the product list.",
|
|
280
|
+
priceHelp: "In dollars, for example 48.00.",
|
|
281
|
+
validation: {
|
|
282
|
+
required: "This field is required.",
|
|
283
|
+
price: "Enter a price like 48 or 48.50.",
|
|
284
|
+
quantity: "Enter a whole number, zero or more."
|
|
285
|
+
}
|
|
286
|
+
}, D = {
|
|
287
|
+
loading: "Loading…",
|
|
288
|
+
empty: "Nothing here yet.",
|
|
289
|
+
save: "Save",
|
|
290
|
+
cancel: "Cancel",
|
|
291
|
+
confirm: "Confirm",
|
|
292
|
+
dismiss: "Dismiss",
|
|
293
|
+
navLabel: "Admin",
|
|
294
|
+
nav: {
|
|
295
|
+
products: "Products",
|
|
296
|
+
orders: "Orders",
|
|
297
|
+
shippingRates: "Shipping rates"
|
|
298
|
+
},
|
|
299
|
+
statuses: {
|
|
300
|
+
draft: "Draft",
|
|
301
|
+
active: "Active",
|
|
302
|
+
archived: "Archived",
|
|
303
|
+
pending: "Pending",
|
|
304
|
+
paid: "Paid",
|
|
305
|
+
shipped: "Shipped",
|
|
306
|
+
cancelled: "Cancelled",
|
|
307
|
+
expired: "Expired",
|
|
308
|
+
needs_attention: "Needs attention",
|
|
309
|
+
refunded: "Refunded",
|
|
310
|
+
sold: "Sold",
|
|
311
|
+
scheduled: "Scheduled",
|
|
312
|
+
inactive: "Inactive"
|
|
313
|
+
},
|
|
314
|
+
errors: {
|
|
315
|
+
unauthorized: "You are not signed in or not allowed to do this.",
|
|
316
|
+
notFound: "We could not find that.",
|
|
317
|
+
invalidInput: "Some of the details are not valid. Check them and try again.",
|
|
318
|
+
invalidOrderState: "This order cannot be changed that way in its current state.",
|
|
319
|
+
insufficientStock: "Not enough stock is available.",
|
|
320
|
+
refundExceedsBalance: "The refund is more than the remaining balance.",
|
|
321
|
+
refundGateway: "The payment provider rejected the refund. Try again shortly.",
|
|
322
|
+
refundOutcomeUnknown: "Refund outcome unknown — retry with the same request.",
|
|
323
|
+
discountCodeTaken: "That discount code is already in use.",
|
|
324
|
+
discountInUse: "This code has been used, so that detail can no longer change. Create a new code instead.",
|
|
325
|
+
imageInvalid: "That image could not be used. Try a different file.",
|
|
326
|
+
imageTooLarge: "That image is too large. Choose a smaller one.",
|
|
327
|
+
generic: "Something went wrong. Try again."
|
|
328
|
+
},
|
|
329
|
+
products: E,
|
|
330
|
+
orders: C,
|
|
331
|
+
shipping: w,
|
|
332
|
+
discounts: T
|
|
333
|
+
};
|
|
334
|
+
// src/lib/merge-labels.ts
|
|
335
|
+
function O(e) {
|
|
336
|
+
let t = C;
|
|
337
|
+
return {
|
|
338
|
+
...t,
|
|
339
|
+
...e,
|
|
340
|
+
tabs: {
|
|
341
|
+
...t.tabs,
|
|
342
|
+
...e?.tabs
|
|
343
|
+
},
|
|
344
|
+
empty: {
|
|
345
|
+
...t.empty,
|
|
346
|
+
...e?.empty
|
|
347
|
+
},
|
|
348
|
+
columns: {
|
|
349
|
+
...t.columns,
|
|
350
|
+
...e?.columns
|
|
351
|
+
},
|
|
352
|
+
itemColumns: {
|
|
353
|
+
...t.itemColumns,
|
|
354
|
+
...e?.itemColumns
|
|
355
|
+
},
|
|
356
|
+
refundColumns: {
|
|
357
|
+
...t.refundColumns,
|
|
358
|
+
...e?.refundColumns
|
|
359
|
+
},
|
|
360
|
+
refundSources: {
|
|
361
|
+
...t.refundSources,
|
|
362
|
+
...e?.refundSources
|
|
363
|
+
},
|
|
364
|
+
refundStatuses: {
|
|
365
|
+
...t.refundStatuses,
|
|
366
|
+
...e?.refundStatuses
|
|
367
|
+
},
|
|
368
|
+
actions: {
|
|
369
|
+
...t.actions,
|
|
370
|
+
...e?.actions
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
function k(e) {
|
|
375
|
+
let t = E;
|
|
376
|
+
return {
|
|
377
|
+
...t,
|
|
378
|
+
...e,
|
|
379
|
+
filters: {
|
|
380
|
+
...t.filters,
|
|
381
|
+
...e?.filters
|
|
382
|
+
},
|
|
383
|
+
empty: {
|
|
384
|
+
...t.empty,
|
|
385
|
+
...e?.empty
|
|
386
|
+
},
|
|
387
|
+
columns: {
|
|
388
|
+
...t.columns,
|
|
389
|
+
...e?.columns
|
|
390
|
+
},
|
|
391
|
+
fields: {
|
|
392
|
+
...t.fields,
|
|
393
|
+
...e?.fields
|
|
394
|
+
},
|
|
395
|
+
validation: {
|
|
396
|
+
...t.validation,
|
|
397
|
+
...e?.validation
|
|
398
|
+
},
|
|
399
|
+
images: {
|
|
400
|
+
...t.images,
|
|
401
|
+
...e?.images
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
function A(e) {
|
|
406
|
+
let t = T;
|
|
407
|
+
return {
|
|
408
|
+
...t,
|
|
409
|
+
...e,
|
|
410
|
+
tabs: {
|
|
411
|
+
...t.tabs,
|
|
412
|
+
...e?.tabs
|
|
413
|
+
},
|
|
414
|
+
empty: {
|
|
415
|
+
...t.empty,
|
|
416
|
+
...e?.empty
|
|
417
|
+
},
|
|
418
|
+
columns: {
|
|
419
|
+
...t.columns,
|
|
420
|
+
...e?.columns
|
|
421
|
+
},
|
|
422
|
+
fields: {
|
|
423
|
+
...t.fields,
|
|
424
|
+
...e?.fields
|
|
425
|
+
},
|
|
426
|
+
types: {
|
|
427
|
+
...t.types,
|
|
428
|
+
...e?.types
|
|
429
|
+
},
|
|
430
|
+
validation: {
|
|
431
|
+
...t.validation,
|
|
432
|
+
...e?.validation
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
function j(e) {
|
|
437
|
+
let t = D;
|
|
438
|
+
return {
|
|
439
|
+
...t,
|
|
440
|
+
...e,
|
|
441
|
+
nav: {
|
|
442
|
+
...t.nav,
|
|
443
|
+
...e?.nav
|
|
444
|
+
},
|
|
445
|
+
statuses: {
|
|
446
|
+
...t.statuses,
|
|
447
|
+
...e?.statuses
|
|
448
|
+
},
|
|
449
|
+
errors: {
|
|
450
|
+
...t.errors,
|
|
451
|
+
...e?.errors
|
|
452
|
+
},
|
|
453
|
+
products: k(e?.products),
|
|
454
|
+
orders: O(e?.orders),
|
|
455
|
+
shipping: {
|
|
456
|
+
...w,
|
|
457
|
+
...e?.shipping
|
|
458
|
+
},
|
|
459
|
+
discounts: A(e?.discounts)
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
// src/lib/provider.tsx
|
|
463
|
+
var M = {
|
|
464
|
+
renderLink: ({ href: e, children: t, className: n }) => /* @__PURE__ */ y("a", {
|
|
465
|
+
href: e,
|
|
466
|
+
className: n,
|
|
467
|
+
children: t
|
|
468
|
+
}),
|
|
469
|
+
renderImage: ({ src: e, alt: t, sizes: n, className: r, priority: i }) => /* @__PURE__ */ y("img", {
|
|
470
|
+
src: e,
|
|
471
|
+
alt: t,
|
|
472
|
+
sizes: n,
|
|
473
|
+
className: r,
|
|
474
|
+
loading: i ? "eager" : "lazy",
|
|
475
|
+
decoding: "async",
|
|
476
|
+
fetchPriority: i ? "high" : void 0
|
|
477
|
+
}),
|
|
478
|
+
locale: "en-US",
|
|
479
|
+
currency: "USD",
|
|
480
|
+
hrefs: {
|
|
481
|
+
products: "/admin/products",
|
|
482
|
+
product: (e) => `/admin/products/${e}`,
|
|
483
|
+
newProduct: "/admin/products/new",
|
|
484
|
+
orders: "/admin/orders",
|
|
485
|
+
order: (e) => `/admin/orders/${e}`,
|
|
486
|
+
shippingRates: "/admin/shipping-rates",
|
|
487
|
+
discounts: "/admin/discounts",
|
|
488
|
+
discount: (e) => `/admin/discounts/${e}`,
|
|
489
|
+
newDiscount: "/admin/discounts/new"
|
|
490
|
+
},
|
|
491
|
+
client: null,
|
|
492
|
+
labels: D
|
|
493
|
+
}, N = f(M);
|
|
494
|
+
function ee({ children: e, hrefs: t, labels: n, ...r }) {
|
|
495
|
+
let i = {
|
|
496
|
+
...M,
|
|
497
|
+
...r,
|
|
498
|
+
hrefs: {
|
|
499
|
+
...M.hrefs,
|
|
500
|
+
...t
|
|
501
|
+
},
|
|
502
|
+
labels: j(n)
|
|
503
|
+
};
|
|
504
|
+
return /* @__PURE__ */ y(N.Provider, {
|
|
505
|
+
value: i,
|
|
506
|
+
children: e
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
function P() {
|
|
510
|
+
return m(N);
|
|
511
|
+
}
|
|
512
|
+
function F() {
|
|
513
|
+
let { client: e } = P();
|
|
514
|
+
if (!e) throw Error("AdminProvider needs a `client` to render this view.");
|
|
515
|
+
return e;
|
|
516
|
+
}
|
|
517
|
+
// src/lib/use-admin-query.ts
|
|
518
|
+
function I(e, t) {
|
|
519
|
+
let n = g(t);
|
|
520
|
+
h(() => {
|
|
521
|
+
n.current = t;
|
|
522
|
+
});
|
|
523
|
+
let [r, i] = _(0), [a, o] = _({
|
|
524
|
+
request: "",
|
|
525
|
+
data: void 0,
|
|
526
|
+
error: void 0
|
|
527
|
+
}), s = `${JSON.stringify(e)}#${r}`;
|
|
528
|
+
h(() => {
|
|
529
|
+
let e = new AbortController();
|
|
530
|
+
return n.current(e.signal).then((t) => {
|
|
531
|
+
e.signal.aborted || o({
|
|
532
|
+
request: s,
|
|
533
|
+
data: t,
|
|
534
|
+
error: void 0
|
|
535
|
+
});
|
|
536
|
+
}).catch((t) => {
|
|
537
|
+
e.signal.aborted || o((e) => ({
|
|
538
|
+
request: s,
|
|
539
|
+
data: e.data,
|
|
540
|
+
error: t
|
|
541
|
+
}));
|
|
542
|
+
}), () => e.abort();
|
|
543
|
+
}, [s]);
|
|
544
|
+
let c = p(() => i((e) => e + 1), []), l = a.request === s;
|
|
545
|
+
return {
|
|
546
|
+
data: a.data,
|
|
547
|
+
error: l ? a.error : void 0,
|
|
548
|
+
loading: !l,
|
|
549
|
+
reload: c
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
// src/lib/use-admin-mutation.ts
|
|
553
|
+
function L(e) {
|
|
554
|
+
let t = g(e);
|
|
555
|
+
h(() => {
|
|
556
|
+
t.current = e;
|
|
557
|
+
});
|
|
558
|
+
let [n, r] = _(!1), [i, a] = _(void 0);
|
|
559
|
+
return {
|
|
560
|
+
run: p(async (...e) => {
|
|
561
|
+
r(!0), a(void 0);
|
|
562
|
+
try {
|
|
563
|
+
return await t.current(...e);
|
|
564
|
+
} catch (e) {
|
|
565
|
+
a(e);
|
|
566
|
+
return;
|
|
567
|
+
} finally {
|
|
568
|
+
r(!1);
|
|
569
|
+
}
|
|
570
|
+
}, []),
|
|
571
|
+
pending: n,
|
|
572
|
+
error: i,
|
|
573
|
+
reset: p(() => a(void 0), [])
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
// src/components/admin-layout/admin-layout.tsx
|
|
577
|
+
function te({ children: e, extraNav: t = [], header: n, footer: r }) {
|
|
578
|
+
let { hrefs: i, labels: a, renderLink: o } = P(), s = [
|
|
579
|
+
{
|
|
580
|
+
href: i.products,
|
|
581
|
+
label: a.nav.products
|
|
582
|
+
},
|
|
583
|
+
{
|
|
584
|
+
href: i.orders,
|
|
585
|
+
label: a.nav.orders
|
|
586
|
+
},
|
|
587
|
+
{
|
|
588
|
+
href: i.shippingRates,
|
|
589
|
+
label: a.nav.shippingRates
|
|
590
|
+
}
|
|
591
|
+
], c = [
|
|
592
|
+
...t.filter((e) => e.position === "start"),
|
|
593
|
+
...s,
|
|
594
|
+
...t.filter((e) => e.position !== "start")
|
|
595
|
+
];
|
|
596
|
+
return /* @__PURE__ */ b("div", {
|
|
597
|
+
className: "sfa-root sfa-layout",
|
|
598
|
+
children: [
|
|
599
|
+
n ? /* @__PURE__ */ y("header", {
|
|
600
|
+
className: "sfa-layout__header",
|
|
601
|
+
children: n
|
|
602
|
+
}) : null,
|
|
603
|
+
/* @__PURE__ */ y("nav", {
|
|
604
|
+
className: "sfa-nav",
|
|
605
|
+
"aria-label": a.navLabel,
|
|
606
|
+
children: /* @__PURE__ */ y("ul", { children: c.map((e) => /* @__PURE__ */ y("li", { children: o({
|
|
607
|
+
href: e.href,
|
|
608
|
+
className: "sfa-nav__link",
|
|
609
|
+
children: e.label
|
|
610
|
+
}) }, e.href)) })
|
|
611
|
+
}),
|
|
612
|
+
/* @__PURE__ */ y("main", {
|
|
613
|
+
className: "sfa-layout__content",
|
|
614
|
+
children: e
|
|
615
|
+
}),
|
|
616
|
+
r ? /* @__PURE__ */ y("footer", {
|
|
617
|
+
className: "sfa-layout__footer",
|
|
618
|
+
children: r
|
|
619
|
+
}) : null
|
|
620
|
+
]
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
// src/components/admin-table/admin-table.tsx
|
|
624
|
+
function R({ columns: e, rows: t, rowKey: n, caption: r }) {
|
|
625
|
+
let { labels: i } = P();
|
|
626
|
+
return t.length === 0 ? /* @__PURE__ */ y("p", {
|
|
627
|
+
className: "sfa-empty",
|
|
628
|
+
children: i.empty
|
|
629
|
+
}) : /* @__PURE__ */ b("table", {
|
|
630
|
+
className: "sfa-table sfa-table--stacked",
|
|
631
|
+
children: [
|
|
632
|
+
r ? /* @__PURE__ */ y("caption", { children: r }) : null,
|
|
633
|
+
/* @__PURE__ */ y("thead", { children: /* @__PURE__ */ y("tr", { children: e.map((e) => /* @__PURE__ */ y("th", {
|
|
634
|
+
scope: "col",
|
|
635
|
+
children: e.header
|
|
636
|
+
}, e.key)) }) }),
|
|
637
|
+
/* @__PURE__ */ y("tbody", { children: t.map((t) => /* @__PURE__ */ y("tr", { children: e.map((e) => /* @__PURE__ */ y("td", {
|
|
638
|
+
"data-label": e.header,
|
|
639
|
+
children: e.render(t)
|
|
640
|
+
}, e.key)) }, n(t))) })
|
|
641
|
+
]
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
// src/components/status-badge/status-badge.tsx
|
|
645
|
+
function z({ status: e }) {
|
|
646
|
+
let { labels: t } = P();
|
|
647
|
+
return /* @__PURE__ */ y("span", {
|
|
648
|
+
className: `sfa-badge sfa-badge--${e.replace(/_/g, "-")}`,
|
|
649
|
+
children: t.statuses[e] ?? e
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
// src/components/money/money.tsx
|
|
653
|
+
function B({ cents: e, currency: t }) {
|
|
654
|
+
let { locale: n } = P(), r = new Intl.NumberFormat(n, {
|
|
655
|
+
style: "currency",
|
|
656
|
+
currency: t
|
|
657
|
+
}).format(e / 100);
|
|
658
|
+
return /* @__PURE__ */ y("span", {
|
|
659
|
+
className: "sfa-money",
|
|
660
|
+
children: r
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
// src/components/confirm-dialog/confirm-dialog.tsx
|
|
664
|
+
var ne = "button:not([disabled]), [href], input:not([disabled]), select, textarea, [tabindex]:not([tabindex=\"-1\"])";
|
|
665
|
+
function V({ open: e, title: t, children: n, confirmLabel: r, destructive: i = !1, pending: a = !1, onConfirm: o, onCancel: s }) {
|
|
666
|
+
let { labels: c } = P(), l = g(null);
|
|
667
|
+
return h(() => {
|
|
668
|
+
if (!e) return;
|
|
669
|
+
let t = document.activeElement;
|
|
670
|
+
return l.current?.querySelector(ne)?.focus(), () => t?.focus();
|
|
671
|
+
}, [e]), e ? /* @__PURE__ */ y("div", {
|
|
672
|
+
className: "sfa-dialog-backdrop",
|
|
673
|
+
onKeyDown: (e) => {
|
|
674
|
+
if (e.key === "Escape") {
|
|
675
|
+
e.stopPropagation(), s();
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
if (e.key !== "Tab") return;
|
|
679
|
+
let t = Array.from(l.current?.querySelectorAll(ne) ?? []);
|
|
680
|
+
if (t.length === 0) return;
|
|
681
|
+
let n = t[0], r = t[t.length - 1];
|
|
682
|
+
e.shiftKey && document.activeElement === n ? (e.preventDefault(), r.focus()) : !e.shiftKey && document.activeElement === r && (e.preventDefault(), n.focus());
|
|
683
|
+
},
|
|
684
|
+
children: /* @__PURE__ */ b("div", {
|
|
685
|
+
ref: l,
|
|
686
|
+
role: "dialog",
|
|
687
|
+
"aria-modal": "true",
|
|
688
|
+
"aria-label": t,
|
|
689
|
+
className: "sfa-dialog",
|
|
690
|
+
children: [
|
|
691
|
+
/* @__PURE__ */ y("h2", {
|
|
692
|
+
className: "sfa-dialog__title",
|
|
693
|
+
children: t
|
|
694
|
+
}),
|
|
695
|
+
n,
|
|
696
|
+
/* @__PURE__ */ b("div", {
|
|
697
|
+
className: "sfa-dialog__actions",
|
|
698
|
+
children: [/* @__PURE__ */ y("button", {
|
|
699
|
+
type: "button",
|
|
700
|
+
className: "sfa-btn",
|
|
701
|
+
onClick: s,
|
|
702
|
+
children: c.cancel
|
|
703
|
+
}), /* @__PURE__ */ y("button", {
|
|
704
|
+
type: "button",
|
|
705
|
+
className: `sfa-btn ${i ? "sfa-btn--danger" : "sfa-btn--primary"}`,
|
|
706
|
+
disabled: a,
|
|
707
|
+
onClick: o,
|
|
708
|
+
children: r ?? c.confirm
|
|
709
|
+
})]
|
|
710
|
+
})
|
|
711
|
+
]
|
|
712
|
+
})
|
|
713
|
+
}) : null;
|
|
714
|
+
}
|
|
715
|
+
// src/components/notice/notice.tsx
|
|
716
|
+
function H({ variant: e, children: t, toast: n = !1, duration: r = 4e3, onDismiss: i }) {
|
|
717
|
+
let { labels: a } = P();
|
|
718
|
+
h(() => {
|
|
719
|
+
if (!n || !i) return;
|
|
720
|
+
let e = setTimeout(i, r);
|
|
721
|
+
return () => clearTimeout(e);
|
|
722
|
+
}, [
|
|
723
|
+
n,
|
|
724
|
+
r,
|
|
725
|
+
i
|
|
726
|
+
]);
|
|
727
|
+
let o = e === "error" ? "alert" : "status", s = `sfa-notice sfa-notice--${e}${n ? " sfa-notice--toast" : ""}`;
|
|
728
|
+
return /* @__PURE__ */ b("div", {
|
|
729
|
+
role: o,
|
|
730
|
+
className: s,
|
|
731
|
+
children: [/* @__PURE__ */ y("span", {
|
|
732
|
+
className: "sfa-notice__body",
|
|
733
|
+
children: t
|
|
734
|
+
}), i && !n ? /* @__PURE__ */ y("button", {
|
|
735
|
+
type: "button",
|
|
736
|
+
className: "sfa-btn",
|
|
737
|
+
onClick: i,
|
|
738
|
+
children: a.dismiss
|
|
739
|
+
}) : null]
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
// src/components/error-message/error-message.tsx
|
|
743
|
+
var re = [
|
|
744
|
+
[e, "unauthorized"],
|
|
745
|
+
[i, "notFound"],
|
|
746
|
+
[l, "invalidInput"],
|
|
747
|
+
[n, "invalidOrderState"],
|
|
748
|
+
[a, "insufficientStock"],
|
|
749
|
+
[r, "refundExceedsBalance"],
|
|
750
|
+
[c, "refundGateway"],
|
|
751
|
+
[o, "refundOutcomeUnknown"],
|
|
752
|
+
[s, "discountCodeTaken"],
|
|
753
|
+
[u, "discountInUse"],
|
|
754
|
+
[t, "imageTooLarge"],
|
|
755
|
+
[d, "imageInvalid"]
|
|
756
|
+
];
|
|
757
|
+
function ie(e) {
|
|
758
|
+
return re.find(([t]) => e instanceof t)?.[1] ?? "generic";
|
|
759
|
+
}
|
|
760
|
+
function U({ error: e }) {
|
|
761
|
+
let { labels: t } = P();
|
|
762
|
+
return e ? /* @__PURE__ */ y(H, {
|
|
763
|
+
variant: "error",
|
|
764
|
+
children: t.errors[ie(e)]
|
|
765
|
+
}) : null;
|
|
766
|
+
}
|
|
767
|
+
// src/lib/product-filter.ts
|
|
768
|
+
function ae(e) {
|
|
769
|
+
return e.status === "active" && e.quantity === 0;
|
|
770
|
+
}
|
|
771
|
+
function oe(e) {
|
|
772
|
+
return ae(e) ? "sold" : e.status;
|
|
773
|
+
}
|
|
774
|
+
function se(e) {
|
|
775
|
+
switch (e) {
|
|
776
|
+
case "live":
|
|
777
|
+
case "sold": return "active";
|
|
778
|
+
case "draft":
|
|
779
|
+
case "archived": return e;
|
|
780
|
+
case "all": return;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
function ce(e) {
|
|
784
|
+
if (e === "live") return "in";
|
|
785
|
+
if (e === "sold") return "sold";
|
|
786
|
+
}
|
|
787
|
+
// src/lib/use-debounced.ts
|
|
788
|
+
function W(e, t) {
|
|
789
|
+
let [n, r] = _(e);
|
|
790
|
+
return h(() => {
|
|
791
|
+
let n = setTimeout(() => r(e), t);
|
|
792
|
+
return () => clearTimeout(n);
|
|
793
|
+
}, [e, t]), n;
|
|
794
|
+
}
|
|
795
|
+
// src/lib/use-product-pages.ts
|
|
796
|
+
function le(e) {
|
|
797
|
+
let t = F(), n = I(["admin-products", e], () => t.listProducts(e)), [r, i] = _(null), a = L(async (n, r) => {
|
|
798
|
+
let a = await t.listProducts({
|
|
799
|
+
...e,
|
|
800
|
+
cursor: n
|
|
801
|
+
});
|
|
802
|
+
i((e) => ({
|
|
803
|
+
base: r,
|
|
804
|
+
items: [...e?.base === r ? e.items : [], ...a.items],
|
|
805
|
+
nextCursor: a.nextCursor
|
|
806
|
+
}));
|
|
807
|
+
}), o = n.data, s = r && r.base === o ? r : null, c = s ? s.nextCursor : o?.nextCursor ?? null;
|
|
808
|
+
return {
|
|
809
|
+
items: [...o?.items ?? [], ...s?.items ?? []],
|
|
810
|
+
loaded: o !== void 0,
|
|
811
|
+
loading: n.loading,
|
|
812
|
+
error: n.error ?? a.error,
|
|
813
|
+
hasMore: !n.loading && c !== null,
|
|
814
|
+
loadingMore: a.pending,
|
|
815
|
+
reload: n.reload,
|
|
816
|
+
loadMore: () => {
|
|
817
|
+
o && c && a.run(c, o);
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
// src/views/products/admin-product-list.tsx
|
|
822
|
+
var ue = [
|
|
823
|
+
"all",
|
|
824
|
+
"live",
|
|
825
|
+
"sold",
|
|
826
|
+
"draft",
|
|
827
|
+
"archived"
|
|
828
|
+
];
|
|
829
|
+
function de() {
|
|
830
|
+
let e = F(), { labels: t, hrefs: n, renderLink: r } = P(), i = t.products, [a, o] = _("all"), [s, c] = _(""), l = W(s.trim(), 300), u = se(a), d = ce(a), f = le({
|
|
831
|
+
...u ? { status: u } : {},
|
|
832
|
+
...d ? { stock: d } : {},
|
|
833
|
+
...l ? { q: l } : {}
|
|
834
|
+
}), [p, m] = _(null), [h, g] = _(!1), v = L(({ kind: t, product: n }) => e.updateProduct(n.id, t === "sold" ? { sold: !0 } : { status: "archived" })), x = async () => {
|
|
835
|
+
if (!p) return;
|
|
836
|
+
let e = await v.run(p);
|
|
837
|
+
m(null), e && (g(!0), f.reload());
|
|
838
|
+
}, S = [
|
|
839
|
+
{
|
|
840
|
+
key: "image",
|
|
841
|
+
header: i.columns.image,
|
|
842
|
+
render: (e) => e.images[0] ? /* @__PURE__ */ y("img", {
|
|
843
|
+
className: "sfa-thumb",
|
|
844
|
+
src: e.images[0].url,
|
|
845
|
+
alt: e.images[0].alt,
|
|
846
|
+
width: 48,
|
|
847
|
+
height: 48
|
|
848
|
+
}) : /* @__PURE__ */ y("span", {
|
|
849
|
+
className: "sfa-thumb sfa-thumb--empty",
|
|
850
|
+
children: i.noImage
|
|
851
|
+
})
|
|
852
|
+
},
|
|
853
|
+
{
|
|
854
|
+
key: "name",
|
|
855
|
+
header: i.columns.name,
|
|
856
|
+
render: (e) => r({
|
|
857
|
+
href: n.product(e.id),
|
|
858
|
+
children: e.name,
|
|
859
|
+
className: "sfa-link--tap"
|
|
860
|
+
})
|
|
861
|
+
},
|
|
862
|
+
{
|
|
863
|
+
key: "price",
|
|
864
|
+
header: i.columns.price,
|
|
865
|
+
render: (e) => /* @__PURE__ */ y(B, {
|
|
866
|
+
cents: e.priceCents,
|
|
867
|
+
currency: e.currency
|
|
868
|
+
})
|
|
869
|
+
},
|
|
870
|
+
{
|
|
871
|
+
key: "status",
|
|
872
|
+
header: i.columns.status,
|
|
873
|
+
render: (e) => /* @__PURE__ */ y(z, { status: oe(e) })
|
|
874
|
+
},
|
|
875
|
+
{
|
|
876
|
+
key: "quantity",
|
|
877
|
+
header: i.columns.quantity,
|
|
878
|
+
render: (e) => e.quantity
|
|
879
|
+
},
|
|
880
|
+
{
|
|
881
|
+
key: "actions",
|
|
882
|
+
header: i.columns.actions,
|
|
883
|
+
render: (e) => /* @__PURE__ */ b("div", {
|
|
884
|
+
className: "sfa-row-actions",
|
|
885
|
+
children: [
|
|
886
|
+
e.status === "active" && n.storefrontProduct ? r({
|
|
887
|
+
href: n.storefrontProduct(e.slug),
|
|
888
|
+
children: i.viewInShop,
|
|
889
|
+
className: "sfa-btn"
|
|
890
|
+
}) : null,
|
|
891
|
+
e.status !== "archived" && e.quantity > 0 ? /* @__PURE__ */ y("button", {
|
|
892
|
+
type: "button",
|
|
893
|
+
className: "sfa-btn",
|
|
894
|
+
onClick: () => m({
|
|
895
|
+
kind: "sold",
|
|
896
|
+
product: e
|
|
897
|
+
}),
|
|
898
|
+
children: i.markSold
|
|
899
|
+
}) : null,
|
|
900
|
+
e.status === "archived" ? null : /* @__PURE__ */ y("button", {
|
|
901
|
+
type: "button",
|
|
902
|
+
className: "sfa-btn",
|
|
903
|
+
onClick: () => m({
|
|
904
|
+
kind: "archive",
|
|
905
|
+
product: e
|
|
906
|
+
}),
|
|
907
|
+
children: i.archive
|
|
908
|
+
})
|
|
909
|
+
]
|
|
910
|
+
})
|
|
911
|
+
}
|
|
912
|
+
], C = f.items, w = l ? i.noMatches : i.empty[a];
|
|
913
|
+
return /* @__PURE__ */ b("section", {
|
|
914
|
+
className: "sfa-products",
|
|
915
|
+
children: [
|
|
916
|
+
/* @__PURE__ */ b("header", {
|
|
917
|
+
className: "sfa-products__header",
|
|
918
|
+
children: [/* @__PURE__ */ y("h1", { children: i.title }), r({
|
|
919
|
+
href: n.newProduct,
|
|
920
|
+
children: i.newProduct,
|
|
921
|
+
className: "sfa-btn sfa-btn--primary"
|
|
922
|
+
})]
|
|
923
|
+
}),
|
|
924
|
+
/* @__PURE__ */ b("div", {
|
|
925
|
+
className: "sfa-products__toolbar",
|
|
926
|
+
children: [/* @__PURE__ */ y("div", {
|
|
927
|
+
role: "group",
|
|
928
|
+
"aria-label": i.columns.status,
|
|
929
|
+
className: "sfa-filter-group",
|
|
930
|
+
children: ue.map((e) => /* @__PURE__ */ y("button", {
|
|
931
|
+
type: "button",
|
|
932
|
+
className: "sfa-btn sfa-filter",
|
|
933
|
+
"aria-pressed": a === e,
|
|
934
|
+
onClick: () => o(e),
|
|
935
|
+
children: i.filters[e]
|
|
936
|
+
}, e))
|
|
937
|
+
}), /* @__PURE__ */ y("input", {
|
|
938
|
+
type: "search",
|
|
939
|
+
"aria-label": i.searchLabel,
|
|
940
|
+
placeholder: i.searchPlaceholder,
|
|
941
|
+
value: s,
|
|
942
|
+
onChange: (e) => c(e.target.value)
|
|
943
|
+
})]
|
|
944
|
+
}),
|
|
945
|
+
/* @__PURE__ */ y(U, { error: f.error ?? v.error }),
|
|
946
|
+
f.loading && !f.loaded ? /* @__PURE__ */ y("p", { children: t.loading }) : C.length === 0 ? /* @__PURE__ */ y("p", {
|
|
947
|
+
className: "sfa-empty",
|
|
948
|
+
children: w
|
|
949
|
+
}) : /* @__PURE__ */ y(R, {
|
|
950
|
+
columns: S,
|
|
951
|
+
rows: C,
|
|
952
|
+
rowKey: (e) => e.id
|
|
953
|
+
}),
|
|
954
|
+
f.hasMore ? /* @__PURE__ */ y("button", {
|
|
955
|
+
type: "button",
|
|
956
|
+
className: "sfa-btn sfa-products__more",
|
|
957
|
+
disabled: f.loadingMore,
|
|
958
|
+
onClick: f.loadMore,
|
|
959
|
+
children: i.loadMore
|
|
960
|
+
}) : null,
|
|
961
|
+
/* @__PURE__ */ y(V, {
|
|
962
|
+
open: p !== null,
|
|
963
|
+
title: p?.kind === "archive" ? i.archiveTitle : i.markSoldTitle,
|
|
964
|
+
confirmLabel: p?.kind === "archive" ? i.archive : i.markSold,
|
|
965
|
+
pending: v.pending,
|
|
966
|
+
onConfirm: x,
|
|
967
|
+
onCancel: () => m(null),
|
|
968
|
+
children: /* @__PURE__ */ b("p", { children: [
|
|
969
|
+
p?.product.name,
|
|
970
|
+
" — ",
|
|
971
|
+
p?.kind === "archive" ? i.archiveBody : i.markSoldBody
|
|
972
|
+
] })
|
|
973
|
+
}),
|
|
974
|
+
h ? /* @__PURE__ */ y(H, {
|
|
975
|
+
variant: "success",
|
|
976
|
+
toast: !0,
|
|
977
|
+
onDismiss: () => g(!1),
|
|
978
|
+
children: i.updated
|
|
979
|
+
}) : null
|
|
980
|
+
]
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
// src/lib/money-input.ts
|
|
984
|
+
var fe = /^\$?\s*(\d+|\d{1,3}(?:,\d{3})+)?(?:\.(\d{1,2}))?$/;
|
|
985
|
+
function G(e) {
|
|
986
|
+
let t = e.trim(), n = fe.exec(t);
|
|
987
|
+
if (!n || !n[1] && !n[2]) return null;
|
|
988
|
+
let r = Number((n[1] ?? "0").replace(/,/g, "")), i = Number((n[2] ?? "").padEnd(2, "0")), a = r * 100 + i;
|
|
989
|
+
return Number.isSafeInteger(a) ? a : null;
|
|
990
|
+
}
|
|
991
|
+
function K(e) {
|
|
992
|
+
return `${Math.floor(e / 100)}.${String(e % 100).padStart(2, "0")}`;
|
|
993
|
+
}
|
|
994
|
+
// src/lib/product-form.ts
|
|
995
|
+
var pe = [
|
|
996
|
+
"name",
|
|
997
|
+
"category",
|
|
998
|
+
"description",
|
|
999
|
+
"materials",
|
|
1000
|
+
"dimensions",
|
|
1001
|
+
"price",
|
|
1002
|
+
"quantity",
|
|
1003
|
+
"status",
|
|
1004
|
+
"featured"
|
|
1005
|
+
], me = {
|
|
1006
|
+
name: "",
|
|
1007
|
+
category: "",
|
|
1008
|
+
description: "",
|
|
1009
|
+
materials: "",
|
|
1010
|
+
dimensions: "",
|
|
1011
|
+
price: "",
|
|
1012
|
+
quantity: "1",
|
|
1013
|
+
status: "draft",
|
|
1014
|
+
featured: !1
|
|
1015
|
+
};
|
|
1016
|
+
function he(e) {
|
|
1017
|
+
return {
|
|
1018
|
+
name: e.name,
|
|
1019
|
+
category: e.category,
|
|
1020
|
+
description: e.description,
|
|
1021
|
+
materials: e.materials ?? "",
|
|
1022
|
+
dimensions: e.dimensions ?? "",
|
|
1023
|
+
price: K(e.priceCents),
|
|
1024
|
+
quantity: String(e.quantity),
|
|
1025
|
+
status: e.status,
|
|
1026
|
+
featured: e.featured
|
|
1027
|
+
};
|
|
1028
|
+
}
|
|
1029
|
+
function ge(e) {
|
|
1030
|
+
let t = String(Array.isArray(e) ? e[0] ?? "" : e ?? ""), n = t === "priceCents" ? "price" : t;
|
|
1031
|
+
return pe.includes(n) ? n : void 0;
|
|
1032
|
+
}
|
|
1033
|
+
function _e(e) {
|
|
1034
|
+
let t = {};
|
|
1035
|
+
for (let n of e) {
|
|
1036
|
+
let { path: e, message: r } = n ?? {}, i = ge(e);
|
|
1037
|
+
i && !t[i] && (t[i] = typeof r == "string" ? r : "Invalid value.");
|
|
1038
|
+
}
|
|
1039
|
+
return t;
|
|
1040
|
+
}
|
|
1041
|
+
function ve(e) {
|
|
1042
|
+
return pe.find((t) => e[t]);
|
|
1043
|
+
}
|
|
1044
|
+
function ye(e) {
|
|
1045
|
+
let t = e.trim();
|
|
1046
|
+
return t === "" ? null : t;
|
|
1047
|
+
}
|
|
1048
|
+
function be(e, t, n) {
|
|
1049
|
+
let r = {}, i = G(e.price);
|
|
1050
|
+
i === null && (r.price = t.validation.price);
|
|
1051
|
+
let a = /^\d+$/.test(e.quantity.trim()) ? Number(e.quantity.trim()) : null;
|
|
1052
|
+
a === null && (r.quantity = t.validation.quantity);
|
|
1053
|
+
let o = x.safeParse({
|
|
1054
|
+
name: e.name,
|
|
1055
|
+
description: e.description,
|
|
1056
|
+
materials: ye(e.materials),
|
|
1057
|
+
dimensions: ye(e.dimensions),
|
|
1058
|
+
priceCents: i ?? 0,
|
|
1059
|
+
...n ? { currency: n } : {},
|
|
1060
|
+
category: e.category,
|
|
1061
|
+
quantity: a ?? 0,
|
|
1062
|
+
status: e.status,
|
|
1063
|
+
featured: e.featured
|
|
1064
|
+
});
|
|
1065
|
+
if (!o.success) for (let e of o.error.issues) {
|
|
1066
|
+
let n = ge(e.path);
|
|
1067
|
+
n && !r[n] && (r[n] = t.validation.required);
|
|
1068
|
+
}
|
|
1069
|
+
return !o.success || Object.keys(r).length > 0 ? {
|
|
1070
|
+
ok: !1,
|
|
1071
|
+
errors: r
|
|
1072
|
+
} : {
|
|
1073
|
+
ok: !0,
|
|
1074
|
+
input: o.data
|
|
1075
|
+
};
|
|
1076
|
+
}
|
|
1077
|
+
var xe = [
|
|
1078
|
+
"name",
|
|
1079
|
+
"description",
|
|
1080
|
+
"materials",
|
|
1081
|
+
"dimensions",
|
|
1082
|
+
"priceCents",
|
|
1083
|
+
"category",
|
|
1084
|
+
"quantity",
|
|
1085
|
+
"status",
|
|
1086
|
+
"featured"
|
|
1087
|
+
];
|
|
1088
|
+
function Se(e, t) {
|
|
1089
|
+
let n = {};
|
|
1090
|
+
for (let r of xe) (t[r] ?? null) !== e[r] && (n[r] = t[r]);
|
|
1091
|
+
return n;
|
|
1092
|
+
}
|
|
1093
|
+
var Ce = [
|
|
1094
|
+
"image/jpeg",
|
|
1095
|
+
"image/png",
|
|
1096
|
+
"image/webp",
|
|
1097
|
+
"image/heic"
|
|
1098
|
+
];
|
|
1099
|
+
function q(e, t) {
|
|
1100
|
+
return e.replace(/\{(\w+)\}/g, (e, n) => t[n] ?? "");
|
|
1101
|
+
}
|
|
1102
|
+
function we(e, t) {
|
|
1103
|
+
return Ce.includes(e.type) ? e.size > 8388608 ? q(t.tooLarge, { name: e.name }) : null : q(t.wrongType, { name: e.name });
|
|
1104
|
+
}
|
|
1105
|
+
// src/lib/use-image-upload.ts
|
|
1106
|
+
function Te({ productId: e, onUploaded: t }) {
|
|
1107
|
+
let n = F(), { labels: r } = P(), [i, a] = _([]), o = g(0), s = g(Promise.resolve()), c = g(t);
|
|
1108
|
+
h(() => {
|
|
1109
|
+
c.current = t;
|
|
1110
|
+
});
|
|
1111
|
+
let l = (e, t) => a((n) => n.map((n) => n.id === e ? {
|
|
1112
|
+
...n,
|
|
1113
|
+
...t
|
|
1114
|
+
} : n)), u = (e) => a((t) => t.filter((t) => t.id !== e)), d = async (t, r, i) => {
|
|
1115
|
+
l(t, { status: "uploading" });
|
|
1116
|
+
try {
|
|
1117
|
+
let a = await n.uploadProductImage(e, r, i);
|
|
1118
|
+
c.current(a), u(t);
|
|
1119
|
+
} catch (e) {
|
|
1120
|
+
l(t, {
|
|
1121
|
+
status: "error",
|
|
1122
|
+
error: e
|
|
1123
|
+
});
|
|
1124
|
+
}
|
|
1125
|
+
};
|
|
1126
|
+
return {
|
|
1127
|
+
entries: i,
|
|
1128
|
+
upload: p((e, t) => {
|
|
1129
|
+
let n = e.map((e) => ({
|
|
1130
|
+
id: o.current++,
|
|
1131
|
+
file: e,
|
|
1132
|
+
reason: we(e, r.products.images)
|
|
1133
|
+
}));
|
|
1134
|
+
a((e) => [...e, ...n.map(({ id: e, file: t, reason: n }) => ({
|
|
1135
|
+
id: e,
|
|
1136
|
+
name: t.name,
|
|
1137
|
+
status: n ? "error" : "queued",
|
|
1138
|
+
reason: n ?? void 0
|
|
1139
|
+
}))]);
|
|
1140
|
+
for (let { id: e, file: r, reason: i } of n) i || (s.current = s.current.then(() => d(e, r, t.trim())));
|
|
1141
|
+
}, [
|
|
1142
|
+
n,
|
|
1143
|
+
e,
|
|
1144
|
+
r
|
|
1145
|
+
]),
|
|
1146
|
+
dismiss: u
|
|
1147
|
+
};
|
|
1148
|
+
}
|
|
1149
|
+
// src/views/products/image-alt-editor.tsx
|
|
1150
|
+
function Ee({ imageId: e, alt: t, name: n, labels: r, onSave: i }) {
|
|
1151
|
+
let [a, o] = _(null), [s, c] = _(!1), [l, u] = _(void 0), d = () => {
|
|
1152
|
+
o(null), u(void 0);
|
|
1153
|
+
};
|
|
1154
|
+
return a === null ? /* @__PURE__ */ y("button", {
|
|
1155
|
+
type: "button",
|
|
1156
|
+
className: "sfa-btn",
|
|
1157
|
+
"aria-label": `${r.editAlt}: ${n}`,
|
|
1158
|
+
onClick: () => o(t),
|
|
1159
|
+
children: r.editAlt
|
|
1160
|
+
}) : /* @__PURE__ */ b("form", {
|
|
1161
|
+
className: "sfa-image-tile__alt",
|
|
1162
|
+
onSubmit: async (e) => {
|
|
1163
|
+
if (e.preventDefault(), a !== null) {
|
|
1164
|
+
c(!0), u(void 0);
|
|
1165
|
+
try {
|
|
1166
|
+
await i(a), o(null);
|
|
1167
|
+
} catch (e) {
|
|
1168
|
+
u(e);
|
|
1169
|
+
} finally {
|
|
1170
|
+
c(!1);
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
},
|
|
1174
|
+
children: [
|
|
1175
|
+
/* @__PURE__ */ y("input", {
|
|
1176
|
+
"aria-label": `${r.altLabel}: ${n}`,
|
|
1177
|
+
value: a,
|
|
1178
|
+
disabled: s,
|
|
1179
|
+
autoFocus: !0,
|
|
1180
|
+
onChange: (e) => o(e.target.value),
|
|
1181
|
+
onKeyDown: (e) => {
|
|
1182
|
+
e.key === "Escape" && d();
|
|
1183
|
+
}
|
|
1184
|
+
}),
|
|
1185
|
+
/* @__PURE__ */ y(U, { error: l }),
|
|
1186
|
+
/* @__PURE__ */ y("button", {
|
|
1187
|
+
type: "submit",
|
|
1188
|
+
className: "sfa-btn",
|
|
1189
|
+
"data-image-id": e,
|
|
1190
|
+
disabled: s,
|
|
1191
|
+
children: r.saveAlt
|
|
1192
|
+
}),
|
|
1193
|
+
/* @__PURE__ */ y("button", {
|
|
1194
|
+
type: "button",
|
|
1195
|
+
className: "sfa-btn",
|
|
1196
|
+
disabled: s,
|
|
1197
|
+
onClick: d,
|
|
1198
|
+
children: r.cancelAlt
|
|
1199
|
+
})
|
|
1200
|
+
]
|
|
1201
|
+
});
|
|
1202
|
+
}
|
|
1203
|
+
// src/views/products/image-tile.tsx
|
|
1204
|
+
function De({ image: e, index: t, total: n, busy: r, labels: i, onMove: a, onRemove: o, onSaveAlt: s }) {
|
|
1205
|
+
let { renderImage: c } = P(), l = e.alt || q(i.photoName, { n: String(t + 1) }), u = (t, n, r) => /* @__PURE__ */ y("button", {
|
|
1206
|
+
type: "button",
|
|
1207
|
+
className: "sfa-btn",
|
|
1208
|
+
"data-image-id": e.id,
|
|
1209
|
+
"data-move": t,
|
|
1210
|
+
"aria-label": `${n}: ${l}`,
|
|
1211
|
+
disabled: r,
|
|
1212
|
+
onClick: () => a(t),
|
|
1213
|
+
children: n
|
|
1214
|
+
});
|
|
1215
|
+
return /* @__PURE__ */ b("li", {
|
|
1216
|
+
className: "sfa-image-tile",
|
|
1217
|
+
"aria-busy": r,
|
|
1218
|
+
"data-image-id": e.id,
|
|
1219
|
+
children: [
|
|
1220
|
+
c({
|
|
1221
|
+
src: e.url,
|
|
1222
|
+
alt: e.alt,
|
|
1223
|
+
sizes: "160px",
|
|
1224
|
+
className: "sfa-image-tile__img"
|
|
1225
|
+
}),
|
|
1226
|
+
t === 0 ? /* @__PURE__ */ y("span", {
|
|
1227
|
+
className: "sfa-image-tile__cover",
|
|
1228
|
+
children: i.cover
|
|
1229
|
+
}) : null,
|
|
1230
|
+
r ? /* @__PURE__ */ y("span", {
|
|
1231
|
+
className: "sfa-spinner",
|
|
1232
|
+
role: "status",
|
|
1233
|
+
children: i.working
|
|
1234
|
+
}) : null,
|
|
1235
|
+
/* @__PURE__ */ b("div", {
|
|
1236
|
+
className: "sfa-image-tile__actions",
|
|
1237
|
+
children: [
|
|
1238
|
+
u("earlier", i.moveEarlier, t === 0),
|
|
1239
|
+
u("later", i.moveLater, t === n - 1),
|
|
1240
|
+
/* @__PURE__ */ y(Ee, {
|
|
1241
|
+
imageId: e.id,
|
|
1242
|
+
alt: e.alt,
|
|
1243
|
+
name: l,
|
|
1244
|
+
labels: i,
|
|
1245
|
+
onSave: s
|
|
1246
|
+
}),
|
|
1247
|
+
/* @__PURE__ */ y("button", {
|
|
1248
|
+
type: "button",
|
|
1249
|
+
className: "sfa-btn sfa-btn--danger",
|
|
1250
|
+
"aria-label": `${i.remove}: ${l}`,
|
|
1251
|
+
onClick: o,
|
|
1252
|
+
children: i.remove
|
|
1253
|
+
})
|
|
1254
|
+
]
|
|
1255
|
+
})
|
|
1256
|
+
]
|
|
1257
|
+
});
|
|
1258
|
+
}
|
|
1259
|
+
// src/views/products/upload-picker.tsx
|
|
1260
|
+
function Oe({ labels: e, onFiles: t }) {
|
|
1261
|
+
let n = (e) => {
|
|
1262
|
+
t(Array.from(e.target.files ?? [])), e.target.value = "";
|
|
1263
|
+
};
|
|
1264
|
+
return /* @__PURE__ */ b("div", {
|
|
1265
|
+
className: "sfa-image-picker",
|
|
1266
|
+
children: [/* @__PURE__ */ b("label", {
|
|
1267
|
+
className: "sfa-btn sfa-image-picker__btn",
|
|
1268
|
+
children: [e.add, /* @__PURE__ */ y("input", {
|
|
1269
|
+
type: "file",
|
|
1270
|
+
accept: "image/*",
|
|
1271
|
+
multiple: !0,
|
|
1272
|
+
className: "sfa-sr-only",
|
|
1273
|
+
onChange: n
|
|
1274
|
+
})]
|
|
1275
|
+
}), /* @__PURE__ */ b("label", {
|
|
1276
|
+
className: "sfa-btn sfa-image-picker__btn",
|
|
1277
|
+
children: [e.takePhoto, /* @__PURE__ */ y("input", {
|
|
1278
|
+
type: "file",
|
|
1279
|
+
accept: "image/*",
|
|
1280
|
+
capture: "environment",
|
|
1281
|
+
className: "sfa-sr-only",
|
|
1282
|
+
onChange: n
|
|
1283
|
+
})]
|
|
1284
|
+
})]
|
|
1285
|
+
});
|
|
1286
|
+
}
|
|
1287
|
+
// src/views/products/admin-product-images.tsx
|
|
1288
|
+
var J = (e) => [...e].sort((e, t) => e.position - t.position);
|
|
1289
|
+
function ke({ productId: e, images: t }) {
|
|
1290
|
+
let n = F(), { labels: r } = P(), i = r.products.images, [a, o] = _(() => J(t)), [s, c] = _(null), [l, u] = _(!1), [d, f] = _(""), [p, m] = _(void 0), [x, S] = _(!1), [C, w] = _(null), T = g(null), E = g(null), { entries: D, upload: O, dismiss: k } = Te({
|
|
1291
|
+
productId: e,
|
|
1292
|
+
onUploaded: (e) => o(J(e.images))
|
|
1293
|
+
});
|
|
1294
|
+
h(() => {
|
|
1295
|
+
let e = T.current;
|
|
1296
|
+
if (!e) return;
|
|
1297
|
+
T.current = null;
|
|
1298
|
+
let t = (t) => E.current?.querySelector(`[data-image-id="${e.id}"][data-move="${t}"]:not(:disabled)`), n = e.direction === "earlier" ? "later" : "earlier";
|
|
1299
|
+
(t(e.direction) ?? t(n))?.focus();
|
|
1300
|
+
}, [a]);
|
|
1301
|
+
let A = async (t, r) => {
|
|
1302
|
+
let i = r === "earlier" ? t - 1 : t + 1;
|
|
1303
|
+
if (l || i < 0 || i >= a.length) return;
|
|
1304
|
+
let s = a, d = [...a];
|
|
1305
|
+
[d[t], d[i]] = [d[i], d[t]], T.current = {
|
|
1306
|
+
id: a[t].id,
|
|
1307
|
+
direction: r
|
|
1308
|
+
}, o(d), u(!0), c(a[t].id), m(void 0), S(!1);
|
|
1309
|
+
try {
|
|
1310
|
+
let t = await n.reorderProductImages(e, d.map((e) => e.id));
|
|
1311
|
+
o(J(t.images));
|
|
1312
|
+
} catch (e) {
|
|
1313
|
+
T.current = {
|
|
1314
|
+
id: a[t].id,
|
|
1315
|
+
direction: r
|
|
1316
|
+
}, o(s), m(e), S(!0);
|
|
1317
|
+
} finally {
|
|
1318
|
+
u(!1), c(null);
|
|
1319
|
+
}
|
|
1320
|
+
}, j = async () => {
|
|
1321
|
+
if (!C) return;
|
|
1322
|
+
let t = C;
|
|
1323
|
+
w(null), c(t.id), m(void 0), S(!1);
|
|
1324
|
+
try {
|
|
1325
|
+
let r = await n.deleteProductImage(e, t.id);
|
|
1326
|
+
o(J(r.images));
|
|
1327
|
+
} catch (e) {
|
|
1328
|
+
m(e);
|
|
1329
|
+
} finally {
|
|
1330
|
+
c(null);
|
|
1331
|
+
}
|
|
1332
|
+
}, M = async (t, r) => {
|
|
1333
|
+
let i = await n.updateProductImage(e, t, { alt: r });
|
|
1334
|
+
o(J(i.images));
|
|
1335
|
+
};
|
|
1336
|
+
return /* @__PURE__ */ b("div", {
|
|
1337
|
+
className: "sfa-images",
|
|
1338
|
+
onDragOver: (e) => e.preventDefault(),
|
|
1339
|
+
onDrop: (e) => {
|
|
1340
|
+
e.preventDefault(), O(Array.from(e.dataTransfer.files), d);
|
|
1341
|
+
},
|
|
1342
|
+
children: [
|
|
1343
|
+
/* @__PURE__ */ y("h2", { children: i.title }),
|
|
1344
|
+
x ? /* @__PURE__ */ y(H, {
|
|
1345
|
+
variant: "error",
|
|
1346
|
+
onDismiss: () => S(!1),
|
|
1347
|
+
children: i.reorderFailed
|
|
1348
|
+
}) : /* @__PURE__ */ y(U, { error: p }),
|
|
1349
|
+
/* @__PURE__ */ b("div", {
|
|
1350
|
+
className: "sfa-field",
|
|
1351
|
+
children: [
|
|
1352
|
+
/* @__PURE__ */ y("label", {
|
|
1353
|
+
className: "sfa-field__label",
|
|
1354
|
+
htmlFor: `${e}-image-alt`,
|
|
1355
|
+
children: i.altLabel
|
|
1356
|
+
}),
|
|
1357
|
+
/* @__PURE__ */ y("input", {
|
|
1358
|
+
id: `${e}-image-alt`,
|
|
1359
|
+
value: d,
|
|
1360
|
+
onChange: (e) => f(e.target.value),
|
|
1361
|
+
onKeyDown: (e) => {
|
|
1362
|
+
e.key === "Enter" && e.preventDefault();
|
|
1363
|
+
}
|
|
1364
|
+
}),
|
|
1365
|
+
/* @__PURE__ */ y("p", {
|
|
1366
|
+
className: "sfa-field__help",
|
|
1367
|
+
children: i.altHelp
|
|
1368
|
+
}),
|
|
1369
|
+
d.trim() === "" ? /* @__PURE__ */ y("p", {
|
|
1370
|
+
className: "sfa-field__error",
|
|
1371
|
+
children: i.altWarning
|
|
1372
|
+
}) : null
|
|
1373
|
+
]
|
|
1374
|
+
}),
|
|
1375
|
+
/* @__PURE__ */ y(Oe, {
|
|
1376
|
+
labels: i,
|
|
1377
|
+
onFiles: (e) => O(e, d)
|
|
1378
|
+
}),
|
|
1379
|
+
/* @__PURE__ */ y("p", {
|
|
1380
|
+
className: "sfa-field__help",
|
|
1381
|
+
children: i.dropHint
|
|
1382
|
+
}),
|
|
1383
|
+
a.length === 0 && D.length === 0 ? /* @__PURE__ */ y("p", { children: i.empty }) : null,
|
|
1384
|
+
/* @__PURE__ */ b("ul", {
|
|
1385
|
+
ref: E,
|
|
1386
|
+
className: "sfa-image-grid",
|
|
1387
|
+
children: [a.map((e, t) => /* @__PURE__ */ y(De, {
|
|
1388
|
+
image: e,
|
|
1389
|
+
index: t,
|
|
1390
|
+
total: a.length,
|
|
1391
|
+
busy: s === e.id,
|
|
1392
|
+
labels: i,
|
|
1393
|
+
onMove: (e) => A(t, e),
|
|
1394
|
+
onRemove: () => w(e),
|
|
1395
|
+
onSaveAlt: (t) => M(e.id, t)
|
|
1396
|
+
}, e.id)), D.map((e) => /* @__PURE__ */ b("li", {
|
|
1397
|
+
className: "sfa-image-tile",
|
|
1398
|
+
"aria-busy": e.status !== "error",
|
|
1399
|
+
children: [/* @__PURE__ */ y("span", { children: e.name }), e.status === "error" ? /* @__PURE__ */ b(v, { children: [e.reason ? /* @__PURE__ */ y(H, {
|
|
1400
|
+
variant: "error",
|
|
1401
|
+
children: e.reason
|
|
1402
|
+
}) : /* @__PURE__ */ y(U, { error: e.error }), /* @__PURE__ */ y("button", {
|
|
1403
|
+
type: "button",
|
|
1404
|
+
className: "sfa-btn",
|
|
1405
|
+
onClick: () => k(e.id),
|
|
1406
|
+
children: i.dismiss
|
|
1407
|
+
})] }) : /* @__PURE__ */ y("span", {
|
|
1408
|
+
className: "sfa-spinner",
|
|
1409
|
+
role: "status",
|
|
1410
|
+
children: e.status === "uploading" ? i.uploading : i.working
|
|
1411
|
+
})]
|
|
1412
|
+
}, e.id))]
|
|
1413
|
+
}),
|
|
1414
|
+
/* @__PURE__ */ y(V, {
|
|
1415
|
+
open: C !== null,
|
|
1416
|
+
title: i.removeTitle,
|
|
1417
|
+
destructive: !0,
|
|
1418
|
+
confirmLabel: i.remove,
|
|
1419
|
+
onConfirm: j,
|
|
1420
|
+
onCancel: () => w(null),
|
|
1421
|
+
children: /* @__PURE__ */ y("p", { children: i.removeBody })
|
|
1422
|
+
})
|
|
1423
|
+
]
|
|
1424
|
+
});
|
|
1425
|
+
}
|
|
1426
|
+
// src/views/products/product-fields.tsx
|
|
1427
|
+
function Y({ name: e, label: t, error: n, help: r, children: i }) {
|
|
1428
|
+
let a = `sfa-field-${e}`, o = [r ? `${a}-help` : "", n ? `${a}-error` : ""].filter(Boolean).join(" ");
|
|
1429
|
+
return /* @__PURE__ */ b("div", {
|
|
1430
|
+
className: "sfa-field",
|
|
1431
|
+
children: [
|
|
1432
|
+
/* @__PURE__ */ y("label", {
|
|
1433
|
+
htmlFor: a,
|
|
1434
|
+
className: "sfa-field__label",
|
|
1435
|
+
children: t
|
|
1436
|
+
}),
|
|
1437
|
+
i({
|
|
1438
|
+
id: a,
|
|
1439
|
+
name: e,
|
|
1440
|
+
"aria-invalid": !!n,
|
|
1441
|
+
"aria-describedby": o || void 0
|
|
1442
|
+
}),
|
|
1443
|
+
r ? /* @__PURE__ */ y("p", {
|
|
1444
|
+
id: `${a}-help`,
|
|
1445
|
+
className: "sfa-field__help",
|
|
1446
|
+
children: r
|
|
1447
|
+
}) : null,
|
|
1448
|
+
n ? /* @__PURE__ */ y("p", {
|
|
1449
|
+
id: `${a}-error`,
|
|
1450
|
+
className: "sfa-field__error",
|
|
1451
|
+
children: n
|
|
1452
|
+
}) : null
|
|
1453
|
+
]
|
|
1454
|
+
});
|
|
1455
|
+
}
|
|
1456
|
+
var Ae = "sfa-field-category-options";
|
|
1457
|
+
function je({ form: e, errors: t, labels: n, categories: r, onChange: i }) {
|
|
1458
|
+
let a = !!r?.length, o = (r) => /* @__PURE__ */ y(Y, {
|
|
1459
|
+
name: r,
|
|
1460
|
+
label: n.fields[r],
|
|
1461
|
+
error: t[r],
|
|
1462
|
+
children: (t) => /* @__PURE__ */ y("input", {
|
|
1463
|
+
...t,
|
|
1464
|
+
type: "text",
|
|
1465
|
+
list: r === "category" && a ? Ae : void 0,
|
|
1466
|
+
value: e[r],
|
|
1467
|
+
onChange: (e) => i(r, e.target.value)
|
|
1468
|
+
})
|
|
1469
|
+
});
|
|
1470
|
+
return /* @__PURE__ */ b(v, { children: [
|
|
1471
|
+
o("name"),
|
|
1472
|
+
o("category"),
|
|
1473
|
+
a ? /* @__PURE__ */ y("datalist", {
|
|
1474
|
+
id: Ae,
|
|
1475
|
+
children: r?.map((e) => /* @__PURE__ */ y("option", { value: e }, e))
|
|
1476
|
+
}) : null,
|
|
1477
|
+
/* @__PURE__ */ y(Y, {
|
|
1478
|
+
name: "description",
|
|
1479
|
+
label: n.fields.description,
|
|
1480
|
+
error: t.description,
|
|
1481
|
+
children: (t) => /* @__PURE__ */ y("textarea", {
|
|
1482
|
+
...t,
|
|
1483
|
+
rows: 5,
|
|
1484
|
+
value: e.description,
|
|
1485
|
+
onChange: (e) => i("description", e.target.value)
|
|
1486
|
+
})
|
|
1487
|
+
}),
|
|
1488
|
+
o("materials"),
|
|
1489
|
+
o("dimensions")
|
|
1490
|
+
] });
|
|
1491
|
+
}
|
|
1492
|
+
var Me = [
|
|
1493
|
+
"draft",
|
|
1494
|
+
"active",
|
|
1495
|
+
"archived"
|
|
1496
|
+
];
|
|
1497
|
+
function Ne({ form: e, errors: t, labels: n, statusLabels: r, onChange: i }) {
|
|
1498
|
+
return /* @__PURE__ */ b(v, { children: [
|
|
1499
|
+
/* @__PURE__ */ y(Y, {
|
|
1500
|
+
name: "price",
|
|
1501
|
+
label: n.fields.price,
|
|
1502
|
+
error: t.price,
|
|
1503
|
+
help: n.priceHelp,
|
|
1504
|
+
children: (t) => /* @__PURE__ */ y("input", {
|
|
1505
|
+
...t,
|
|
1506
|
+
type: "text",
|
|
1507
|
+
inputMode: "decimal",
|
|
1508
|
+
value: e.price,
|
|
1509
|
+
onChange: (e) => i("price", e.target.value)
|
|
1510
|
+
})
|
|
1511
|
+
}),
|
|
1512
|
+
/* @__PURE__ */ y(Y, {
|
|
1513
|
+
name: "quantity",
|
|
1514
|
+
label: n.fields.quantity,
|
|
1515
|
+
error: t.quantity,
|
|
1516
|
+
children: (t) => /* @__PURE__ */ y("input", {
|
|
1517
|
+
...t,
|
|
1518
|
+
type: "text",
|
|
1519
|
+
inputMode: "numeric",
|
|
1520
|
+
value: e.quantity,
|
|
1521
|
+
onChange: (e) => i("quantity", e.target.value)
|
|
1522
|
+
})
|
|
1523
|
+
}),
|
|
1524
|
+
/* @__PURE__ */ y(Y, {
|
|
1525
|
+
name: "status",
|
|
1526
|
+
label: n.fields.status,
|
|
1527
|
+
error: t.status,
|
|
1528
|
+
help: n.statusHelp,
|
|
1529
|
+
children: (t) => /* @__PURE__ */ y("select", {
|
|
1530
|
+
...t,
|
|
1531
|
+
value: e.status,
|
|
1532
|
+
onChange: (e) => i("status", e.target.value),
|
|
1533
|
+
children: Me.map((e) => /* @__PURE__ */ y("option", {
|
|
1534
|
+
value: e,
|
|
1535
|
+
children: r[e] ?? e
|
|
1536
|
+
}, e))
|
|
1537
|
+
})
|
|
1538
|
+
}),
|
|
1539
|
+
/* @__PURE__ */ y("div", {
|
|
1540
|
+
className: "sfa-field",
|
|
1541
|
+
children: /* @__PURE__ */ b("label", {
|
|
1542
|
+
className: "sfa-check",
|
|
1543
|
+
htmlFor: "sfa-field-featured",
|
|
1544
|
+
children: [/* @__PURE__ */ y("input", {
|
|
1545
|
+
id: "sfa-field-featured",
|
|
1546
|
+
name: "featured",
|
|
1547
|
+
type: "checkbox",
|
|
1548
|
+
checked: e.featured,
|
|
1549
|
+
onChange: (e) => i("featured", e.target.checked)
|
|
1550
|
+
}), /* @__PURE__ */ y("span", { children: n.fields.featured })]
|
|
1551
|
+
})
|
|
1552
|
+
})
|
|
1553
|
+
] });
|
|
1554
|
+
}
|
|
1555
|
+
// src/views/products/admin-product-editor.tsx
|
|
1556
|
+
function Pe({ productId: e, onSaved: t, imagesSlot: n, categories: r }) {
|
|
1557
|
+
return e ? /* @__PURE__ */ y(Fe, {
|
|
1558
|
+
productId: e,
|
|
1559
|
+
onSaved: t,
|
|
1560
|
+
imagesSlot: n,
|
|
1561
|
+
categories: r
|
|
1562
|
+
}) : /* @__PURE__ */ y(Ie, {
|
|
1563
|
+
product: void 0,
|
|
1564
|
+
onSaved: t,
|
|
1565
|
+
imagesSlot: null,
|
|
1566
|
+
categories: r
|
|
1567
|
+
});
|
|
1568
|
+
}
|
|
1569
|
+
function Fe({ productId: e, onSaved: t, imagesSlot: n, categories: r }) {
|
|
1570
|
+
let i = F(), { labels: a } = P(), o = I(["admin-product", e], () => i.getProduct(e));
|
|
1571
|
+
return o.error ? /* @__PURE__ */ y(U, { error: o.error }) : o.data ? /* @__PURE__ */ y(Ie, {
|
|
1572
|
+
product: o.data,
|
|
1573
|
+
onSaved: t,
|
|
1574
|
+
imagesSlot: n,
|
|
1575
|
+
categories: r
|
|
1576
|
+
}, o.data.id) : /* @__PURE__ */ y("p", { children: a.loading });
|
|
1577
|
+
}
|
|
1578
|
+
function Ie({ product: e, onSaved: t, imagesSlot: n, categories: r }) {
|
|
1579
|
+
let i = F(), { labels: a } = P(), o = a.products, [s, c] = _(e), [u, d] = _(e ? he(e) : me), [f, p] = _({}), [m, h] = _(!1), g = (e, t) => {
|
|
1580
|
+
p(t);
|
|
1581
|
+
let n = ve(t);
|
|
1582
|
+
n && e.elements.namedItem(n)?.focus();
|
|
1583
|
+
}, v = L(async (e) => {
|
|
1584
|
+
let t = be(u, o, s?.currency);
|
|
1585
|
+
if (!t.ok) g(e, t.errors);
|
|
1586
|
+
else try {
|
|
1587
|
+
if (!s) return await i.createProduct(t.input);
|
|
1588
|
+
let e = Se(s, t.input);
|
|
1589
|
+
return Object.keys(e).length === 0 ? s : await i.updateProduct(s.id, e);
|
|
1590
|
+
} catch (t) {
|
|
1591
|
+
if (!(t instanceof l)) throw t;
|
|
1592
|
+
g(e, _e(t.issues));
|
|
1593
|
+
return;
|
|
1594
|
+
}
|
|
1595
|
+
}), x = (e, t) => {
|
|
1596
|
+
d((n) => ({
|
|
1597
|
+
...n,
|
|
1598
|
+
[e]: t
|
|
1599
|
+
})), p((t) => ({
|
|
1600
|
+
...t,
|
|
1601
|
+
[e]: void 0
|
|
1602
|
+
}));
|
|
1603
|
+
}, S = async (e) => {
|
|
1604
|
+
e.preventDefault(), h(!1), p({}), v.reset();
|
|
1605
|
+
let n = await v.run(e.currentTarget);
|
|
1606
|
+
n && (c(n), d(he(n)), h(!0), t?.(n));
|
|
1607
|
+
}, C = e ? n ?? /* @__PURE__ */ y(ke, {
|
|
1608
|
+
productId: e.id,
|
|
1609
|
+
images: e.images
|
|
1610
|
+
}) : null, w = {
|
|
1611
|
+
form: u,
|
|
1612
|
+
errors: f,
|
|
1613
|
+
labels: o,
|
|
1614
|
+
statusLabels: a.statuses,
|
|
1615
|
+
categories: r,
|
|
1616
|
+
onChange: x
|
|
1617
|
+
};
|
|
1618
|
+
return /* @__PURE__ */ b("form", {
|
|
1619
|
+
noValidate: !0,
|
|
1620
|
+
className: "sfa-form",
|
|
1621
|
+
onSubmit: S,
|
|
1622
|
+
children: [
|
|
1623
|
+
/* @__PURE__ */ y("h1", { children: e ? o.editTitle : o.createTitle }),
|
|
1624
|
+
/* @__PURE__ */ y(U, { error: v.error }),
|
|
1625
|
+
/* @__PURE__ */ y(je, { ...w }),
|
|
1626
|
+
/* @__PURE__ */ y(Ne, { ...w }),
|
|
1627
|
+
C ? /* @__PURE__ */ y("section", {
|
|
1628
|
+
"data-slot": "images",
|
|
1629
|
+
className: "sfa-form__images",
|
|
1630
|
+
children: C
|
|
1631
|
+
}) : null,
|
|
1632
|
+
/* @__PURE__ */ y("button", {
|
|
1633
|
+
type: "submit",
|
|
1634
|
+
className: "sfa-btn sfa-btn--primary",
|
|
1635
|
+
disabled: v.pending,
|
|
1636
|
+
children: a.save
|
|
1637
|
+
}),
|
|
1638
|
+
m ? /* @__PURE__ */ y(H, {
|
|
1639
|
+
variant: "success",
|
|
1640
|
+
toast: !0,
|
|
1641
|
+
onDismiss: () => h(!1),
|
|
1642
|
+
children: o.saved
|
|
1643
|
+
}) : null
|
|
1644
|
+
]
|
|
1645
|
+
});
|
|
1646
|
+
}
|
|
1647
|
+
// src/lib/use-order-pages.ts
|
|
1648
|
+
function Le(e) {
|
|
1649
|
+
let t = F(), n = I(["admin-orders", e], () => t.listOrders(e)), [r, i] = _(null), a = L(async (n, r) => {
|
|
1650
|
+
let a = await t.listOrders({
|
|
1651
|
+
...e,
|
|
1652
|
+
cursor: n
|
|
1653
|
+
});
|
|
1654
|
+
i((e) => ({
|
|
1655
|
+
base: r,
|
|
1656
|
+
items: [...e?.base === r ? e.items : [], ...a.items],
|
|
1657
|
+
nextCursor: a.nextCursor
|
|
1658
|
+
}));
|
|
1659
|
+
}), o = n.data, s = r && r.base === o ? r : null, c = s ? s.nextCursor : o?.nextCursor ?? null;
|
|
1660
|
+
return {
|
|
1661
|
+
items: [...o?.items ?? [], ...s?.items ?? []],
|
|
1662
|
+
loading: n.loading,
|
|
1663
|
+
error: n.error ?? a.error,
|
|
1664
|
+
hasMore: !n.loading && c !== null,
|
|
1665
|
+
loadingMore: a.pending,
|
|
1666
|
+
loadMore: () => {
|
|
1667
|
+
o && c && a.run(c, o);
|
|
1668
|
+
}
|
|
1669
|
+
};
|
|
1670
|
+
}
|
|
1671
|
+
// src/views/orders/admin-order-list.tsx
|
|
1672
|
+
var Re = [
|
|
1673
|
+
"paid",
|
|
1674
|
+
"shipped",
|
|
1675
|
+
"needs_attention",
|
|
1676
|
+
"pending_refund",
|
|
1677
|
+
"all"
|
|
1678
|
+
];
|
|
1679
|
+
function ze(e) {
|
|
1680
|
+
return e === "pending_refund" ? { hasPendingRefund: !0 } : e === "all" ? {} : { status: e };
|
|
1681
|
+
}
|
|
1682
|
+
function Be() {
|
|
1683
|
+
let { labels: e, locale: t, hrefs: n, renderLink: r } = P(), i = e.orders, [a, o] = _("paid"), [s, c] = _(""), l = W(s.trim(), 300), u = Le({
|
|
1684
|
+
...ze(a),
|
|
1685
|
+
...l ? { q: l } : {}
|
|
1686
|
+
}), d = new Intl.DateTimeFormat(t), f = [
|
|
1687
|
+
{
|
|
1688
|
+
key: "order",
|
|
1689
|
+
header: i.columns.order,
|
|
1690
|
+
render: (e) => r({
|
|
1691
|
+
href: n.order(e.id),
|
|
1692
|
+
children: e.id,
|
|
1693
|
+
className: "sfa-link--tap"
|
|
1694
|
+
})
|
|
1695
|
+
},
|
|
1696
|
+
{
|
|
1697
|
+
key: "status",
|
|
1698
|
+
header: i.columns.status,
|
|
1699
|
+
render: (e) => /* @__PURE__ */ y(z, { status: e.status })
|
|
1700
|
+
},
|
|
1701
|
+
{
|
|
1702
|
+
key: "email",
|
|
1703
|
+
header: i.columns.email,
|
|
1704
|
+
render: (e) => e.email ?? i.noEmail
|
|
1705
|
+
},
|
|
1706
|
+
{
|
|
1707
|
+
key: "items",
|
|
1708
|
+
header: i.columns.items,
|
|
1709
|
+
render: (e) => e.itemCount
|
|
1710
|
+
},
|
|
1711
|
+
{
|
|
1712
|
+
key: "total",
|
|
1713
|
+
header: i.columns.total,
|
|
1714
|
+
render: (e) => /* @__PURE__ */ y(B, {
|
|
1715
|
+
cents: e.totalCents,
|
|
1716
|
+
currency: e.currency
|
|
1717
|
+
})
|
|
1718
|
+
},
|
|
1719
|
+
{
|
|
1720
|
+
key: "date",
|
|
1721
|
+
header: i.columns.date,
|
|
1722
|
+
render: (e) => d.format(new Date(e.createdAt))
|
|
1723
|
+
}
|
|
1724
|
+
];
|
|
1725
|
+
return /* @__PURE__ */ b("section", {
|
|
1726
|
+
className: "sfa-orders",
|
|
1727
|
+
children: [
|
|
1728
|
+
/* @__PURE__ */ y("h1", { children: i.title }),
|
|
1729
|
+
/* @__PURE__ */ b("div", {
|
|
1730
|
+
className: "sfa-orders__toolbar",
|
|
1731
|
+
children: [/* @__PURE__ */ y("div", {
|
|
1732
|
+
role: "group",
|
|
1733
|
+
"aria-label": i.columns.status,
|
|
1734
|
+
className: "sfa-filter-group",
|
|
1735
|
+
children: Re.map((e) => /* @__PURE__ */ y("button", {
|
|
1736
|
+
type: "button",
|
|
1737
|
+
className: "sfa-btn sfa-filter",
|
|
1738
|
+
"aria-pressed": a === e,
|
|
1739
|
+
onClick: () => o(e),
|
|
1740
|
+
children: i.tabs[e]
|
|
1741
|
+
}, e))
|
|
1742
|
+
}), /* @__PURE__ */ y("input", {
|
|
1743
|
+
type: "search",
|
|
1744
|
+
"aria-label": i.searchLabel,
|
|
1745
|
+
placeholder: i.searchPlaceholder,
|
|
1746
|
+
value: s,
|
|
1747
|
+
onChange: (e) => c(e.target.value)
|
|
1748
|
+
})]
|
|
1749
|
+
}),
|
|
1750
|
+
/* @__PURE__ */ y(U, { error: u.error }),
|
|
1751
|
+
u.loading ? /* @__PURE__ */ y("p", { children: e.loading }) : u.items.length === 0 ? /* @__PURE__ */ y("p", {
|
|
1752
|
+
className: "sfa-empty",
|
|
1753
|
+
children: l ? i.noMatches : i.empty[a]
|
|
1754
|
+
}) : /* @__PURE__ */ y(R, {
|
|
1755
|
+
columns: f,
|
|
1756
|
+
rows: u.items,
|
|
1757
|
+
rowKey: (e) => e.id
|
|
1758
|
+
}),
|
|
1759
|
+
u.hasMore ? /* @__PURE__ */ y("button", {
|
|
1760
|
+
type: "button",
|
|
1761
|
+
className: "sfa-btn sfa-orders__more",
|
|
1762
|
+
disabled: u.loadingMore,
|
|
1763
|
+
onClick: u.loadMore,
|
|
1764
|
+
children: i.loadMore
|
|
1765
|
+
}) : null
|
|
1766
|
+
]
|
|
1767
|
+
});
|
|
1768
|
+
}
|
|
1769
|
+
// src/lib/refund-rules.ts
|
|
1770
|
+
function Ve(e) {
|
|
1771
|
+
return e.refunds.filter((e) => e.status === "pending").reduce((e, t) => e + t.amountCents, 0);
|
|
1772
|
+
}
|
|
1773
|
+
function X(e) {
|
|
1774
|
+
return e.totalCents - e.refundedCents - Ve(e);
|
|
1775
|
+
}
|
|
1776
|
+
function He(e) {
|
|
1777
|
+
return e.refunds.some((e) => e.status === "pending");
|
|
1778
|
+
}
|
|
1779
|
+
function Ue(e, t) {
|
|
1780
|
+
return e.status !== "needs_attention" && t !== null && t === X(e);
|
|
1781
|
+
}
|
|
1782
|
+
function We(e) {
|
|
1783
|
+
return e.status === "paid" || e.status === "shipped";
|
|
1784
|
+
}
|
|
1785
|
+
function Ge(e) {
|
|
1786
|
+
return (We(e) || e.status === "needs_attention") && X(e) > 0;
|
|
1787
|
+
}
|
|
1788
|
+
// src/views/orders/refund-dialog.tsx
|
|
1789
|
+
function Ke({ order: e, onClose: t, onDone: n }) {
|
|
1790
|
+
let r = F(), i = P().labels.orders.actions, a = g(crypto.randomUUID()), s = X(e), [l, u] = _(K(s)), [d, f] = _(""), [p, m] = _(!1), [h, v] = _(!1), x = L(r.refundOrder), S = G(l), C = S !== null && S > 0 && S <= s, w = Ue(e, S), T = x.error instanceof c || x.error instanceof o;
|
|
1791
|
+
return /* @__PURE__ */ b(V, {
|
|
1792
|
+
open: !0,
|
|
1793
|
+
title: i.refundTitle,
|
|
1794
|
+
confirmLabel: T ? i.refundRetry : i.refundSubmit,
|
|
1795
|
+
destructive: !0,
|
|
1796
|
+
pending: x.pending,
|
|
1797
|
+
onConfirm: async () => {
|
|
1798
|
+
C ? (v(!1), await x.run(e.id, {
|
|
1799
|
+
amountCents: S,
|
|
1800
|
+
reason: d.trim() || void 0,
|
|
1801
|
+
restock: p && w
|
|
1802
|
+
}, { idempotencyKey: a.current }) && n(i.refundDone)) : v(!0);
|
|
1803
|
+
},
|
|
1804
|
+
onCancel: t,
|
|
1805
|
+
children: [
|
|
1806
|
+
He(e) ? /* @__PURE__ */ y(H, {
|
|
1807
|
+
variant: "warning",
|
|
1808
|
+
children: i.refundPending
|
|
1809
|
+
}) : null,
|
|
1810
|
+
/* @__PURE__ */ b("div", {
|
|
1811
|
+
className: "sfa-field",
|
|
1812
|
+
children: [
|
|
1813
|
+
/* @__PURE__ */ y("label", {
|
|
1814
|
+
htmlFor: "sfa-refund-amount",
|
|
1815
|
+
className: "sfa-field__label",
|
|
1816
|
+
children: i.refundAmount
|
|
1817
|
+
}),
|
|
1818
|
+
/* @__PURE__ */ y("input", {
|
|
1819
|
+
id: "sfa-refund-amount",
|
|
1820
|
+
inputMode: "decimal",
|
|
1821
|
+
value: l,
|
|
1822
|
+
disabled: T,
|
|
1823
|
+
"aria-invalid": h && !C,
|
|
1824
|
+
onChange: (e) => u(e.target.value)
|
|
1825
|
+
}),
|
|
1826
|
+
h && !C ? /* @__PURE__ */ y("p", {
|
|
1827
|
+
className: "sfa-field__error",
|
|
1828
|
+
children: i.refundAmountInvalid
|
|
1829
|
+
}) : null
|
|
1830
|
+
]
|
|
1831
|
+
}),
|
|
1832
|
+
/* @__PURE__ */ b("div", {
|
|
1833
|
+
className: "sfa-field",
|
|
1834
|
+
children: [/* @__PURE__ */ y("label", {
|
|
1835
|
+
htmlFor: "sfa-refund-reason",
|
|
1836
|
+
className: "sfa-field__label",
|
|
1837
|
+
children: i.refundReason
|
|
1838
|
+
}), /* @__PURE__ */ y("textarea", {
|
|
1839
|
+
id: "sfa-refund-reason",
|
|
1840
|
+
maxLength: 500,
|
|
1841
|
+
value: d,
|
|
1842
|
+
disabled: T,
|
|
1843
|
+
onChange: (e) => f(e.target.value)
|
|
1844
|
+
})]
|
|
1845
|
+
}),
|
|
1846
|
+
w ? /* @__PURE__ */ b("div", {
|
|
1847
|
+
className: "sfa-field",
|
|
1848
|
+
children: [/* @__PURE__ */ b("label", { children: [
|
|
1849
|
+
/* @__PURE__ */ y("input", {
|
|
1850
|
+
type: "checkbox",
|
|
1851
|
+
checked: p,
|
|
1852
|
+
disabled: T,
|
|
1853
|
+
onChange: (e) => m(e.target.checked)
|
|
1854
|
+
}),
|
|
1855
|
+
" ",
|
|
1856
|
+
i.restock
|
|
1857
|
+
] }), /* @__PURE__ */ y("p", {
|
|
1858
|
+
className: "sfa-field__help",
|
|
1859
|
+
children: i.restockWarning
|
|
1860
|
+
})]
|
|
1861
|
+
}) : null,
|
|
1862
|
+
x.error instanceof o ? /* @__PURE__ */ y(H, {
|
|
1863
|
+
variant: "warning",
|
|
1864
|
+
children: i.refundUnknown
|
|
1865
|
+
}) : x.error instanceof c ? /* @__PURE__ */ y(H, {
|
|
1866
|
+
variant: "warning",
|
|
1867
|
+
children: i.refundGateway
|
|
1868
|
+
}) : /* @__PURE__ */ y(U, { error: x.error })
|
|
1869
|
+
]
|
|
1870
|
+
});
|
|
1871
|
+
}
|
|
1872
|
+
// src/views/orders/resolve-button.tsx
|
|
1873
|
+
function qe({ order: e, onDone: t }) {
|
|
1874
|
+
let n = F(), { labels: r, hrefs: i, renderLink: o } = P(), s = r.orders.actions, c = L(n.resolveOrder), l = async () => {
|
|
1875
|
+
await c.run(e.id) && t(s.resolved);
|
|
1876
|
+
}, u = c.error instanceof a ? c.error : null, d = new Map(e.items.map((e) => [e.productId, e.name]));
|
|
1877
|
+
return /* @__PURE__ */ b("div", {
|
|
1878
|
+
className: "sfa-order__action",
|
|
1879
|
+
children: [
|
|
1880
|
+
/* @__PURE__ */ y("p", { children: s.resolveHelp }),
|
|
1881
|
+
u ? /* @__PURE__ */ b(H, {
|
|
1882
|
+
variant: "error",
|
|
1883
|
+
children: [r.errors.insufficientStock, /* @__PURE__ */ y("ul", { children: u.productIds.map((e) => /* @__PURE__ */ y("li", { children: o({
|
|
1884
|
+
href: i.product(e),
|
|
1885
|
+
children: `${s.restockThenResolve}: ${d.get(e) ?? e}`,
|
|
1886
|
+
className: "sfa-link--tap"
|
|
1887
|
+
}) }, e)) })]
|
|
1888
|
+
}) : /* @__PURE__ */ y(U, { error: c.error }),
|
|
1889
|
+
/* @__PURE__ */ y("button", {
|
|
1890
|
+
type: "button",
|
|
1891
|
+
className: "sfa-btn sfa-btn--primary",
|
|
1892
|
+
disabled: c.pending,
|
|
1893
|
+
onClick: l,
|
|
1894
|
+
children: s.resolve
|
|
1895
|
+
})
|
|
1896
|
+
]
|
|
1897
|
+
});
|
|
1898
|
+
}
|
|
1899
|
+
// src/views/orders/ship-form.tsx
|
|
1900
|
+
function Je(e) {
|
|
1901
|
+
try {
|
|
1902
|
+
let { protocol: t } = new URL(e);
|
|
1903
|
+
return t === "http:" || t === "https:";
|
|
1904
|
+
} catch {
|
|
1905
|
+
return !1;
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
function Ye({ order: e, onDone: t }) {
|
|
1909
|
+
let n = F(), r = P().labels.orders.actions, i = e.fulfillment, [a, o] = _(i?.carrier ?? ""), [s, c] = _(i?.trackingNumber ?? ""), [l, u] = _(i?.trackingUrl ?? ""), [d, f] = _(!1), p = L(n.shipOrder), m = e.status === "shipped";
|
|
1910
|
+
return /* @__PURE__ */ b("form", {
|
|
1911
|
+
className: "sfa-order__action",
|
|
1912
|
+
onSubmit: async (n) => {
|
|
1913
|
+
n.preventDefault();
|
|
1914
|
+
let i = l.trim();
|
|
1915
|
+
i && !Je(i) ? f(!0) : (f(!1), await p.run(e.id, {
|
|
1916
|
+
carrier: a.trim() || void 0,
|
|
1917
|
+
trackingNumber: s.trim() || void 0,
|
|
1918
|
+
trackingUrl: i || void 0
|
|
1919
|
+
}) && t(r.shipped));
|
|
1920
|
+
},
|
|
1921
|
+
children: [
|
|
1922
|
+
/* @__PURE__ */ y("h3", { children: r.shipHeading }),
|
|
1923
|
+
/* @__PURE__ */ b("div", {
|
|
1924
|
+
className: "sfa-field",
|
|
1925
|
+
children: [/* @__PURE__ */ y("label", {
|
|
1926
|
+
htmlFor: "sfa-ship-carrier",
|
|
1927
|
+
className: "sfa-field__label",
|
|
1928
|
+
children: r.carrier
|
|
1929
|
+
}), /* @__PURE__ */ y("input", {
|
|
1930
|
+
id: "sfa-ship-carrier",
|
|
1931
|
+
value: a,
|
|
1932
|
+
onChange: (e) => o(e.target.value)
|
|
1933
|
+
})]
|
|
1934
|
+
}),
|
|
1935
|
+
/* @__PURE__ */ b("div", {
|
|
1936
|
+
className: "sfa-field",
|
|
1937
|
+
children: [/* @__PURE__ */ y("label", {
|
|
1938
|
+
htmlFor: "sfa-ship-number",
|
|
1939
|
+
className: "sfa-field__label",
|
|
1940
|
+
children: r.trackingNumber
|
|
1941
|
+
}), /* @__PURE__ */ y("input", {
|
|
1942
|
+
id: "sfa-ship-number",
|
|
1943
|
+
value: s,
|
|
1944
|
+
onChange: (e) => c(e.target.value)
|
|
1945
|
+
})]
|
|
1946
|
+
}),
|
|
1947
|
+
/* @__PURE__ */ b("div", {
|
|
1948
|
+
className: "sfa-field",
|
|
1949
|
+
children: [
|
|
1950
|
+
/* @__PURE__ */ y("label", {
|
|
1951
|
+
htmlFor: "sfa-ship-url",
|
|
1952
|
+
className: "sfa-field__label",
|
|
1953
|
+
children: r.trackingUrl
|
|
1954
|
+
}),
|
|
1955
|
+
/* @__PURE__ */ y("input", {
|
|
1956
|
+
id: "sfa-ship-url",
|
|
1957
|
+
value: l,
|
|
1958
|
+
"aria-invalid": d,
|
|
1959
|
+
"aria-describedby": d ? "sfa-ship-url-error" : void 0,
|
|
1960
|
+
onChange: (e) => u(e.target.value)
|
|
1961
|
+
}),
|
|
1962
|
+
d ? /* @__PURE__ */ y("p", {
|
|
1963
|
+
id: "sfa-ship-url-error",
|
|
1964
|
+
className: "sfa-field__error",
|
|
1965
|
+
children: r.trackingUrlInvalid
|
|
1966
|
+
}) : null
|
|
1967
|
+
]
|
|
1968
|
+
}),
|
|
1969
|
+
/* @__PURE__ */ y(U, { error: p.error }),
|
|
1970
|
+
/* @__PURE__ */ y("button", {
|
|
1971
|
+
type: "submit",
|
|
1972
|
+
className: "sfa-btn sfa-btn--primary",
|
|
1973
|
+
disabled: p.pending,
|
|
1974
|
+
children: m ? r.reship : r.ship
|
|
1975
|
+
})
|
|
1976
|
+
]
|
|
1977
|
+
});
|
|
1978
|
+
}
|
|
1979
|
+
// src/views/orders/order-actions.tsx
|
|
1980
|
+
function Xe({ order: e, reload: t }) {
|
|
1981
|
+
let n = P().labels.orders.actions, [r, i] = _(!1), [a, o] = _(null), s = (e) => {
|
|
1982
|
+
i(!1), o(e), t();
|
|
1983
|
+
};
|
|
1984
|
+
return /* @__PURE__ */ b("div", {
|
|
1985
|
+
className: "sfa-order__actions",
|
|
1986
|
+
children: [
|
|
1987
|
+
a ? /* @__PURE__ */ y(H, {
|
|
1988
|
+
variant: "success",
|
|
1989
|
+
onDismiss: () => o(null),
|
|
1990
|
+
children: a
|
|
1991
|
+
}) : null,
|
|
1992
|
+
We(e) ? /* @__PURE__ */ y(Ye, {
|
|
1993
|
+
order: e,
|
|
1994
|
+
onDone: s
|
|
1995
|
+
}) : null,
|
|
1996
|
+
e.status === "needs_attention" ? /* @__PURE__ */ y(qe, {
|
|
1997
|
+
order: e,
|
|
1998
|
+
onDone: s
|
|
1999
|
+
}) : null,
|
|
2000
|
+
Ge(e) ? /* @__PURE__ */ y("button", {
|
|
2001
|
+
type: "button",
|
|
2002
|
+
className: "sfa-btn sfa-btn--danger",
|
|
2003
|
+
onClick: () => i(!0),
|
|
2004
|
+
children: n.refund
|
|
2005
|
+
}) : null,
|
|
2006
|
+
r ? /* @__PURE__ */ y(Ke, {
|
|
2007
|
+
order: e,
|
|
2008
|
+
onClose: () => {
|
|
2009
|
+
i(!1), t();
|
|
2010
|
+
},
|
|
2011
|
+
onDone: s
|
|
2012
|
+
}) : null
|
|
2013
|
+
]
|
|
2014
|
+
});
|
|
2015
|
+
}
|
|
2016
|
+
// src/views/orders/order-fulfillment.tsx
|
|
2017
|
+
function Ze({ order: e }) {
|
|
2018
|
+
let { labels: t, locale: n, renderLink: r } = P(), i = t.orders, a = e.fulfillment;
|
|
2019
|
+
return /* @__PURE__ */ b("section", {
|
|
2020
|
+
className: "sfa-order__section",
|
|
2021
|
+
children: [/* @__PURE__ */ y("h2", { children: i.fulfillment }), a ? /* @__PURE__ */ b("dl", { children: [
|
|
2022
|
+
/* @__PURE__ */ y("dt", { children: i.shippedOn }),
|
|
2023
|
+
/* @__PURE__ */ y("dd", { children: new Intl.DateTimeFormat(n).format(new Date(a.shippedAt)) }),
|
|
2024
|
+
a.carrier ? /* @__PURE__ */ b(v, { children: [/* @__PURE__ */ y("dt", { children: i.carrier }), /* @__PURE__ */ y("dd", { children: a.carrier })] }) : null,
|
|
2025
|
+
a.trackingNumber ? /* @__PURE__ */ b(v, { children: [/* @__PURE__ */ y("dt", { children: i.tracking }), /* @__PURE__ */ y("dd", { children: a.trackingNumber })] }) : null,
|
|
2026
|
+
a.trackingUrl ? /* @__PURE__ */ y("dd", { children: r({
|
|
2027
|
+
href: a.trackingUrl,
|
|
2028
|
+
children: i.trackShipment,
|
|
2029
|
+
className: "sfa-link--tap"
|
|
2030
|
+
}) }) : null
|
|
2031
|
+
] }) : /* @__PURE__ */ y("p", { children: i.notShipped })]
|
|
2032
|
+
});
|
|
2033
|
+
}
|
|
2034
|
+
// src/views/orders/order-items.tsx
|
|
2035
|
+
function Qe({ order: e }) {
|
|
2036
|
+
let { labels: t } = P(), n = t.orders, { currency: r } = e, i = [
|
|
2037
|
+
{
|
|
2038
|
+
key: "name",
|
|
2039
|
+
header: n.itemColumns.name,
|
|
2040
|
+
render: (e) => e.name
|
|
2041
|
+
},
|
|
2042
|
+
{
|
|
2043
|
+
key: "price",
|
|
2044
|
+
header: n.itemColumns.price,
|
|
2045
|
+
render: (e) => /* @__PURE__ */ y(B, {
|
|
2046
|
+
cents: e.priceCents,
|
|
2047
|
+
currency: r
|
|
2048
|
+
})
|
|
2049
|
+
},
|
|
2050
|
+
{
|
|
2051
|
+
key: "quantity",
|
|
2052
|
+
header: n.itemColumns.quantity,
|
|
2053
|
+
render: (e) => e.quantity
|
|
2054
|
+
},
|
|
2055
|
+
{
|
|
2056
|
+
key: "line",
|
|
2057
|
+
header: n.itemColumns.line,
|
|
2058
|
+
render: (e) => /* @__PURE__ */ y(B, {
|
|
2059
|
+
cents: e.priceCents * e.quantity,
|
|
2060
|
+
currency: r
|
|
2061
|
+
})
|
|
2062
|
+
}
|
|
2063
|
+
];
|
|
2064
|
+
return /* @__PURE__ */ b("section", {
|
|
2065
|
+
className: "sfa-order__section",
|
|
2066
|
+
children: [
|
|
2067
|
+
/* @__PURE__ */ y("h2", { children: n.itemsHeading }),
|
|
2068
|
+
/* @__PURE__ */ y(R, {
|
|
2069
|
+
columns: i,
|
|
2070
|
+
rows: e.items,
|
|
2071
|
+
rowKey: (e) => e.productId
|
|
2072
|
+
}),
|
|
2073
|
+
/* @__PURE__ */ b("dl", {
|
|
2074
|
+
className: "sfa-order__totals",
|
|
2075
|
+
children: [
|
|
2076
|
+
/* @__PURE__ */ y("dt", { children: n.subtotal }),
|
|
2077
|
+
/* @__PURE__ */ y("dd", { children: /* @__PURE__ */ y(B, {
|
|
2078
|
+
cents: e.subtotalCents,
|
|
2079
|
+
currency: r
|
|
2080
|
+
}) }),
|
|
2081
|
+
e.discountCents > 0 ? /* @__PURE__ */ b(v, { children: [/* @__PURE__ */ b("dt", { children: [t.discounts.orderRow, e.discountCode ? ` (${e.discountCode})` : ""] }), /* @__PURE__ */ b("dd", { children: ["−", /* @__PURE__ */ y(B, {
|
|
2082
|
+
cents: e.discountCents,
|
|
2083
|
+
currency: r
|
|
2084
|
+
})] })] }) : null,
|
|
2085
|
+
/* @__PURE__ */ y("dt", { children: e.shippingLabel ?? n.shipping }),
|
|
2086
|
+
/* @__PURE__ */ y("dd", { children: /* @__PURE__ */ y(B, {
|
|
2087
|
+
cents: e.shippingCents,
|
|
2088
|
+
currency: r
|
|
2089
|
+
}) }),
|
|
2090
|
+
/* @__PURE__ */ y("dt", { children: n.total }),
|
|
2091
|
+
/* @__PURE__ */ y("dd", { children: /* @__PURE__ */ y(B, {
|
|
2092
|
+
cents: e.totalCents,
|
|
2093
|
+
currency: r
|
|
2094
|
+
}) })
|
|
2095
|
+
]
|
|
2096
|
+
})
|
|
2097
|
+
]
|
|
2098
|
+
});
|
|
2099
|
+
}
|
|
2100
|
+
// src/views/orders/order-refunds.tsx
|
|
2101
|
+
function $e({ order: e }) {
|
|
2102
|
+
let { labels: t, locale: n } = P(), r = t.orders, { currency: i } = e, a = new Intl.DateTimeFormat(n), o = [
|
|
2103
|
+
{
|
|
2104
|
+
key: "amount",
|
|
2105
|
+
header: r.refundColumns.amount,
|
|
2106
|
+
render: (e) => /* @__PURE__ */ y(B, {
|
|
2107
|
+
cents: e.amountCents,
|
|
2108
|
+
currency: i
|
|
2109
|
+
})
|
|
2110
|
+
},
|
|
2111
|
+
{
|
|
2112
|
+
key: "reason",
|
|
2113
|
+
header: r.refundColumns.reason,
|
|
2114
|
+
render: (e) => e.reason ?? "—"
|
|
2115
|
+
},
|
|
2116
|
+
{
|
|
2117
|
+
key: "source",
|
|
2118
|
+
header: r.refundColumns.source,
|
|
2119
|
+
render: (e) => r.refundSources[e.source]
|
|
2120
|
+
},
|
|
2121
|
+
{
|
|
2122
|
+
key: "status",
|
|
2123
|
+
header: r.refundColumns.status,
|
|
2124
|
+
render: (e) => /* @__PURE__ */ y("span", {
|
|
2125
|
+
className: `sfa-badge sfa-badge--refund-${e.status}`,
|
|
2126
|
+
"data-refund-status": e.status,
|
|
2127
|
+
children: r.refundStatuses[e.status]
|
|
2128
|
+
})
|
|
2129
|
+
},
|
|
2130
|
+
{
|
|
2131
|
+
key: "restocked",
|
|
2132
|
+
header: r.refundColumns.restocked,
|
|
2133
|
+
render: (e) => e.restocked ? r.yes : r.no
|
|
2134
|
+
},
|
|
2135
|
+
{
|
|
2136
|
+
key: "date",
|
|
2137
|
+
header: r.refundColumns.date,
|
|
2138
|
+
render: (e) => a.format(new Date(e.createdAt))
|
|
2139
|
+
}
|
|
2140
|
+
], s = e.totalCents - e.refundedCents;
|
|
2141
|
+
return /* @__PURE__ */ b("section", {
|
|
2142
|
+
className: "sfa-order__section",
|
|
2143
|
+
children: [/* @__PURE__ */ y("h2", { children: r.refunds }), e.refunds.length === 0 ? /* @__PURE__ */ y("p", { children: r.noRefunds }) : /* @__PURE__ */ b(v, { children: [/* @__PURE__ */ y(R, {
|
|
2144
|
+
columns: o,
|
|
2145
|
+
rows: e.refunds,
|
|
2146
|
+
rowKey: (e) => e.id
|
|
2147
|
+
}), /* @__PURE__ */ b("dl", {
|
|
2148
|
+
className: "sfa-order__totals",
|
|
2149
|
+
children: [
|
|
2150
|
+
/* @__PURE__ */ y("dt", { children: r.refunded }),
|
|
2151
|
+
/* @__PURE__ */ y("dd", { children: /* @__PURE__ */ y(B, {
|
|
2152
|
+
cents: e.refundedCents,
|
|
2153
|
+
currency: i
|
|
2154
|
+
}) }),
|
|
2155
|
+
/* @__PURE__ */ y("dt", { children: r.remaining }),
|
|
2156
|
+
/* @__PURE__ */ y("dd", { children: /* @__PURE__ */ y(B, {
|
|
2157
|
+
cents: s,
|
|
2158
|
+
currency: i
|
|
2159
|
+
}) })
|
|
2160
|
+
]
|
|
2161
|
+
})] })]
|
|
2162
|
+
});
|
|
2163
|
+
}
|
|
2164
|
+
// src/views/orders/admin-order-detail.tsx
|
|
2165
|
+
function et(e) {
|
|
2166
|
+
let t = e.shippingAddress;
|
|
2167
|
+
if (!t) return [];
|
|
2168
|
+
let n = [
|
|
2169
|
+
t.city,
|
|
2170
|
+
t.state,
|
|
2171
|
+
t.postalCode
|
|
2172
|
+
].filter(Boolean).join(" ");
|
|
2173
|
+
return [
|
|
2174
|
+
t.name,
|
|
2175
|
+
t.line1,
|
|
2176
|
+
t.line2,
|
|
2177
|
+
n,
|
|
2178
|
+
t.country
|
|
2179
|
+
].filter((e) => !!e);
|
|
2180
|
+
}
|
|
2181
|
+
function tt({ orderId: e, actions: t }) {
|
|
2182
|
+
let n = F(), { labels: r, locale: i, hrefs: a, renderLink: o } = P(), s = r.orders, c = I(["admin-order", e], () => n.getOrder(e));
|
|
2183
|
+
if (c.error) return /* @__PURE__ */ y(U, { error: c.error });
|
|
2184
|
+
let l = c.data;
|
|
2185
|
+
if (!l) return /* @__PURE__ */ y("p", { children: r.loading });
|
|
2186
|
+
let u = et(l);
|
|
2187
|
+
return /* @__PURE__ */ b("article", {
|
|
2188
|
+
className: "sfa-order",
|
|
2189
|
+
children: [
|
|
2190
|
+
o({
|
|
2191
|
+
href: a.orders,
|
|
2192
|
+
children: s.back,
|
|
2193
|
+
className: "sfa-link--tap"
|
|
2194
|
+
}),
|
|
2195
|
+
/* @__PURE__ */ b("header", {
|
|
2196
|
+
className: "sfa-order__header",
|
|
2197
|
+
children: [
|
|
2198
|
+
/* @__PURE__ */ b("h1", { children: [
|
|
2199
|
+
s.detailTitle,
|
|
2200
|
+
" ",
|
|
2201
|
+
l.id
|
|
2202
|
+
] }),
|
|
2203
|
+
/* @__PURE__ */ y(z, { status: l.status }),
|
|
2204
|
+
/* @__PURE__ */ b("span", { children: [
|
|
2205
|
+
s.placed,
|
|
2206
|
+
" ",
|
|
2207
|
+
new Intl.DateTimeFormat(i).format(new Date(l.createdAt))
|
|
2208
|
+
] }),
|
|
2209
|
+
/* @__PURE__ */ y(B, {
|
|
2210
|
+
cents: l.totalCents,
|
|
2211
|
+
currency: l.currency
|
|
2212
|
+
})
|
|
2213
|
+
]
|
|
2214
|
+
}),
|
|
2215
|
+
/* @__PURE__ */ b("section", {
|
|
2216
|
+
className: "sfa-order__section",
|
|
2217
|
+
children: [/* @__PURE__ */ y("h2", { children: s.buyer }), /* @__PURE__ */ y("p", { children: l.email ?? r.orders.noEmail })]
|
|
2218
|
+
}),
|
|
2219
|
+
/* @__PURE__ */ y(Qe, { order: l }),
|
|
2220
|
+
/* @__PURE__ */ b("section", {
|
|
2221
|
+
className: "sfa-order__section",
|
|
2222
|
+
children: [/* @__PURE__ */ y("h2", { children: s.shippingAddress }), u.length === 0 ? /* @__PURE__ */ y("p", { children: s.noAddress }) : /* @__PURE__ */ y("address", {
|
|
2223
|
+
className: "sfa-order__address",
|
|
2224
|
+
children: u.map((e) => /* @__PURE__ */ y("div", { children: e }, e))
|
|
2225
|
+
})]
|
|
2226
|
+
}),
|
|
2227
|
+
/* @__PURE__ */ y(Ze, { order: l }),
|
|
2228
|
+
/* @__PURE__ */ y($e, { order: l }),
|
|
2229
|
+
/* @__PURE__ */ y("section", {
|
|
2230
|
+
className: "sfa-order__section",
|
|
2231
|
+
children: t ? t({
|
|
2232
|
+
order: l,
|
|
2233
|
+
reload: c.reload
|
|
2234
|
+
}) : /* @__PURE__ */ y(Xe, {
|
|
2235
|
+
order: l,
|
|
2236
|
+
reload: c.reload
|
|
2237
|
+
})
|
|
2238
|
+
})
|
|
2239
|
+
]
|
|
2240
|
+
});
|
|
2241
|
+
}
|
|
2242
|
+
// src/lib/shipping-rates.ts
|
|
2243
|
+
var nt = 0, rt = () => `rate-${++nt}`;
|
|
2244
|
+
function it(e) {
|
|
2245
|
+
return [...e].sort((e, t) => e.sort - t.sort).map((e) => ({
|
|
2246
|
+
key: rt(),
|
|
2247
|
+
label: e.label,
|
|
2248
|
+
amount: K(e.amountCents),
|
|
2249
|
+
currency: e.currency,
|
|
2250
|
+
minDays: e.minDays == null ? "" : String(e.minDays),
|
|
2251
|
+
maxDays: e.maxDays == null ? "" : String(e.maxDays),
|
|
2252
|
+
active: e.active
|
|
2253
|
+
}));
|
|
2254
|
+
}
|
|
2255
|
+
function at(e, t) {
|
|
2256
|
+
return {
|
|
2257
|
+
key: rt(),
|
|
2258
|
+
label: t,
|
|
2259
|
+
amount: "",
|
|
2260
|
+
currency: e,
|
|
2261
|
+
minDays: "",
|
|
2262
|
+
maxDays: "",
|
|
2263
|
+
active: !0
|
|
2264
|
+
};
|
|
2265
|
+
}
|
|
2266
|
+
var Z = (e) => JSON.stringify(e.map(({ key: e, ...t }) => t));
|
|
2267
|
+
function ot(e) {
|
|
2268
|
+
let t = e.trim();
|
|
2269
|
+
return t === "" ? null : /^\d+$/.test(t) ? Number(t) : void 0;
|
|
2270
|
+
}
|
|
2271
|
+
function st(e, t) {
|
|
2272
|
+
let n = {}, r = [], i = /* @__PURE__ */ new Map();
|
|
2273
|
+
if (e.forEach((e) => {
|
|
2274
|
+
let t = e.label.trim();
|
|
2275
|
+
i.set(t, (i.get(t) ?? 0) + 1);
|
|
2276
|
+
}), e.forEach((e, a) => {
|
|
2277
|
+
let o = {}, s = e.label.trim(), c = G(e.amount), l = ot(e.minDays), u = ot(e.maxDays);
|
|
2278
|
+
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({
|
|
2279
|
+
label: s,
|
|
2280
|
+
amountCents: c ?? 0,
|
|
2281
|
+
currency: e.currency,
|
|
2282
|
+
minDays: l ?? null,
|
|
2283
|
+
maxDays: u ?? null,
|
|
2284
|
+
active: e.active,
|
|
2285
|
+
sort: a
|
|
2286
|
+
});
|
|
2287
|
+
}), Object.keys(n).length === 0) {
|
|
2288
|
+
let i = S.safeParse(r);
|
|
2289
|
+
if (!i.success) for (let r of i.error.issues) {
|
|
2290
|
+
let i = typeof r.path[0] == "number" ? e[r.path[0]]?.key : void 0;
|
|
2291
|
+
i && (n[i] = { row: t.rowInvalid });
|
|
2292
|
+
}
|
|
2293
|
+
}
|
|
2294
|
+
let a = !e.some((e) => e.active);
|
|
2295
|
+
return {
|
|
2296
|
+
rates: r,
|
|
2297
|
+
rowErrors: n,
|
|
2298
|
+
noActive: a,
|
|
2299
|
+
valid: Object.keys(n).length === 0 && !a
|
|
2300
|
+
};
|
|
2301
|
+
}
|
|
2302
|
+
var ct = {
|
|
2303
|
+
label: "label",
|
|
2304
|
+
amountCents: "amount",
|
|
2305
|
+
currency: "currency",
|
|
2306
|
+
minDays: "minDays",
|
|
2307
|
+
maxDays: "maxDays"
|
|
2308
|
+
};
|
|
2309
|
+
function lt(e, t, n) {
|
|
2310
|
+
let r = {};
|
|
2311
|
+
for (let i of e) {
|
|
2312
|
+
let e = i?.path ?? [], a = e.findIndex((e) => typeof e == "number"), o = a >= 0 ? t[e[a]]?.key : void 0;
|
|
2313
|
+
if (!o) continue;
|
|
2314
|
+
let s = e[e.length - 1], c = e.length - 1 > a && typeof s == "string" ? ct[s] : void 0;
|
|
2315
|
+
r[o] = {
|
|
2316
|
+
...r[o],
|
|
2317
|
+
[c ?? "row"]: n.rowInvalid
|
|
2318
|
+
};
|
|
2319
|
+
}
|
|
2320
|
+
return r;
|
|
2321
|
+
}
|
|
2322
|
+
// src/views/shipping/shipping-rate-row.tsx
|
|
2323
|
+
function ut({ draft: e, index: t, total: n, errors: r, disabled: i, labels: a, onChange: o, onMove: s, onRemove: c }) {
|
|
2324
|
+
let l = e.label.trim() || q(a.rowName, { n: String(t + 1) }), u = (t, n, a, s, c) => {
|
|
2325
|
+
let l = r[s], u = `${e.key}-${t}`;
|
|
2326
|
+
return /* @__PURE__ */ b("div", {
|
|
2327
|
+
className: "sfa-field",
|
|
2328
|
+
children: [
|
|
2329
|
+
/* @__PURE__ */ y("label", {
|
|
2330
|
+
className: "sfa-field__label",
|
|
2331
|
+
htmlFor: u,
|
|
2332
|
+
children: n
|
|
2333
|
+
}),
|
|
2334
|
+
/* @__PURE__ */ y("input", {
|
|
2335
|
+
id: u,
|
|
2336
|
+
value: a,
|
|
2337
|
+
inputMode: c,
|
|
2338
|
+
disabled: i,
|
|
2339
|
+
"aria-invalid": !!l,
|
|
2340
|
+
"aria-describedby": l ? `${u}-error` : void 0,
|
|
2341
|
+
onChange: (e) => o({ [s]: e.target.value })
|
|
2342
|
+
}),
|
|
2343
|
+
l ? /* @__PURE__ */ y("p", {
|
|
2344
|
+
id: `${u}-error`,
|
|
2345
|
+
className: "sfa-field__error",
|
|
2346
|
+
children: l
|
|
2347
|
+
}) : null
|
|
2348
|
+
]
|
|
2349
|
+
});
|
|
2350
|
+
};
|
|
2351
|
+
return /* @__PURE__ */ b("li", {
|
|
2352
|
+
className: "sfa-rate",
|
|
2353
|
+
"data-rate-key": e.key,
|
|
2354
|
+
children: [
|
|
2355
|
+
u("label", a.label, e.label, "label"),
|
|
2356
|
+
u("amount", a.amount, e.amount, "amount", "decimal"),
|
|
2357
|
+
/* @__PURE__ */ b("div", {
|
|
2358
|
+
className: "sfa-field",
|
|
2359
|
+
children: [
|
|
2360
|
+
/* @__PURE__ */ y("span", {
|
|
2361
|
+
className: "sfa-field__label",
|
|
2362
|
+
children: a.currency
|
|
2363
|
+
}),
|
|
2364
|
+
/* @__PURE__ */ y("span", {
|
|
2365
|
+
className: "sfa-rate__currency",
|
|
2366
|
+
"aria-invalid": !!r.currency,
|
|
2367
|
+
children: e.currency
|
|
2368
|
+
}),
|
|
2369
|
+
r.currency ? /* @__PURE__ */ y("p", {
|
|
2370
|
+
className: "sfa-field__error",
|
|
2371
|
+
children: r.currency
|
|
2372
|
+
}) : null
|
|
2373
|
+
]
|
|
2374
|
+
}),
|
|
2375
|
+
u("min", a.minDays, e.minDays, "minDays", "numeric"),
|
|
2376
|
+
u("max", a.maxDays, e.maxDays, "maxDays", "numeric"),
|
|
2377
|
+
/* @__PURE__ */ b("label", {
|
|
2378
|
+
className: "sfa-rate__active",
|
|
2379
|
+
children: [/* @__PURE__ */ y("input", {
|
|
2380
|
+
type: "checkbox",
|
|
2381
|
+
checked: e.active,
|
|
2382
|
+
disabled: i,
|
|
2383
|
+
onChange: (e) => o({ active: e.target.checked })
|
|
2384
|
+
}), a.active]
|
|
2385
|
+
}),
|
|
2386
|
+
r.row ? /* @__PURE__ */ y("p", {
|
|
2387
|
+
className: "sfa-field__error",
|
|
2388
|
+
children: r.row
|
|
2389
|
+
}) : null,
|
|
2390
|
+
/* @__PURE__ */ b("div", {
|
|
2391
|
+
className: "sfa-rate__actions",
|
|
2392
|
+
children: [
|
|
2393
|
+
/* @__PURE__ */ y("button", {
|
|
2394
|
+
type: "button",
|
|
2395
|
+
className: "sfa-btn",
|
|
2396
|
+
"aria-label": `${a.moveEarlier}: ${l}`,
|
|
2397
|
+
disabled: i || t === 0,
|
|
2398
|
+
onClick: () => s("earlier"),
|
|
2399
|
+
children: a.moveEarlier
|
|
2400
|
+
}),
|
|
2401
|
+
/* @__PURE__ */ y("button", {
|
|
2402
|
+
type: "button",
|
|
2403
|
+
className: "sfa-btn",
|
|
2404
|
+
"aria-label": `${a.moveLater}: ${l}`,
|
|
2405
|
+
disabled: i || t === n - 1,
|
|
2406
|
+
onClick: () => s("later"),
|
|
2407
|
+
children: a.moveLater
|
|
2408
|
+
}),
|
|
2409
|
+
/* @__PURE__ */ y("button", {
|
|
2410
|
+
type: "button",
|
|
2411
|
+
className: "sfa-btn sfa-btn--danger",
|
|
2412
|
+
"aria-label": `${a.remove}: ${l}`,
|
|
2413
|
+
disabled: i,
|
|
2414
|
+
onClick: c,
|
|
2415
|
+
children: a.remove
|
|
2416
|
+
})
|
|
2417
|
+
]
|
|
2418
|
+
})
|
|
2419
|
+
]
|
|
2420
|
+
});
|
|
2421
|
+
}
|
|
2422
|
+
// src/views/shipping/admin-shipping-rates.tsx
|
|
2423
|
+
function dt({ onDirtyChange: e }) {
|
|
2424
|
+
let t = F(), { labels: n, currency: r } = P(), i = n.shipping, a = I(["shipping-rates"], () => t.listShippingRates()), [o, s] = _([]), [c, u] = _("[]"), [d, f] = _(void 0), [p, m] = _(null), [v, x] = _({}), [S, C] = _(!1), [w, T] = _(!1), [E, D] = _(!1), O = L((e) => t.replaceShippingRates(e)), k = g(void 0);
|
|
2425
|
+
if (a.data && a.data !== d) {
|
|
2426
|
+
let e = it(a.data);
|
|
2427
|
+
f(a.data), s(e), u(Z(e));
|
|
2428
|
+
}
|
|
2429
|
+
let A = d !== void 0 && Z(o) !== c;
|
|
2430
|
+
h(() => {
|
|
2431
|
+
k.current !== A && (k.current = A, e?.(A));
|
|
2432
|
+
}, [A, e]);
|
|
2433
|
+
let j = (e) => {
|
|
2434
|
+
s(e), T(!1), C(!1);
|
|
2435
|
+
}, M = (e, t) => {
|
|
2436
|
+
j(o.map((n) => n.key === e ? {
|
|
2437
|
+
...n,
|
|
2438
|
+
...t
|
|
2439
|
+
} : n)), x(({ [e]: t, ...n }) => n);
|
|
2440
|
+
}, N = (e, t) => {
|
|
2441
|
+
let n = t === "earlier" ? e - 1 : e + 1;
|
|
2442
|
+
if (n < 0 || n >= o.length) return;
|
|
2443
|
+
let r = [...o];
|
|
2444
|
+
[r[e], r[n]] = [r[n], r[e]], j(r);
|
|
2445
|
+
}, ee = () => j([...o, at(r, i.newRateLabel)]), te = () => {
|
|
2446
|
+
p && (j(o.filter((e) => e.key !== p.key)), D(!0), m(null));
|
|
2447
|
+
}, R = async () => {
|
|
2448
|
+
let e = st(o, i);
|
|
2449
|
+
if (x(e.rowErrors), C(e.noActive), !e.valid) return;
|
|
2450
|
+
let t = await O.run(e.rates);
|
|
2451
|
+
if (!t) return;
|
|
2452
|
+
let n = it(t);
|
|
2453
|
+
s(n), u(Z(n)), x({}), D(!1), T(!0);
|
|
2454
|
+
}, z = o.some((e) => e.currency !== r), B = O.error instanceof l ? lt(O.error.issues, o, i) : {};
|
|
2455
|
+
return a.loading && !a.data ? /* @__PURE__ */ y("p", {
|
|
2456
|
+
role: "status",
|
|
2457
|
+
children: i.loading
|
|
2458
|
+
}) : a.data ? /* @__PURE__ */ b("div", {
|
|
2459
|
+
className: "sfa-shipping",
|
|
2460
|
+
children: [
|
|
2461
|
+
/* @__PURE__ */ y("h2", { children: i.title }),
|
|
2462
|
+
E ? /* @__PURE__ */ y(H, {
|
|
2463
|
+
variant: "warning",
|
|
2464
|
+
children: i.removalWarning
|
|
2465
|
+
}) : null,
|
|
2466
|
+
z ? /* @__PURE__ */ y(H, {
|
|
2467
|
+
variant: "warning",
|
|
2468
|
+
children: q(i.mixedCurrency, { currency: r })
|
|
2469
|
+
}) : null,
|
|
2470
|
+
S ? /* @__PURE__ */ y(H, {
|
|
2471
|
+
variant: "error",
|
|
2472
|
+
children: i.noActive
|
|
2473
|
+
}) : null,
|
|
2474
|
+
/* @__PURE__ */ y(U, { error: O.error }),
|
|
2475
|
+
w ? /* @__PURE__ */ y(H, {
|
|
2476
|
+
variant: "success",
|
|
2477
|
+
children: i.saved
|
|
2478
|
+
}) : null,
|
|
2479
|
+
A ? /* @__PURE__ */ y("p", {
|
|
2480
|
+
className: "sfa-field__help",
|
|
2481
|
+
children: i.unsaved
|
|
2482
|
+
}) : null,
|
|
2483
|
+
o.length === 0 ? /* @__PURE__ */ y("p", { children: i.empty }) : null,
|
|
2484
|
+
/* @__PURE__ */ y("ul", {
|
|
2485
|
+
className: "sfa-rates",
|
|
2486
|
+
children: o.map((e, t) => /* @__PURE__ */ y(ut, {
|
|
2487
|
+
draft: e,
|
|
2488
|
+
index: t,
|
|
2489
|
+
total: o.length,
|
|
2490
|
+
errors: {
|
|
2491
|
+
...B[e.key],
|
|
2492
|
+
...v[e.key]
|
|
2493
|
+
},
|
|
2494
|
+
disabled: O.pending,
|
|
2495
|
+
labels: i,
|
|
2496
|
+
onChange: (t) => M(e.key, t),
|
|
2497
|
+
onMove: (e) => N(t, e),
|
|
2498
|
+
onRemove: () => m(e)
|
|
2499
|
+
}, e.key))
|
|
2500
|
+
}),
|
|
2501
|
+
/* @__PURE__ */ b("div", {
|
|
2502
|
+
className: "sfa-shipping__actions",
|
|
2503
|
+
children: [/* @__PURE__ */ y("button", {
|
|
2504
|
+
type: "button",
|
|
2505
|
+
className: "sfa-btn",
|
|
2506
|
+
onClick: ee,
|
|
2507
|
+
children: i.add
|
|
2508
|
+
}), /* @__PURE__ */ y("button", {
|
|
2509
|
+
type: "button",
|
|
2510
|
+
className: "sfa-btn sfa-btn--primary",
|
|
2511
|
+
disabled: O.pending,
|
|
2512
|
+
onClick: R,
|
|
2513
|
+
children: i.save
|
|
2514
|
+
})]
|
|
2515
|
+
}),
|
|
2516
|
+
/* @__PURE__ */ y(V, {
|
|
2517
|
+
open: p !== null,
|
|
2518
|
+
title: i.removeTitle,
|
|
2519
|
+
destructive: !0,
|
|
2520
|
+
confirmLabel: i.remove,
|
|
2521
|
+
onConfirm: te,
|
|
2522
|
+
onCancel: () => m(null),
|
|
2523
|
+
children: /* @__PURE__ */ y("p", { children: i.removeBody })
|
|
2524
|
+
})
|
|
2525
|
+
]
|
|
2526
|
+
}) : /* @__PURE__ */ y(U, { error: a.error });
|
|
2527
|
+
}
|
|
2528
|
+
// src/lib/discount-status.ts
|
|
2529
|
+
function ft(e, t = /* @__PURE__ */ new Date()) {
|
|
2530
|
+
return e.active ? e.startsAt && new Date(e.startsAt) > t ? "scheduled" : e.endsAt && new Date(e.endsAt) <= t ? "expired" : "active" : "inactive";
|
|
2531
|
+
}
|
|
2532
|
+
function Q(e, t) {
|
|
2533
|
+
return e.replace(/\{(\w+)\}/g, (e, n) => n in t ? String(t[n]) : e);
|
|
2534
|
+
}
|
|
2535
|
+
// src/lib/use-discount-pages.ts
|
|
2536
|
+
function pt(e) {
|
|
2537
|
+
let t = F(), n = I(["admin-discounts", e], () => t.listDiscounts(e)), [r, i] = _(null), a = L(async (n, r) => {
|
|
2538
|
+
let a = await t.listDiscounts({
|
|
2539
|
+
...e,
|
|
2540
|
+
cursor: n
|
|
2541
|
+
});
|
|
2542
|
+
i((e) => ({
|
|
2543
|
+
base: r,
|
|
2544
|
+
items: [...e?.base === r ? e.items : [], ...a.items],
|
|
2545
|
+
nextCursor: a.nextCursor
|
|
2546
|
+
}));
|
|
2547
|
+
}), o = n.data, s = r && r.base === o ? r : null, c = s ? s.nextCursor : o?.nextCursor ?? null;
|
|
2548
|
+
return {
|
|
2549
|
+
items: [...o?.items ?? [], ...s?.items ?? []],
|
|
2550
|
+
loaded: o !== void 0,
|
|
2551
|
+
loading: n.loading,
|
|
2552
|
+
error: n.error ?? a.error,
|
|
2553
|
+
hasMore: !n.loading && c !== null,
|
|
2554
|
+
loadingMore: a.pending,
|
|
2555
|
+
reload: n.reload,
|
|
2556
|
+
loadMore: () => {
|
|
2557
|
+
o && c && a.run(c, o);
|
|
2558
|
+
}
|
|
2559
|
+
};
|
|
2560
|
+
}
|
|
2561
|
+
// src/views/discounts/discount-value.tsx
|
|
2562
|
+
function mt({ discount: e }) {
|
|
2563
|
+
return e.type === "percent" ? /* @__PURE__ */ b("span", { children: [e.percentOff, "%"] }) : /* @__PURE__ */ y(B, {
|
|
2564
|
+
cents: e.amountOffCents ?? 0,
|
|
2565
|
+
currency: e.currency ?? "USD"
|
|
2566
|
+
});
|
|
2567
|
+
}
|
|
2568
|
+
// src/views/discounts/admin-discount-list.tsx
|
|
2569
|
+
var ht = [
|
|
2570
|
+
"active",
|
|
2571
|
+
"scheduled",
|
|
2572
|
+
"expired",
|
|
2573
|
+
"inactive"
|
|
2574
|
+
];
|
|
2575
|
+
function gt() {
|
|
2576
|
+
let { labels: e, hrefs: t, renderLink: n } = P(), r = e.discounts, [i, a] = _("active"), [o, s] = _(""), c = W(o.trim(), 300), l = pt({
|
|
2577
|
+
status: i,
|
|
2578
|
+
...c ? { q: c } : {}
|
|
2579
|
+
}), u = [
|
|
2580
|
+
{
|
|
2581
|
+
key: "code",
|
|
2582
|
+
header: r.columns.code,
|
|
2583
|
+
render: (e) => n({
|
|
2584
|
+
href: t.discount(e.id),
|
|
2585
|
+
children: e.code,
|
|
2586
|
+
className: "sfa-link--tap"
|
|
2587
|
+
})
|
|
2588
|
+
},
|
|
2589
|
+
{
|
|
2590
|
+
key: "value",
|
|
2591
|
+
header: r.columns.value,
|
|
2592
|
+
render: (e) => /* @__PURE__ */ y(mt, { discount: e })
|
|
2593
|
+
},
|
|
2594
|
+
{
|
|
2595
|
+
key: "status",
|
|
2596
|
+
header: r.columns.status,
|
|
2597
|
+
render: (e) => /* @__PURE__ */ y(z, { status: ft(e) })
|
|
2598
|
+
},
|
|
2599
|
+
{
|
|
2600
|
+
key: "usage",
|
|
2601
|
+
header: r.columns.usage,
|
|
2602
|
+
render: (e) => {
|
|
2603
|
+
let t = e.redeemedCount + e.reservedCount;
|
|
2604
|
+
return e.maxRedemptions ? Q(r.usage, {
|
|
2605
|
+
used: t,
|
|
2606
|
+
max: e.maxRedemptions
|
|
2607
|
+
}) : Q(r.usageUnlimited, { used: t });
|
|
2608
|
+
}
|
|
2609
|
+
}
|
|
2610
|
+
];
|
|
2611
|
+
return /* @__PURE__ */ b("section", {
|
|
2612
|
+
className: "sfa-products",
|
|
2613
|
+
children: [
|
|
2614
|
+
/* @__PURE__ */ b("header", {
|
|
2615
|
+
className: "sfa-products__header",
|
|
2616
|
+
children: [/* @__PURE__ */ y("h1", { children: r.title }), n({
|
|
2617
|
+
href: t.newDiscount,
|
|
2618
|
+
children: r.newDiscount,
|
|
2619
|
+
className: "sfa-btn sfa-btn--primary"
|
|
2620
|
+
})]
|
|
2621
|
+
}),
|
|
2622
|
+
/* @__PURE__ */ b("div", {
|
|
2623
|
+
className: "sfa-products__toolbar",
|
|
2624
|
+
children: [/* @__PURE__ */ y("div", {
|
|
2625
|
+
role: "group",
|
|
2626
|
+
"aria-label": r.columns.status,
|
|
2627
|
+
className: "sfa-filter-group",
|
|
2628
|
+
children: ht.map((e) => /* @__PURE__ */ y("button", {
|
|
2629
|
+
type: "button",
|
|
2630
|
+
className: "sfa-btn sfa-filter",
|
|
2631
|
+
"aria-pressed": i === e,
|
|
2632
|
+
onClick: () => a(e),
|
|
2633
|
+
children: r.tabs[e]
|
|
2634
|
+
}, e))
|
|
2635
|
+
}), /* @__PURE__ */ y("input", {
|
|
2636
|
+
type: "search",
|
|
2637
|
+
"aria-label": r.searchLabel,
|
|
2638
|
+
placeholder: r.searchPlaceholder,
|
|
2639
|
+
value: o,
|
|
2640
|
+
onChange: (e) => s(e.target.value)
|
|
2641
|
+
})]
|
|
2642
|
+
}),
|
|
2643
|
+
/* @__PURE__ */ y(U, { error: l.error }),
|
|
2644
|
+
l.loading && !l.loaded ? /* @__PURE__ */ y("p", { children: e.loading }) : l.items.length === 0 ? /* @__PURE__ */ y("p", {
|
|
2645
|
+
className: "sfa-empty",
|
|
2646
|
+
children: c ? r.noMatches : r.empty[i]
|
|
2647
|
+
}) : /* @__PURE__ */ y(R, {
|
|
2648
|
+
columns: u,
|
|
2649
|
+
rows: l.items,
|
|
2650
|
+
rowKey: (e) => e.id
|
|
2651
|
+
}),
|
|
2652
|
+
l.hasMore ? /* @__PURE__ */ y("button", {
|
|
2653
|
+
type: "button",
|
|
2654
|
+
className: "sfa-btn sfa-products__more",
|
|
2655
|
+
disabled: l.loadingMore,
|
|
2656
|
+
onClick: l.loadMore,
|
|
2657
|
+
children: r.loadMore
|
|
2658
|
+
}) : null
|
|
2659
|
+
]
|
|
2660
|
+
});
|
|
2661
|
+
}
|
|
2662
|
+
// src/lib/discount-form.ts
|
|
2663
|
+
var _t = {
|
|
2664
|
+
code: "",
|
|
2665
|
+
type: "percent",
|
|
2666
|
+
percentOff: "",
|
|
2667
|
+
amountOff: "",
|
|
2668
|
+
minSubtotal: "",
|
|
2669
|
+
startsAt: "",
|
|
2670
|
+
endsAt: "",
|
|
2671
|
+
maxRedemptions: ""
|
|
2672
|
+
}, $ = (e) => String(e).padStart(2, "0");
|
|
2673
|
+
function vt(e) {
|
|
2674
|
+
if (!e) return "";
|
|
2675
|
+
let t = new Date(e);
|
|
2676
|
+
return Number.isNaN(t.getTime()) ? "" : `${t.getFullYear()}-${$(t.getMonth() + 1)}-${$(t.getDate())}T${$(t.getHours())}:${$(t.getMinutes())}`;
|
|
2677
|
+
}
|
|
2678
|
+
function yt(e) {
|
|
2679
|
+
if (e.trim() === "") return null;
|
|
2680
|
+
let t = new Date(e);
|
|
2681
|
+
return Number.isNaN(t.getTime()) ? null : t.toISOString();
|
|
2682
|
+
}
|
|
2683
|
+
function bt(e) {
|
|
2684
|
+
return {
|
|
2685
|
+
code: e.code,
|
|
2686
|
+
type: e.type,
|
|
2687
|
+
percentOff: e.percentOff ? String(e.percentOff) : "",
|
|
2688
|
+
amountOff: e.amountOffCents ? K(e.amountOffCents) : "",
|
|
2689
|
+
minSubtotal: e.minSubtotalCents ? K(e.minSubtotalCents) : "",
|
|
2690
|
+
startsAt: vt(e.startsAt),
|
|
2691
|
+
endsAt: vt(e.endsAt),
|
|
2692
|
+
maxRedemptions: e.maxRedemptions ? String(e.maxRedemptions) : ""
|
|
2693
|
+
};
|
|
2694
|
+
}
|
|
2695
|
+
function xt(e) {
|
|
2696
|
+
return !!(e && e.redeemedCount + e.reservedCount > 0);
|
|
2697
|
+
}
|
|
2698
|
+
var St = (e) => /^\d+$/.test(e.trim()) && Number(e) > 0 ? Number(e) : null;
|
|
2699
|
+
function Ct(e, t, n, r = 0) {
|
|
2700
|
+
let i = t.validation, a = {}, o = e.code.trim().toUpperCase();
|
|
2701
|
+
/^[A-Z0-9_-]{1,40}$/.test(o) || (a.code = i.code);
|
|
2702
|
+
let s = St(e.percentOff), c = G(e.amountOff);
|
|
2703
|
+
e.type === "percent" && (s === null || s > 100) && (a.percentOff = i.percentOff), e.type === "fixed" && !c && (a.amountOff = i.amountOff);
|
|
2704
|
+
let l = e.minSubtotal.trim(), u = l === "" ? null : G(l);
|
|
2705
|
+
l !== "" && !u && (a.minSubtotal = i.minSubtotal);
|
|
2706
|
+
let d = e.maxRedemptions.trim(), f = d === "" ? null : St(d);
|
|
2707
|
+
d !== "" && f === null ? a.maxRedemptions = i.maxRedemptions : f !== null && f < r && (a.maxRedemptions = i.maxRedemptionsBelowUsage);
|
|
2708
|
+
let p = yt(e.startsAt), m = yt(e.endsAt);
|
|
2709
|
+
return e.startsAt.trim() !== "" && !p && (a.startsAt = i.date), e.endsAt.trim() !== "" && !m && (a.endsAt = i.date), p && m && new Date(m) <= new Date(p) && (a.endsAt = i.endsBeforeStart), Object.keys(a).length > 0 ? {
|
|
2710
|
+
ok: !1,
|
|
2711
|
+
errors: a
|
|
2712
|
+
} : {
|
|
2713
|
+
ok: !0,
|
|
2714
|
+
input: {
|
|
2715
|
+
code: o,
|
|
2716
|
+
type: e.type,
|
|
2717
|
+
percentOff: e.type === "percent" ? s : null,
|
|
2718
|
+
amountOffCents: e.type === "fixed" ? c : null,
|
|
2719
|
+
currency: e.type === "fixed" ? n : null,
|
|
2720
|
+
minSubtotalCents: u,
|
|
2721
|
+
startsAt: p,
|
|
2722
|
+
endsAt: m,
|
|
2723
|
+
maxRedemptions: f,
|
|
2724
|
+
active: !0
|
|
2725
|
+
}
|
|
2726
|
+
};
|
|
2727
|
+
}
|
|
2728
|
+
var wt = [
|
|
2729
|
+
"type",
|
|
2730
|
+
"percentOff",
|
|
2731
|
+
"amountOffCents",
|
|
2732
|
+
"currency"
|
|
2733
|
+
], Tt = [
|
|
2734
|
+
"minSubtotalCents",
|
|
2735
|
+
"startsAt",
|
|
2736
|
+
"endsAt",
|
|
2737
|
+
"maxRedemptions"
|
|
2738
|
+
];
|
|
2739
|
+
function Et(e, t, n) {
|
|
2740
|
+
let r = {}, i = t, a = e, o = (e) => (i[e] ?? null) !== (a[e] ?? null);
|
|
2741
|
+
for (let e of Tt) o(e) && (r[e] = i[e]);
|
|
2742
|
+
if (n) return r;
|
|
2743
|
+
if (o("code") && (r.code = t.code), wt.some(o)) for (let e of wt) r[e] = i[e];
|
|
2744
|
+
return r;
|
|
2745
|
+
}
|
|
2746
|
+
function Dt(e, t) {
|
|
2747
|
+
let n = {
|
|
2748
|
+
code: "code",
|
|
2749
|
+
percentOff: "percentOff",
|
|
2750
|
+
amountOffCents: "amountOff",
|
|
2751
|
+
minSubtotalCents: "minSubtotal",
|
|
2752
|
+
startsAt: "startsAt",
|
|
2753
|
+
endsAt: "endsAt",
|
|
2754
|
+
maxRedemptions: "maxRedemptions"
|
|
2755
|
+
}, r = {};
|
|
2756
|
+
for (let i of e) {
|
|
2757
|
+
let e = i?.path?.[0], a = typeof e == "string" ? n[e] : void 0;
|
|
2758
|
+
a && !r[a] && (r[a] = t);
|
|
2759
|
+
}
|
|
2760
|
+
return r;
|
|
2761
|
+
}
|
|
2762
|
+
// src/views/discounts/discount-fields.tsx
|
|
2763
|
+
function Ot({ name: e, label: t, error: n, help: r, disabled: i, children: a }) {
|
|
2764
|
+
let o = `sfa-field-${e}`, s = [r ? `${o}-help` : "", n ? `${o}-error` : ""].filter(Boolean).join(" ");
|
|
2765
|
+
return /* @__PURE__ */ b("div", {
|
|
2766
|
+
className: "sfa-field",
|
|
2767
|
+
children: [
|
|
2768
|
+
/* @__PURE__ */ y("label", {
|
|
2769
|
+
htmlFor: o,
|
|
2770
|
+
className: "sfa-field__label",
|
|
2771
|
+
children: t
|
|
2772
|
+
}),
|
|
2773
|
+
a({
|
|
2774
|
+
id: o,
|
|
2775
|
+
name: e,
|
|
2776
|
+
disabled: !!i,
|
|
2777
|
+
"aria-invalid": !!n,
|
|
2778
|
+
"aria-describedby": s || void 0
|
|
2779
|
+
}),
|
|
2780
|
+
r ? /* @__PURE__ */ y("p", {
|
|
2781
|
+
id: `${o}-help`,
|
|
2782
|
+
className: "sfa-field__help",
|
|
2783
|
+
children: r
|
|
2784
|
+
}) : null,
|
|
2785
|
+
n ? /* @__PURE__ */ y("p", {
|
|
2786
|
+
id: `${o}-error`,
|
|
2787
|
+
className: "sfa-field__error",
|
|
2788
|
+
children: n
|
|
2789
|
+
}) : null
|
|
2790
|
+
]
|
|
2791
|
+
});
|
|
2792
|
+
}
|
|
2793
|
+
var kt = ["percent", "fixed"];
|
|
2794
|
+
function At({ form: e, errors: t, labels: n, usedCount: r, onChange: i }) {
|
|
2795
|
+
let a = r > 0, o = a ? Q(n.lockedHelp, { count: r }) : void 0, s = (n, r, a = {}) => /* @__PURE__ */ y(Ot, {
|
|
2796
|
+
name: n,
|
|
2797
|
+
label: r,
|
|
2798
|
+
error: t[n],
|
|
2799
|
+
help: a.help,
|
|
2800
|
+
disabled: a.locked,
|
|
2801
|
+
children: (t) => /* @__PURE__ */ y("input", {
|
|
2802
|
+
...t,
|
|
2803
|
+
type: "text",
|
|
2804
|
+
inputMode: a.inputMode,
|
|
2805
|
+
value: e[n],
|
|
2806
|
+
onChange: (e) => i(n, e.target.value)
|
|
2807
|
+
})
|
|
2808
|
+
}), c = (r) => /* @__PURE__ */ y(Ot, {
|
|
2809
|
+
name: r,
|
|
2810
|
+
label: n.fields[r],
|
|
2811
|
+
error: t[r],
|
|
2812
|
+
help: n.optionalHelp,
|
|
2813
|
+
children: (t) => /* @__PURE__ */ y("input", {
|
|
2814
|
+
...t,
|
|
2815
|
+
type: "datetime-local",
|
|
2816
|
+
value: e[r],
|
|
2817
|
+
onChange: (e) => i(r, e.target.value)
|
|
2818
|
+
})
|
|
2819
|
+
});
|
|
2820
|
+
return /* @__PURE__ */ b(v, { children: [
|
|
2821
|
+
s("code", n.fields.code, {
|
|
2822
|
+
help: o,
|
|
2823
|
+
locked: a
|
|
2824
|
+
}),
|
|
2825
|
+
/* @__PURE__ */ y(Ot, {
|
|
2826
|
+
name: "type",
|
|
2827
|
+
label: n.fields.type,
|
|
2828
|
+
disabled: a,
|
|
2829
|
+
children: (t) => /* @__PURE__ */ y("select", {
|
|
2830
|
+
...t,
|
|
2831
|
+
value: e.type,
|
|
2832
|
+
onChange: (e) => i("type", e.target.value),
|
|
2833
|
+
children: kt.map((e) => /* @__PURE__ */ y("option", {
|
|
2834
|
+
value: e,
|
|
2835
|
+
children: n.types[e]
|
|
2836
|
+
}, e))
|
|
2837
|
+
})
|
|
2838
|
+
}),
|
|
2839
|
+
e.type === "percent" ? s("percentOff", n.fields.percentOff, {
|
|
2840
|
+
locked: a,
|
|
2841
|
+
inputMode: "numeric"
|
|
2842
|
+
}) : s("amountOff", n.fields.amountOff, {
|
|
2843
|
+
locked: a,
|
|
2844
|
+
inputMode: "decimal"
|
|
2845
|
+
}),
|
|
2846
|
+
s("minSubtotal", n.fields.minSubtotal, {
|
|
2847
|
+
help: n.optionalHelp,
|
|
2848
|
+
inputMode: "decimal"
|
|
2849
|
+
}),
|
|
2850
|
+
c("startsAt"),
|
|
2851
|
+
c("endsAt"),
|
|
2852
|
+
s("maxRedemptions", n.fields.maxRedemptions, {
|
|
2853
|
+
help: n.optionalHelp,
|
|
2854
|
+
inputMode: "numeric"
|
|
2855
|
+
})
|
|
2856
|
+
] });
|
|
2857
|
+
}
|
|
2858
|
+
// src/views/discounts/admin-discount-editor.tsx
|
|
2859
|
+
function jt({ discountId: e, onSaved: t }) {
|
|
2860
|
+
return e ? /* @__PURE__ */ y(Mt, {
|
|
2861
|
+
discountId: e,
|
|
2862
|
+
onSaved: t
|
|
2863
|
+
}) : /* @__PURE__ */ y(Nt, {
|
|
2864
|
+
discount: void 0,
|
|
2865
|
+
onSaved: t
|
|
2866
|
+
});
|
|
2867
|
+
}
|
|
2868
|
+
function Mt({ discountId: e, onSaved: t }) {
|
|
2869
|
+
let n = F(), { labels: r } = P(), i = I(["admin-discount", e], () => n.getDiscount(e));
|
|
2870
|
+
return i.error ? /* @__PURE__ */ y(U, { error: i.error }) : i.data ? /* @__PURE__ */ y(Nt, {
|
|
2871
|
+
discount: i.data,
|
|
2872
|
+
onSaved: t
|
|
2873
|
+
}, i.data.id) : /* @__PURE__ */ y("p", { children: r.loading });
|
|
2874
|
+
}
|
|
2875
|
+
function Nt({ discount: e, onSaved: t }) {
|
|
2876
|
+
let n = F(), { labels: r, currency: i } = P(), a = r.discounts, [o, c] = _(e), [u, d] = _(e ? bt(e) : _t), [f, p] = _({}), [m, h] = _(!1), [g, v] = _(!1), x = o ? o.redeemedCount + o.reservedCount : 0, S = xt(o), C = (e, t) => {
|
|
2877
|
+
p(t);
|
|
2878
|
+
let n = Object.keys(t)[0];
|
|
2879
|
+
n && e.elements.namedItem(n)?.focus();
|
|
2880
|
+
}, w = L(async (e) => {
|
|
2881
|
+
let t = Ct(u, a, o?.currency ?? i, x);
|
|
2882
|
+
if (!t.ok) C(e, t.errors);
|
|
2883
|
+
else try {
|
|
2884
|
+
if (!o) return await n.createDiscount(t.input);
|
|
2885
|
+
let e = Et(o, t.input, S);
|
|
2886
|
+
return Object.keys(e).length === 0 ? o : await n.updateDiscount(o.id, e);
|
|
2887
|
+
} catch (t) {
|
|
2888
|
+
if (t instanceof s) {
|
|
2889
|
+
C(e, { code: a.validation.codeTaken });
|
|
2890
|
+
return;
|
|
2891
|
+
}
|
|
2892
|
+
if (!(t instanceof l)) throw t;
|
|
2893
|
+
C(e, Dt(t.issues, a.validation.invalid));
|
|
2894
|
+
return;
|
|
2895
|
+
}
|
|
2896
|
+
}), T = L((e) => {
|
|
2897
|
+
if (!o) throw Error("Discount has not been created yet.");
|
|
2898
|
+
return n.updateDiscount(o.id, { active: e });
|
|
2899
|
+
}), E = (e) => {
|
|
2900
|
+
c(e), d(bt(e)), h(!0), t?.(e);
|
|
2901
|
+
}, D = (e, t) => {
|
|
2902
|
+
d((n) => ({
|
|
2903
|
+
...n,
|
|
2904
|
+
[e]: t
|
|
2905
|
+
})), p((t) => ({
|
|
2906
|
+
...t,
|
|
2907
|
+
[e]: void 0
|
|
2908
|
+
}));
|
|
2909
|
+
}, O = async (e) => {
|
|
2910
|
+
e.preventDefault(), h(!1), p({}), w.reset();
|
|
2911
|
+
let t = await w.run(e.currentTarget);
|
|
2912
|
+
t && E(t);
|
|
2913
|
+
}, k = async (e) => {
|
|
2914
|
+
v(!1), h(!1);
|
|
2915
|
+
let t = await T.run(e);
|
|
2916
|
+
t && E(t);
|
|
2917
|
+
};
|
|
2918
|
+
return /* @__PURE__ */ b("form", {
|
|
2919
|
+
noValidate: !0,
|
|
2920
|
+
className: "sfa-form",
|
|
2921
|
+
onSubmit: O,
|
|
2922
|
+
children: [
|
|
2923
|
+
/* @__PURE__ */ y("h1", { children: o ? a.editTitle : a.createTitle }),
|
|
2924
|
+
/* @__PURE__ */ y(U, { error: w.error ?? T.error }),
|
|
2925
|
+
/* @__PURE__ */ y(At, {
|
|
2926
|
+
form: u,
|
|
2927
|
+
errors: f,
|
|
2928
|
+
labels: a,
|
|
2929
|
+
usedCount: x,
|
|
2930
|
+
onChange: D
|
|
2931
|
+
}),
|
|
2932
|
+
/* @__PURE__ */ b("div", {
|
|
2933
|
+
className: "sfa-row-actions",
|
|
2934
|
+
children: [
|
|
2935
|
+
/* @__PURE__ */ y("button", {
|
|
2936
|
+
type: "submit",
|
|
2937
|
+
className: "sfa-btn sfa-btn--primary",
|
|
2938
|
+
disabled: w.pending,
|
|
2939
|
+
children: r.save
|
|
2940
|
+
}),
|
|
2941
|
+
o?.active ? /* @__PURE__ */ y("button", {
|
|
2942
|
+
type: "button",
|
|
2943
|
+
className: "sfa-btn",
|
|
2944
|
+
onClick: () => v(!0),
|
|
2945
|
+
children: a.deactivate
|
|
2946
|
+
}) : null,
|
|
2947
|
+
o && !o.active ? /* @__PURE__ */ y("button", {
|
|
2948
|
+
type: "button",
|
|
2949
|
+
className: "sfa-btn",
|
|
2950
|
+
disabled: T.pending,
|
|
2951
|
+
onClick: () => k(!0),
|
|
2952
|
+
children: a.reactivate
|
|
2953
|
+
}) : null
|
|
2954
|
+
]
|
|
2955
|
+
}),
|
|
2956
|
+
/* @__PURE__ */ y(V, {
|
|
2957
|
+
open: g,
|
|
2958
|
+
title: a.deactivateTitle,
|
|
2959
|
+
confirmLabel: a.deactivate,
|
|
2960
|
+
destructive: !0,
|
|
2961
|
+
pending: T.pending,
|
|
2962
|
+
onConfirm: () => k(!1),
|
|
2963
|
+
onCancel: () => v(!1),
|
|
2964
|
+
children: /* @__PURE__ */ y("p", { children: a.deactivateBody })
|
|
2965
|
+
}),
|
|
2966
|
+
m ? /* @__PURE__ */ y(H, {
|
|
2967
|
+
variant: "success",
|
|
2968
|
+
toast: !0,
|
|
2969
|
+
onDismiss: () => h(!1),
|
|
2970
|
+
children: a.saved
|
|
2971
|
+
}) : null
|
|
2972
|
+
]
|
|
2973
|
+
});
|
|
2974
|
+
}
|
|
2975
|
+
export { jt as AdminDiscountEditor, gt as AdminDiscountList, te as AdminLayout, tt as AdminOrderDetail, Be as AdminOrderList, Pe as AdminProductEditor, ke as AdminProductImages, de as AdminProductList, ee as AdminProvider, dt as AdminShippingRates, R as AdminTable, V as ConfirmDialog, U as ErrorMessage, B as Money, H as Notice, Xe as OrderActions, z as StatusBadge, ie as errorKey, K as formatMoneyInput, G as parseMoneyInput, P as useAdmin, F as useAdminClient, L as useAdminMutation, I as useAdminQuery };
|
|
2976
|
+
|
|
2977
|
+
//# sourceMappingURL=index.js.map
|