@zeyolabs/shopping 2026.11.37 → 2026.11.39
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/basket/client.remote.ts +16 -2
- package/basket/cookies.server.ts +13 -1
- package/basket/library.ts +58 -0
- package/basket/pages/Basket.svelte +80 -30
- package/basket/service.server.ts +139 -6
- package/bundles/admin/BundleEditPage.svelte +7 -4
- package/bundles/admin/BundleForm.svelte +50 -11
- package/bundles/admin/BundlesPage.svelte +14 -10
- package/bundles/client.remote.ts +18 -6
- package/bundles/library.ts +51 -0
- package/bundles/pages/Bundle.svelte +233 -68
- package/bundles/schema.ts +13 -2
- package/bundles/service.server.ts +185 -33
- package/catalogue/admin/CategoriesPage.svelte +13 -10
- package/catalogue/admin/CategoryForm.svelte +4 -3
- package/catalogue/admin/ProductEditPage.svelte +7 -4
- package/catalogue/admin/ProductForm.svelte +31 -29
- package/catalogue/admin/ProductsPage.svelte +16 -14
- package/catalogue/client.remote.ts +23 -9
- package/catalogue/components/ProductCard.svelte +22 -14
- package/catalogue/library.ts +91 -0
- package/catalogue/loads.server.ts +8 -4
- package/catalogue/pages/Category.svelte +15 -6
- package/catalogue/pages/Product.svelte +164 -45
- package/catalogue/pages/Search.svelte +12 -7
- package/catalogue/pages/Shop.svelte +12 -12
- package/catalogue/service.server.ts +44 -9
- package/checkout/manager.server.ts +68 -16
- package/checkout/pages/CheckoutSuccess.svelte +10 -8
- package/customers/pages/Account.svelte +19 -15
- package/db/schema.ts +27 -3
- package/fulfilment/admin/OrderPage.svelte +60 -56
- package/fulfilment/admin/OrdersPage.svelte +26 -22
- package/orders/manager.server.ts +45 -11
- package/orders/pages/Order.svelte +35 -29
- package/orders/service.server.ts +25 -3
- package/package.json +5 -4
- package/reviews/admin/ReviewsPage.svelte +23 -19
- package/reviews/components/ReviewForm.svelte +3 -2
- package/reviews/components/Reviews.svelte +17 -13
- package/stock/admin/StockPage.svelte +12 -9
- package/stock/admin/StockRow.svelte +3 -2
- package/stock/service.server.ts +6 -1
- package/ui/PageLinks.svelte +45 -0
- package/ui/PageTitle.svelte +20 -4
- package/ui/Stars.svelte +3 -1
|
@@ -2,16 +2,20 @@
|
|
|
2
2
|
import { goto } from '$app/navigation';
|
|
3
3
|
import { resolve } from '$app/paths';
|
|
4
4
|
import { page } from '$app/state';
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import { ErrorMessage } from '../../utils/errors';
|
|
8
|
-
import { toast } from 'svelte-sonner';
|
|
5
|
+
import Badge from '@zeyolabs/ui/badge/Badge.svelte';
|
|
6
|
+
import Boundary from '@zeyolabs/ui/boundary/Boundary.svelte';
|
|
9
7
|
import Button from '@zeyolabs/ui/form/Button.svelte';
|
|
10
|
-
import
|
|
8
|
+
import Span from '@zeyolabs/ui/text/Span.svelte';
|
|
9
|
+
import Text from '@zeyolabs/ui/text/Text.svelte';
|
|
10
|
+
import Title from '@zeyolabs/ui/text/Title.svelte';
|
|
11
|
+
import { toast } from 'svelte-sonner';
|
|
11
12
|
import { SvelteSet, SvelteURLSearchParams } from 'svelte/reactivity';
|
|
13
|
+
|
|
14
|
+
import { ErrorMessage } from '../../utils/errors';
|
|
15
|
+
import { Money } from '../../utils/money';
|
|
16
|
+
import { dispatchOrders, getOrderCounts, getOrders, getReadyByService } from '../admin.remote';
|
|
17
|
+
import { BULK_DISPATCH_LIMIT, FILTER_LABELS, ORDER_FILTERS, type OrderFilter } from '../filters';
|
|
12
18
|
import { Packing } from '../library';
|
|
13
|
-
import Badge from '@zeyolabs/ui/badge/Badge.svelte';
|
|
14
|
-
import Boundary from '@zeyolabs/ui/boundary/Boundary.svelte';
|
|
15
19
|
|
|
16
20
|
const filter = $derived.by((): OrderFilter => {
|
|
17
21
|
const value = page.url.searchParams.get('filter');
|
|
@@ -80,15 +84,15 @@
|
|
|
80
84
|
|
|
81
85
|
<svelte:head><title>Orders · Admin</title></svelte:head>
|
|
82
86
|
|
|
83
|
-
<
|
|
87
|
+
<Title level={1} size="md">Orders</Title>
|
|
84
88
|
|
|
85
89
|
<nav class="mt-4 flex flex-wrap items-center gap-2" aria-label="Order filter">
|
|
86
90
|
{#each ORDER_FILTERS as f (f)}
|
|
87
91
|
<!-- eslint-disable svelte/no-navigation-without-resolve -- href() resolves the path -->
|
|
88
92
|
<a
|
|
89
93
|
class="rounded-full border px-3 py-1 text-sm no-underline {f === filter
|
|
90
|
-
? 'border-[var(--
|
|
91
|
-
: 'border-[var(--
|
|
94
|
+
? 'border-[var(--acc)] bg-[var(--acc)] text-white'
|
|
95
|
+
: 'border-[var(--bd)] bg-white text-[var(--tx)]'}"
|
|
92
96
|
aria-current={f === filter ? 'page' : undefined}
|
|
93
97
|
href={href({ filter: f })}
|
|
94
98
|
>
|
|
@@ -99,8 +103,10 @@
|
|
|
99
103
|
{/each}
|
|
100
104
|
<Boundary message="Could not load ready counts.">
|
|
101
105
|
{#each Object.entries(await getReadyByService()) as [service, n] (service)}
|
|
102
|
-
<
|
|
106
|
+
<Span color="secondary">{service}: {n} ready</Span>
|
|
103
107
|
{/each}
|
|
108
|
+
|
|
109
|
+
{#snippet pending()}{/snippet}
|
|
104
110
|
</Boundary>
|
|
105
111
|
<form
|
|
106
112
|
class="ml-auto"
|
|
@@ -113,7 +119,7 @@
|
|
|
113
119
|
>
|
|
114
120
|
<input
|
|
115
121
|
name="q"
|
|
116
|
-
class="w-56 rounded-md border border-[var(--
|
|
122
|
+
class="w-56 rounded-md border border-[var(--bd)] px-3 py-1.5 text-sm"
|
|
117
123
|
placeholder="Order, email or name"
|
|
118
124
|
type="search"
|
|
119
125
|
value={q}
|
|
@@ -126,9 +132,9 @@
|
|
|
126
132
|
<!-- Only orders still on screen: a search or tab change must not dispatch hidden ticks. -->
|
|
127
133
|
{let chosen = $derived(rows.map((r) => r.number).filter((n) => selected.has(n)))}
|
|
128
134
|
{#if rows.length === 0}
|
|
129
|
-
<
|
|
135
|
+
<Text class="mt-6" color="secondary">
|
|
130
136
|
{filter === 'to-ship' && !q ? 'Nothing to ship. All caught up.' : 'No orders match.'}
|
|
131
|
-
</
|
|
137
|
+
</Text>
|
|
132
138
|
{:else}
|
|
133
139
|
{#if filter === 'ready'}
|
|
134
140
|
<div class="mt-4 flex flex-wrap items-center gap-4 text-sm">
|
|
@@ -146,7 +152,7 @@
|
|
|
146
152
|
Select {Math.min(rows.length, BULK_DISPATCH_LIMIT)}
|
|
147
153
|
</label>
|
|
148
154
|
<label class="flex items-center gap-2">
|
|
149
|
-
<input bind:checked={sendEmail}
|
|
155
|
+
<input type="checkbox" bind:checked={sendEmail} />
|
|
150
156
|
Email the customers
|
|
151
157
|
</label>
|
|
152
158
|
<Button
|
|
@@ -157,9 +163,9 @@
|
|
|
157
163
|
</Button>
|
|
158
164
|
</div>
|
|
159
165
|
{/if}
|
|
160
|
-
<div class="mt-4 overflow-x-auto rounded-xl border border-[var(--
|
|
166
|
+
<div class="mt-4 overflow-x-auto rounded-xl border border-[var(--bd)] bg-white">
|
|
161
167
|
<table class="w-full text-left text-sm">
|
|
162
|
-
<thead class="border-b border-[var(--
|
|
168
|
+
<thead class="border-b border-[var(--bd)] text-[var(--txs)]">
|
|
163
169
|
<tr>
|
|
164
170
|
{#if filter === 'ready'}<th class="w-8 px-4 py-2"></th>{/if}
|
|
165
171
|
<th class="px-4 py-2 font-medium">Order</th>
|
|
@@ -169,7 +175,7 @@
|
|
|
169
175
|
<th class="px-4 py-2 font-medium">Status</th>
|
|
170
176
|
</tr>
|
|
171
177
|
</thead>
|
|
172
|
-
<tbody class="divide-y divide-[var(--
|
|
178
|
+
<tbody class="divide-y divide-[var(--bd)]">
|
|
173
179
|
{#each rows as row (row.number)}
|
|
174
180
|
<tr>
|
|
175
181
|
{#if filter === 'ready'}
|
|
@@ -192,9 +198,7 @@
|
|
|
192
198
|
<td class="px-4 py-2 whitespace-nowrap">{date.format(row.createdAt)}</td>
|
|
193
199
|
<td class="px-4 py-2">
|
|
194
200
|
{row.name}
|
|
195
|
-
<
|
|
196
|
-
>{row.email} · {row.country}</span
|
|
197
|
-
>
|
|
201
|
+
<Span class="block" color="secondary" size="sm">{row.email} · {row.country}</Span>
|
|
198
202
|
</td>
|
|
199
203
|
<td class="px-4 py-2 text-right whitespace-nowrap">{Money.format(row.totalPence)}</td>
|
|
200
204
|
<td class="px-4 py-2">
|
|
@@ -212,6 +216,6 @@
|
|
|
212
216
|
</div>
|
|
213
217
|
{/if}
|
|
214
218
|
{#snippet pending()}
|
|
215
|
-
<
|
|
219
|
+
<Text class="mt-6" color="secondary">Loading…</Text>
|
|
216
220
|
{/snippet}
|
|
217
221
|
</Boundary>
|
package/orders/manager.server.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type Stripe from 'stripe';
|
|
|
2
2
|
|
|
3
3
|
import { logger } from '@zeyolabs/kit/server/logger';
|
|
4
4
|
|
|
5
|
+
import { BundleParts } from '../bundles/library';
|
|
5
6
|
import { ShopClients } from '../clients/shop.server';
|
|
6
7
|
import { shopping } from '../config';
|
|
7
8
|
import { ShippingService } from '../shipping/service.server';
|
|
@@ -62,17 +63,7 @@ export const OrderManager = {
|
|
|
62
63
|
}
|
|
63
64
|
);
|
|
64
65
|
|
|
65
|
-
const items
|
|
66
|
-
const product = line.price?.product as Stripe.Product;
|
|
67
|
-
const productId = Number(product.metadata.productId);
|
|
68
|
-
return {
|
|
69
|
-
name: line.description ?? product.name,
|
|
70
|
-
productId: Number.isInteger(productId) ? productId : null,
|
|
71
|
-
quantity: line.quantity ?? 1,
|
|
72
|
-
sku: product.metadata.sku ?? '',
|
|
73
|
-
unitPricePence: line.price?.unit_amount ?? 0,
|
|
74
|
-
};
|
|
75
|
-
});
|
|
66
|
+
const items = await orderItems(service, session.line_items?.data ?? []);
|
|
76
67
|
if (!(await service.writeItems(order.id, items))) return;
|
|
77
68
|
|
|
78
69
|
// The customer is already charged and the order recorded: neither follow-up may fail the webhook.
|
|
@@ -130,3 +121,46 @@ export const OrderManager = {
|
|
|
130
121
|
return invoice.invoice_pdf ?? invoice.hosted_invoice_url ?? undefined;
|
|
131
122
|
},
|
|
132
123
|
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The paid session's lines as order items. A grouped bundle is its own line at the price paid, then
|
|
127
|
+
* each part at no charge (sku `BUNDLE-<id>-<n>:<part sku>`), so its stock is taken when the items
|
|
128
|
+
* are written; a kit's parts are single units.
|
|
129
|
+
*/
|
|
130
|
+
async function orderItems(
|
|
131
|
+
service: OrderService,
|
|
132
|
+
lines: Stripe.LineItem[]
|
|
133
|
+
): Promise<NewOrderItem[]> {
|
|
134
|
+
const items: NewOrderItem[] = [];
|
|
135
|
+
const bundled = lines.map((line) =>
|
|
136
|
+
BundleParts.decode((line.price?.product as Stripe.Product).metadata.bundleParts)
|
|
137
|
+
);
|
|
138
|
+
const names = await service.productNames([...new Set(bundled.flat().map((p) => p.productId))]);
|
|
139
|
+
for (const [n, line] of lines.entries()) {
|
|
140
|
+
const product = line.price?.product as Stripe.Product;
|
|
141
|
+
const productId = Number(product.metadata.productId);
|
|
142
|
+
const parts = bundled[n];
|
|
143
|
+
const sku = parts.length
|
|
144
|
+
? `${product.metadata.sku ?? 'BUNDLE'}-${n + 1}`
|
|
145
|
+
: (product.metadata.sku ?? '');
|
|
146
|
+
items.push({
|
|
147
|
+
name: line.description ?? product.name,
|
|
148
|
+
productId: !parts.length && Number.isInteger(productId) ? productId : null,
|
|
149
|
+
quantity: line.quantity ?? 1,
|
|
150
|
+
sku,
|
|
151
|
+
unitPricePence: line.price?.unit_amount ?? 0,
|
|
152
|
+
});
|
|
153
|
+
for (const part of parts) {
|
|
154
|
+
const known = names.get(part.productId);
|
|
155
|
+
items.push({
|
|
156
|
+
name: known?.name ?? `Product ${part.productId}`,
|
|
157
|
+
productId: part.productId,
|
|
158
|
+
quantity: part.quantity,
|
|
159
|
+
singleUnits: part.singleUnits,
|
|
160
|
+
sku: `${sku}:${known?.sku ?? part.productId}`,
|
|
161
|
+
unitPricePence: 0,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return items;
|
|
166
|
+
}
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { page } from '$app/state';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import Boundary from '@zeyolabs/ui/boundary/Boundary.svelte';
|
|
4
|
+
import SkeletonCard from '@zeyolabs/ui/skeleton/SkeletonCard.svelte';
|
|
5
|
+
import Span from '@zeyolabs/ui/text/Span.svelte';
|
|
6
|
+
import Text from '@zeyolabs/ui/text/Text.svelte';
|
|
7
|
+
import Title from '@zeyolabs/ui/text/Title.svelte';
|
|
8
|
+
|
|
9
|
+
import { shopContext } from '../../context';
|
|
5
10
|
import { getOrderReviews } from '../../reviews/client.remote';
|
|
6
11
|
import ReviewForm from '../../reviews/components/ReviewForm.svelte';
|
|
7
|
-
import
|
|
12
|
+
import PageTitle from '../../ui/PageTitle.svelte';
|
|
8
13
|
import { Money } from '../../utils/money';
|
|
14
|
+
import { getOrderPage } from '../client.remote';
|
|
9
15
|
import { Orders } from '../library';
|
|
10
|
-
import Boundary from '@zeyolabs/ui/boundary/Boundary.svelte';
|
|
11
|
-
import SkeletonCard from '@zeyolabs/ui/skeleton/SkeletonCard.svelte';
|
|
12
16
|
|
|
13
17
|
const context = shopContext();
|
|
14
18
|
const date = new Intl.DateTimeFormat('en-GB', { dateStyle: 'long', timeZone: 'Europe/London' });
|
|
@@ -32,54 +36,56 @@
|
|
|
32
36
|
{ done: order.shippedAt !== null, label: 'Dispatched', when: order.shippedAt },
|
|
33
37
|
])}
|
|
34
38
|
|
|
35
|
-
<
|
|
39
|
+
<Text color="secondary">Order <strong class="text-[var(--tx)]">{order.number}</strong></Text>
|
|
36
40
|
|
|
37
41
|
{#if cancelled}
|
|
38
|
-
<
|
|
42
|
+
<Text class="mt-4 rounded-2xl border border-[var(--bd)] p-4">
|
|
39
43
|
This order was {order.status}. Email
|
|
40
44
|
<a class="underline" href="mailto:{context.supportEmail}">{context.supportEmail}</a> if you have
|
|
41
45
|
any questions.
|
|
42
|
-
</
|
|
46
|
+
</Text>
|
|
43
47
|
{:else}
|
|
44
48
|
<ol class="mt-6 space-y-3">
|
|
45
49
|
{#each steps as step (step.label)}
|
|
46
50
|
<li class="flex items-center gap-3">
|
|
47
|
-
<
|
|
51
|
+
<div
|
|
48
52
|
class="grid size-6 place-items-center rounded-full text-xs {step.done
|
|
49
53
|
? 'bg-[var(--primary-strong)] text-white'
|
|
50
54
|
: 'border border-[var(--bd)] text-[var(--txs)]'}"
|
|
51
|
-
aria-hidden="true"
|
|
55
|
+
aria-hidden="true"
|
|
52
56
|
>
|
|
53
|
-
|
|
57
|
+
{step.done ? '✓' : ''}
|
|
58
|
+
</div>
|
|
59
|
+
<Span bold={step.done} color={step.done ? undefined : 'secondary'}>
|
|
54
60
|
{step.label}{step.done && step.when ? `: ${date.format(step.when)}` : ''}
|
|
55
|
-
</
|
|
61
|
+
</Span>
|
|
56
62
|
</li>
|
|
57
63
|
{/each}
|
|
58
64
|
</ol>
|
|
59
65
|
|
|
60
66
|
{#if order.shippedAt && tracking}
|
|
61
|
-
<
|
|
67
|
+
<Text class="mt-4">
|
|
62
68
|
Tracking number:
|
|
63
69
|
<!-- eslint-disable-next-line svelte/no-navigation-without-resolve -- external Royal Mail URL -->
|
|
64
70
|
<a class="underline" href={tracking} rel="noopener" target="_blank"
|
|
65
71
|
>{order.trackingNumber}</a
|
|
66
72
|
>
|
|
67
|
-
</
|
|
73
|
+
</Text>
|
|
68
74
|
{:else if order.shippedAt}
|
|
69
|
-
<
|
|
75
|
+
<Text class="mt-4" color="secondary">This parcel is sent untracked.</Text>
|
|
70
76
|
{:else}
|
|
71
|
-
<
|
|
77
|
+
<Text class="mt-4" color="secondary">
|
|
72
78
|
We will dispatch your order soon. This page updates as soon as it is on its way.
|
|
73
|
-
</
|
|
79
|
+
</Text>
|
|
74
80
|
{/if}
|
|
75
81
|
{/if}
|
|
76
82
|
|
|
77
|
-
<
|
|
83
|
+
<Title class="mt-8" level={2} size="sm">Items</Title>
|
|
78
84
|
<ul class="mt-2 divide-y divide-[var(--bd)] border-y border-[var(--bd)]">
|
|
79
85
|
{#each data.items as item (item.name)}
|
|
80
86
|
<li class="flex justify-between gap-4 py-3">
|
|
81
|
-
<
|
|
82
|
-
<
|
|
87
|
+
<Span>{item.name} <Span color="secondary">× {item.quantity}</Span></Span>
|
|
88
|
+
<Span>{Money.format(item.quantity * item.unitPricePence)}</Span>
|
|
83
89
|
</li>
|
|
84
90
|
{/each}
|
|
85
91
|
</ul>
|
|
@@ -106,15 +112,15 @@
|
|
|
106
112
|
</dl>
|
|
107
113
|
|
|
108
114
|
{#if order.hasInvoice}
|
|
109
|
-
<
|
|
115
|
+
<Text class="mt-3 text-right">
|
|
110
116
|
<!-- eslint-disable-next-line svelte/no-navigation-without-resolve -- server route, opens Stripe's PDF -->
|
|
111
117
|
<a class="underline" href="{page.url.pathname}/invoice" rel="external"
|
|
112
118
|
>Download invoice (PDF)</a
|
|
113
119
|
>
|
|
114
|
-
</
|
|
120
|
+
</Text>
|
|
115
121
|
{/if}
|
|
116
122
|
|
|
117
|
-
<
|
|
123
|
+
<Title class="mt-8" level={2} size="sm">Delivering to</Title>
|
|
118
124
|
<address class="mt-2 not-italic">
|
|
119
125
|
{data.address.name}<br />
|
|
120
126
|
{data.address.line1}<br />
|
|
@@ -128,20 +134,20 @@
|
|
|
128
134
|
await getOrderReviews({ number: order.number, token: page.params.token ?? '' })
|
|
129
135
|
)}
|
|
130
136
|
{#if reviewable.items.length > 0}
|
|
131
|
-
<
|
|
137
|
+
<Title class="mt-8" level={2} size="sm">Review your items</Title>
|
|
132
138
|
<ul class="mt-2 space-y-6">
|
|
133
139
|
{#each reviewable.items as item (item.productId)}
|
|
134
140
|
<li class="rounded-2xl border border-[var(--bd)] p-4">
|
|
135
|
-
<
|
|
141
|
+
<Text bold>{item.name}</Text>
|
|
136
142
|
{#if item.review}
|
|
137
|
-
<
|
|
143
|
+
<Text class="mt-1" color="secondary">
|
|
138
144
|
Reviewed, {item.review.rating} of 5.
|
|
139
145
|
{item.review.status === 'pending'
|
|
140
146
|
? 'It will appear once we have checked it.'
|
|
141
147
|
: item.review.status === 'approved'
|
|
142
148
|
? 'It is on the product page.'
|
|
143
149
|
: ''}
|
|
144
|
-
</
|
|
150
|
+
</Text>
|
|
145
151
|
{:else}
|
|
146
152
|
<ReviewForm
|
|
147
153
|
name={item.name}
|
|
@@ -155,11 +161,11 @@
|
|
|
155
161
|
</ul>
|
|
156
162
|
{/if}
|
|
157
163
|
|
|
158
|
-
<
|
|
164
|
+
<Text class="mt-8" color="secondary">
|
|
159
165
|
Need help? Email <a class="underline" href="mailto:{context.supportEmail}"
|
|
160
166
|
>{context.supportEmail}</a
|
|
161
167
|
>, quoting {order.number}.
|
|
162
|
-
</
|
|
168
|
+
</Text>
|
|
163
169
|
|
|
164
170
|
{#snippet pending()}
|
|
165
171
|
<SkeletonCard lines={4} />
|
package/orders/service.server.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Crypto } from '@zeyolabs/kit/utils/crypto';
|
|
2
|
-
import { eq } from 'drizzle-orm';
|
|
2
|
+
import { eq, inArray } from 'drizzle-orm';
|
|
3
3
|
|
|
4
4
|
import type { ShopDb } from '../db/index';
|
|
5
5
|
|
|
6
|
-
import { addresses, orderItems, orders } from '../db/schema';
|
|
6
|
+
import { addresses, orderItems, orders, products } from '../db/schema';
|
|
7
7
|
import { StockService } from '../stock/service.server';
|
|
8
|
+
import { Batches } from '../utils/batches';
|
|
8
9
|
|
|
9
10
|
export type NewOrderItem = Omit<typeof orderItems.$inferInsert, 'id' | 'orderId'>;
|
|
10
11
|
type NewAddress = Omit<typeof addresses.$inferInsert, 'createdAt' | 'id'>;
|
|
@@ -69,6 +70,25 @@ export class OrderService {
|
|
|
69
70
|
return row !== undefined;
|
|
70
71
|
}
|
|
71
72
|
|
|
73
|
+
/** Names and SKUs by id, for a bundle's parts on a new order. */
|
|
74
|
+
async productNames(ids: number[]): Promise<Map<number, { name: string; sku: string }>> {
|
|
75
|
+
if (ids.length === 0) return new Map();
|
|
76
|
+
const rows = await Batches.rows(ids, (slice) =>
|
|
77
|
+
this.db
|
|
78
|
+
.select({
|
|
79
|
+
id: products.id,
|
|
80
|
+
label: products.variationLabel,
|
|
81
|
+
name: products.name,
|
|
82
|
+
sku: products.sku,
|
|
83
|
+
})
|
|
84
|
+
.from(products)
|
|
85
|
+
.where(inArray(products.id, slice))
|
|
86
|
+
);
|
|
87
|
+
return new Map(
|
|
88
|
+
rows.map((r) => [r.id, { name: r.label ? `${r.name} (${r.label})` : r.name, sku: r.sku }])
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
72
92
|
async setRoyalMailOrderId(orderId: number, royalMailOrderId: string) {
|
|
73
93
|
await this.db.update(orders).set({ royalMailOrderId }).where(eq(orders.id, orderId));
|
|
74
94
|
}
|
|
@@ -82,7 +102,9 @@ export class OrderService {
|
|
|
82
102
|
const stock = new StockService(this.db);
|
|
83
103
|
const stockStatements = await stock.paidStatements(
|
|
84
104
|
items.flatMap((item) =>
|
|
85
|
-
item.productId == null
|
|
105
|
+
item.productId == null
|
|
106
|
+
? []
|
|
107
|
+
: [{ productId: item.productId, quantity: item.quantity, singleUnits: item.singleUnits }]
|
|
86
108
|
)
|
|
87
109
|
);
|
|
88
110
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeyolabs/shopping",
|
|
3
|
-
"version": "2026.11.
|
|
3
|
+
"version": "2026.11.39",
|
|
4
4
|
"description": "Shop and order fulfilment for SvelteKit 3 on Cloudflare: catalogue, basket, Stripe Checkout, orders, Royal Mail Click & Drop, order emails, packing, pages and admin.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"lint": "eslint . --cache --cache-location .cache/.eslintcache --cache-strategy content",
|
|
43
43
|
"test": "vitest run",
|
|
44
44
|
"fmt": "prettier --write .",
|
|
45
|
-
"check": "prettier --check . && pnpm lint && pnpm test"
|
|
45
|
+
"check": "prettier --check . && pnpm lint && svelte-check --tsconfig ./tsconfig.json && pnpm test"
|
|
46
46
|
},
|
|
47
47
|
"exports": {
|
|
48
48
|
"./*.svelte": "./*.svelte",
|
|
@@ -67,8 +67,8 @@
|
|
|
67
67
|
"@eslint/compat": "2.1.1",
|
|
68
68
|
"@eslint/js": "10.0.1",
|
|
69
69
|
"@sveltejs/kit": "3.2.0",
|
|
70
|
-
"@zeyolabs/kit": "2026.11.
|
|
71
|
-
"@zeyolabs/ui": "2026.11.
|
|
70
|
+
"@zeyolabs/kit": "2026.11.36",
|
|
71
|
+
"@zeyolabs/ui": "2026.11.32",
|
|
72
72
|
"drizzle-orm": "0.45.4",
|
|
73
73
|
"eslint": "10.15.0",
|
|
74
74
|
"eslint-config-prettier": "10.1.8",
|
|
@@ -80,6 +80,7 @@
|
|
|
80
80
|
"prettier": "3.10.1",
|
|
81
81
|
"prettier-plugin-svelte": "4.1.1",
|
|
82
82
|
"svelte": "5.57.3",
|
|
83
|
+
"svelte-check": "4.7.8",
|
|
83
84
|
"svelte-eslint-parser": "1.10.1",
|
|
84
85
|
"typescript": "6.0.3",
|
|
85
86
|
"typescript-eslint": "8.72.2",
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { resolve } from '$app/paths';
|
|
3
3
|
import { page } from '$app/state';
|
|
4
|
-
import
|
|
5
|
-
import { getReviews, moderateReviewForm } from '../admin.remote';
|
|
6
|
-
import { ModerateReviewSchema } from '../schema';
|
|
4
|
+
import Boundary from '@zeyolabs/ui/boundary/Boundary.svelte';
|
|
7
5
|
import { Form } from '@zeyolabs/ui/form';
|
|
8
6
|
import Button from '@zeyolabs/ui/form/Button.svelte';
|
|
9
|
-
import
|
|
7
|
+
import Text from '@zeyolabs/ui/text/Text.svelte';
|
|
8
|
+
import Title from '@zeyolabs/ui/text/Title.svelte';
|
|
9
|
+
|
|
10
10
|
import { shopContext } from '../../context';
|
|
11
|
+
import { REVIEW_STATUSES, type ReviewStatus } from '../../db/schema';
|
|
12
|
+
import { getReviews, moderateReviewForm } from '../admin.remote';
|
|
13
|
+
import { ModerateReviewSchema } from '../schema';
|
|
11
14
|
|
|
12
15
|
const context = shopContext();
|
|
13
16
|
const status = $derived.by((): ReviewStatus => {
|
|
@@ -24,17 +27,17 @@
|
|
|
24
27
|
|
|
25
28
|
<svelte:head><title>Reviews · Admin</title></svelte:head>
|
|
26
29
|
|
|
27
|
-
<
|
|
28
|
-
<
|
|
30
|
+
<Title level={1} size="md">Reviews</Title>
|
|
31
|
+
<Text class="mt-1" color="secondary">
|
|
29
32
|
Customers review items from their order page. A review shows on the product page once approved.
|
|
30
|
-
</
|
|
33
|
+
</Text>
|
|
31
34
|
|
|
32
35
|
<nav class="mt-4 flex gap-2" aria-label="Review status">
|
|
33
36
|
{#each REVIEW_STATUSES as s (s)}
|
|
34
37
|
<a
|
|
35
38
|
class="rounded-full border px-3 py-1 text-sm no-underline {s === status
|
|
36
|
-
? 'border-[var(--
|
|
37
|
-
: 'border-[var(--
|
|
39
|
+
? 'border-[var(--acc)] bg-[var(--acc)] text-white'
|
|
40
|
+
: 'border-[var(--bd)] bg-white text-[var(--tx)]'}"
|
|
38
41
|
aria-current={s === status ? 'page' : undefined}
|
|
39
42
|
href="{resolve('/reviews')}?status={s}">{LABELS[s]}</a
|
|
40
43
|
>
|
|
@@ -44,13 +47,13 @@
|
|
|
44
47
|
<Boundary message="Could not load reviews.">
|
|
45
48
|
{let rows = $derived(await getReviews(status))}
|
|
46
49
|
{#if rows.length === 0}
|
|
47
|
-
<
|
|
50
|
+
<Text class="mt-6" color="secondary">Nothing here.</Text>
|
|
48
51
|
{:else}
|
|
49
52
|
<ul class="mt-4 space-y-4">
|
|
50
53
|
{#each rows as review (review.id)}
|
|
51
54
|
{const form = moderateReviewForm.for(review.id)}
|
|
52
|
-
<li class="rounded-xl border border-[var(--
|
|
53
|
-
<
|
|
55
|
+
<li class="rounded-xl border border-[var(--bd)] bg-white p-4">
|
|
56
|
+
<Text color="secondary">
|
|
54
57
|
<!-- eslint-disable-next-line svelte/no-navigation-without-resolve -- the shop's own domain -->
|
|
55
58
|
<a href="{context.siteUrl}/product/{review.productSlug}" rel="noopener" target="_blank"
|
|
56
59
|
>{review.productName}</a
|
|
@@ -60,15 +63,16 @@
|
|
|
60
63
|
>{review.orderNumber}</a
|
|
61
64
|
>
|
|
62
65
|
· {review.email} · {date.format(review.createdAt)}
|
|
63
|
-
</
|
|
64
|
-
<
|
|
65
|
-
|
|
66
|
+
</Text>
|
|
67
|
+
<Text class="mt-2">
|
|
68
|
+
<!-- eslint-disable-next-line svelte/no-restricted-html-elements -- star glyphs with an aria-label, which Span does not take -->
|
|
69
|
+
<span class="text-[var(--acc)]" aria-label="{review.rating} out of 5"
|
|
66
70
|
>{'★'.repeat(review.rating)}{'☆'.repeat(5 - review.rating)}</span
|
|
67
71
|
>
|
|
68
72
|
{#if review.title}<strong class="ml-2">{review.title}</strong>{/if}
|
|
69
|
-
</
|
|
70
|
-
<
|
|
71
|
-
<
|
|
73
|
+
</Text>
|
|
74
|
+
<Text class="mt-2 whitespace-pre-line">{review.body}</Text>
|
|
75
|
+
<Text class="mt-2">by {review.name}</Text>
|
|
72
76
|
<Form
|
|
73
77
|
class="mt-3 flex gap-2"
|
|
74
78
|
{form}
|
|
@@ -90,6 +94,6 @@
|
|
|
90
94
|
</ul>
|
|
91
95
|
{/if}
|
|
92
96
|
{#snippet pending()}
|
|
93
|
-
<
|
|
97
|
+
<Text class="mt-6" color="secondary">Loading…</Text>
|
|
94
98
|
{/snippet}
|
|
95
99
|
</Boundary>
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { reviewForm } from '../client.remote';
|
|
3
|
-
import { ReviewSchema } from '../schema';
|
|
4
2
|
import { Form, MessageField, SelectField, TextField } from '@zeyolabs/ui/form';
|
|
5
3
|
import Button from '@zeyolabs/ui/form/Button.svelte';
|
|
6
4
|
|
|
5
|
+
import { reviewForm } from '../client.remote';
|
|
6
|
+
import { ReviewSchema } from '../schema';
|
|
7
|
+
|
|
7
8
|
let {
|
|
8
9
|
name,
|
|
9
10
|
number,
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import Span from '@zeyolabs/ui/text/Span.svelte';
|
|
3
|
+
import Text from '@zeyolabs/ui/text/Text.svelte';
|
|
4
|
+
import Title from '@zeyolabs/ui/text/Title.svelte';
|
|
5
|
+
|
|
2
6
|
import Stars from '../../ui/Stars.svelte';
|
|
3
7
|
|
|
4
8
|
type Review = {
|
|
@@ -16,31 +20,31 @@
|
|
|
16
20
|
const date = new Intl.DateTimeFormat('en-GB', { dateStyle: 'medium', timeZone: 'Europe/London' });
|
|
17
21
|
</script>
|
|
18
22
|
|
|
19
|
-
<section class="mt-12" aria-
|
|
20
|
-
<
|
|
23
|
+
<section id="reviews" class="mt-12" aria-label="Reviews">
|
|
24
|
+
<Title level={2} size="md">Reviews</Title>
|
|
21
25
|
{#if reviews.count === 0 || reviews.average === null}
|
|
22
|
-
<
|
|
26
|
+
<Text class="mt-2" color="secondary">
|
|
23
27
|
No reviews yet. Bought this? You can review it from your order page.
|
|
24
|
-
</
|
|
28
|
+
</Text>
|
|
25
29
|
{:else}
|
|
26
|
-
<
|
|
30
|
+
<Text class="mt-2 flex items-center gap-2">
|
|
27
31
|
<Stars rating={reviews.average} />
|
|
28
|
-
<
|
|
32
|
+
<Span
|
|
29
33
|
>{reviews.average} out of 5, from {reviews.count}
|
|
30
|
-
{reviews.count === 1 ? 'review' : 'reviews'}</
|
|
34
|
+
{reviews.count === 1 ? 'review' : 'reviews'}</Span
|
|
31
35
|
>
|
|
32
|
-
</
|
|
36
|
+
</Text>
|
|
33
37
|
<ul class="mt-4 divide-y divide-[var(--bd)] border-y border-[var(--bd)]">
|
|
34
38
|
{#each reviews.list as review (review.id)}
|
|
35
39
|
<li class="py-4">
|
|
36
|
-
<
|
|
40
|
+
<Text class="flex flex-wrap items-center gap-2">
|
|
37
41
|
<Stars rating={review.rating} size="text-sm" />
|
|
38
42
|
{#if review.title}<strong>{review.title}</strong>{/if}
|
|
39
|
-
</
|
|
40
|
-
<
|
|
41
|
-
<
|
|
43
|
+
</Text>
|
|
44
|
+
<Text class="mt-2 whitespace-pre-line">{review.body}</Text>
|
|
45
|
+
<Text class="mt-2" color="secondary">
|
|
42
46
|
{review.name}, verified buyer, {date.format(review.createdAt)}
|
|
43
|
-
</
|
|
47
|
+
</Text>
|
|
44
48
|
</li>
|
|
45
49
|
{/each}
|
|
46
50
|
</ul>
|
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { getStock } from '../admin.remote';
|
|
3
|
-
import StockRow from './StockRow.svelte';
|
|
4
2
|
import Badge from '@zeyolabs/ui/badge/Badge.svelte';
|
|
5
3
|
import Boundary from '@zeyolabs/ui/boundary/Boundary.svelte';
|
|
4
|
+
import Text from '@zeyolabs/ui/text/Text.svelte';
|
|
5
|
+
import Title from '@zeyolabs/ui/text/Title.svelte';
|
|
6
|
+
|
|
7
|
+
import { getStock } from '../admin.remote';
|
|
8
|
+
import StockRow from './StockRow.svelte';
|
|
6
9
|
</script>
|
|
7
10
|
|
|
8
11
|
<svelte:head><title>Stock</title></svelte:head>
|
|
9
12
|
|
|
10
|
-
<
|
|
11
|
-
<
|
|
13
|
+
<Title level={1} size="md">Stock</Title>
|
|
14
|
+
<Text class="mt-1" color="secondary">
|
|
12
15
|
Setting a sold-out product above 0 emails the customers waiting for it, up to 50 a minute, and
|
|
13
16
|
removes them from the list.
|
|
14
|
-
</
|
|
17
|
+
</Text>
|
|
15
18
|
|
|
16
19
|
<Boundary message="Could not load stock.">
|
|
17
20
|
{let rows = $derived(await getStock())}
|
|
18
|
-
<div class="mt-4 overflow-x-auto rounded-xl border border-[var(--
|
|
21
|
+
<div class="mt-4 overflow-x-auto rounded-xl border border-[var(--bd)] bg-white">
|
|
19
22
|
<table class="w-full text-left text-sm">
|
|
20
|
-
<thead class="border-b border-[var(--
|
|
23
|
+
<thead class="border-b border-[var(--bd)] text-[var(--txs)]">
|
|
21
24
|
<tr>
|
|
22
25
|
<th class="px-4 py-2 font-medium">Product</th>
|
|
23
26
|
<th class="px-4 py-2 font-medium">SKU</th>
|
|
@@ -25,7 +28,7 @@
|
|
|
25
28
|
<th class="px-4 py-2 text-right font-medium">Stock</th>
|
|
26
29
|
</tr>
|
|
27
30
|
</thead>
|
|
28
|
-
<tbody class="divide-y divide-[var(--
|
|
31
|
+
<tbody class="divide-y divide-[var(--bd)]">
|
|
29
32
|
{#each rows as row (row.id)}
|
|
30
33
|
<tr>
|
|
31
34
|
<td class="px-4 py-2 font-medium">
|
|
@@ -47,6 +50,6 @@
|
|
|
47
50
|
</table>
|
|
48
51
|
</div>
|
|
49
52
|
{#snippet pending()}
|
|
50
|
-
<
|
|
53
|
+
<Text class="mt-6" color="secondary">Loading…</Text>
|
|
51
54
|
{/snippet}
|
|
52
55
|
</Boundary>
|