@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.
Files changed (46) hide show
  1. package/basket/client.remote.ts +16 -2
  2. package/basket/cookies.server.ts +13 -1
  3. package/basket/library.ts +58 -0
  4. package/basket/pages/Basket.svelte +80 -30
  5. package/basket/service.server.ts +139 -6
  6. package/bundles/admin/BundleEditPage.svelte +7 -4
  7. package/bundles/admin/BundleForm.svelte +50 -11
  8. package/bundles/admin/BundlesPage.svelte +14 -10
  9. package/bundles/client.remote.ts +18 -6
  10. package/bundles/library.ts +51 -0
  11. package/bundles/pages/Bundle.svelte +233 -68
  12. package/bundles/schema.ts +13 -2
  13. package/bundles/service.server.ts +185 -33
  14. package/catalogue/admin/CategoriesPage.svelte +13 -10
  15. package/catalogue/admin/CategoryForm.svelte +4 -3
  16. package/catalogue/admin/ProductEditPage.svelte +7 -4
  17. package/catalogue/admin/ProductForm.svelte +31 -29
  18. package/catalogue/admin/ProductsPage.svelte +16 -14
  19. package/catalogue/client.remote.ts +23 -9
  20. package/catalogue/components/ProductCard.svelte +22 -14
  21. package/catalogue/library.ts +91 -0
  22. package/catalogue/loads.server.ts +8 -4
  23. package/catalogue/pages/Category.svelte +15 -6
  24. package/catalogue/pages/Product.svelte +164 -45
  25. package/catalogue/pages/Search.svelte +12 -7
  26. package/catalogue/pages/Shop.svelte +12 -12
  27. package/catalogue/service.server.ts +44 -9
  28. package/checkout/manager.server.ts +68 -16
  29. package/checkout/pages/CheckoutSuccess.svelte +10 -8
  30. package/customers/pages/Account.svelte +19 -15
  31. package/db/schema.ts +27 -3
  32. package/fulfilment/admin/OrderPage.svelte +60 -56
  33. package/fulfilment/admin/OrdersPage.svelte +26 -22
  34. package/orders/manager.server.ts +45 -11
  35. package/orders/pages/Order.svelte +35 -29
  36. package/orders/service.server.ts +25 -3
  37. package/package.json +5 -4
  38. package/reviews/admin/ReviewsPage.svelte +23 -19
  39. package/reviews/components/ReviewForm.svelte +3 -2
  40. package/reviews/components/Reviews.svelte +17 -13
  41. package/stock/admin/StockPage.svelte +12 -9
  42. package/stock/admin/StockRow.svelte +3 -2
  43. package/stock/service.server.ts +6 -1
  44. package/ui/PageLinks.svelte +45 -0
  45. package/ui/PageTitle.svelte +20 -4
  46. package/ui/Stars.svelte +3 -1
@@ -8,9 +8,60 @@ import { CoverService } from '../catalogue/covers.server';
8
8
  import { bundles, bundleStepProducts, bundleSteps, products } from '../db/schema';
9
9
  import { StockService } from '../stock/service.server';
10
10
  import { Batches } from '../utils/batches';
11
+ import { BundleSku } from './library';
11
12
 
12
13
  type Choice = { productIds: number[]; stepId: number };
13
14
 
15
+ /** One product in a resolved bundle. `singleUnits`: `quantity` is single units (a kit's fill). */
16
+ export type BundlePart = {
17
+ massGrams: number;
18
+ name: string;
19
+ pricePence: number;
20
+ productId: number;
21
+ quantity: number;
22
+ singleUnits: boolean;
23
+ sku: string;
24
+ };
25
+
26
+ export type ResolvedBundle = {
27
+ bundle: { id: number; image: null | string; name: string; slug: string };
28
+ /** What was chosen, one line each, for the basket and the order. */
29
+ details: string[];
30
+ /** True when the basket keeps it as one line (a kit, or a discounted bundle). */
31
+ grouped: boolean;
32
+ kit: boolean;
33
+ /** The parts at their own prices, before any discount (a kit's free parts count 0). */
34
+ listPricePence: number;
35
+ massGrams: number;
36
+ parts: BundlePart[];
37
+ pricePence: number;
38
+ };
39
+
40
+ type Offered = {
41
+ id: number;
42
+ massGrams: number;
43
+ name: string;
44
+ packSize: number;
45
+ pricePence: number;
46
+ sku: string;
47
+ units: number;
48
+ variationLabel: null | string;
49
+ };
50
+
51
+ const Parts = {
52
+ label: (p: Offered) => (p.variationLabel ? `${p.name} (${p.variationLabel})` : p.name),
53
+ /** `units` single units of a product, weighing their share of a pack. */
54
+ single: (p: Offered, units: number): BundlePart => ({
55
+ massGrams: Math.round((p.massGrams * units) / Math.max(1, p.packSize)),
56
+ name: Parts.label(p),
57
+ pricePence: 0,
58
+ productId: p.id,
59
+ quantity: units,
60
+ singleUnits: true,
61
+ sku: p.sku,
62
+ }),
63
+ };
64
+
14
65
  /** Bundles built in steps. Data access and the rules for a valid choice; the basket does the rest. */
15
66
  export class BundleService {
16
67
  constructor(private readonly db: ShopDb) {}
@@ -25,36 +76,15 @@ export class BundleService {
25
76
  }
26
77
 
27
78
  /**
28
- * Checks a customer's choice against the bundle's steps and returns how many of each product to
29
- * add to the basket. Throws a 400 with a message the customer can act on.
79
+ * Checks a plain bundle's choice and returns how many of each product to add to the basket as
80
+ * ordinary lines. Throws a 400 with a message the customer can act on.
30
81
  */
31
82
  async expand(bundleId: number, choices: Choice[]): Promise<Map<number, number>> {
32
- const bundle = await this.db.query.bundles.findFirst({
33
- where: and(eq(bundles.id, bundleId), eq(bundles.active, true)),
34
- });
35
- if (!bundle) throw Error400('This bundle is no longer available.');
36
- const steps = await this.steps(bundle.id, { activeOnly: true });
37
- const chosen = new Map(choices.map((c) => [c.stepId, [...new Set(c.productIds)]]));
83
+ const resolved = await this.resolve(bundleId, choices);
38
84
  const lines = new Map<number, number>();
39
- for (const step of steps) {
40
- const picks = chosen.get(step.id) ?? [];
41
- if (picks.length < step.minChoices || picks.length > step.maxChoices) {
42
- throw Error400(
43
- step.minChoices === step.maxChoices
44
- ? `${step.title}: choose ${step.minChoices}.`
45
- : `${step.title}: choose ${step.minChoices} to ${step.maxChoices}.`
46
- );
47
- }
48
- for (const id of picks) {
49
- const product = step.products.find((p) => p.id === id);
50
- if (!product) throw Error400(`${step.title}: that choice is not available.`);
51
- if (product.stock < 1) throw Error400(`${product.name} is out of stock.`);
52
- lines.set(id, (lines.get(id) ?? 0) + 1);
53
- }
85
+ for (const part of resolved.parts) {
86
+ lines.set(part.productId, (lines.get(part.productId) ?? 0) + part.quantity);
54
87
  }
55
- const known = new Set(steps.map((s) => s.id));
56
- if (choices.some((c) => !known.has(c.stepId))) throw Error400('This bundle has changed.');
57
- if (lines.size === 0) throw Error400('Choose at least one product.');
58
88
  return lines;
59
89
  }
60
90
 
@@ -68,8 +98,12 @@ export class BundleService {
68
98
  steps: steps.map((s) => ({
69
99
  description: s.description,
70
100
  maxChoices: s.maxChoices,
101
+ maxPerChoice: s.maxPerChoice,
71
102
  minChoices: s.minChoices,
72
- skus: s.products.map((p) => p.sku),
103
+ role: s.role,
104
+ skus: s.products.map((p) =>
105
+ BundleSku.format({ pricePence: p.kitPricePence, sku: p.sku, slots: p.slots })
106
+ ),
73
107
  title: s.title,
74
108
  })),
75
109
  };
@@ -89,9 +123,114 @@ export class BundleService {
89
123
  return { ...bundle, steps: await this.steps(bundle.id, { activeOnly: true }) };
90
124
  }
91
125
 
126
+ /**
127
+ * Checks a customer's choice against the bundle's steps and prices it. A plain bundle's parts
128
+ * keep their own prices; a discounted bundle costs their total less its discount; a kit costs
129
+ * its base's price, its other parts are single units at no charge. `grouped` says whether the
130
+ * basket keeps it as one line. Throws a 400 with a message the customer can act on.
131
+ */
132
+ async resolve(bundleId: number, choices: Choice[]): Promise<ResolvedBundle> {
133
+ const bundle = await this.db.query.bundles.findFirst({
134
+ where: and(eq(bundles.id, bundleId), eq(bundles.active, true)),
135
+ });
136
+ if (!bundle) throw Error400('This bundle is no longer available.');
137
+ const steps = await this.steps(bundle.id, { activeOnly: true });
138
+ const known = new Set(steps.map((s) => s.id));
139
+ if (choices.some((c) => !known.has(c.stepId))) throw Error400('This bundle has changed.');
140
+ const chosen = new Map(choices.map((c) => [c.stepId, c.productIds]));
141
+ const kit = steps.some((s) => s.role === 'base');
142
+ const parts: BundlePart[] = [];
143
+ const details: string[] = [];
144
+ let slots = 0;
145
+ let kitPrice = 0;
146
+
147
+ for (const step of steps) {
148
+ const ids = chosen.get(step.id) ?? [];
149
+ const offered = (id: number) => {
150
+ const product = step.products.find((p) => p.id === id);
151
+ if (!product) throw Error400(`${step.title}: that choice is not available.`);
152
+ return product;
153
+ };
154
+
155
+ if (step.role === 'fill') {
156
+ if (!slots) throw Error400(`${step.title}: choose a size first.`);
157
+ if (ids.length !== slots) throw Error400(`${step.title}: fill all ${slots} slots.`);
158
+ const counts = new Map<number, number>();
159
+ for (const id of ids) counts.set(id, (counts.get(id) ?? 0) + 1);
160
+ for (const [id, units] of counts) {
161
+ const product = offered(id);
162
+ if (step.maxPerChoice && units > step.maxPerChoice) {
163
+ throw Error400(`${step.title}: at most ${step.maxPerChoice} of ${product.name}.`);
164
+ }
165
+ if (product.units < units)
166
+ throw Error400(`Only ${product.units} of ${product.name} left.`);
167
+ parts.push(Parts.single(product, units));
168
+ details.push(`${units} × ${Parts.label(product)}`);
169
+ }
170
+ continue;
171
+ }
172
+
173
+ const picks = [...new Set(ids)];
174
+ const [min, max] =
175
+ step.role === 'base' || step.role === 'cover' ? [1, 1] : [step.minChoices, step.maxChoices];
176
+ if (picks.length < min || picks.length > max) {
177
+ throw Error400(
178
+ min === max ? `${step.title}: choose ${min}.` : `${step.title}: choose ${min} to ${max}.`
179
+ );
180
+ }
181
+ for (const id of picks) {
182
+ const product = offered(id);
183
+ if (step.role === 'cover') {
184
+ if (!slots) throw Error400(`${step.title}: choose a size first.`);
185
+ if (product.units < slots)
186
+ throw Error400(`Only ${product.units} of ${product.name} left.`);
187
+ parts.push(Parts.single(product, slots));
188
+ details.push(`${step.title}: ${Parts.label(product)}`);
189
+ continue;
190
+ }
191
+ if (product.stock < 1) throw Error400(`${product.name} is out of stock.`);
192
+ if (step.role === 'base') {
193
+ if (!product.slots) throw Error400(`${step.title}: that choice is not available.`);
194
+ slots = product.slots;
195
+ kitPrice = product.kitPricePence ?? product.pricePence;
196
+ }
197
+ parts.push({
198
+ ...Parts.single(product, 1),
199
+ massGrams: product.massGrams,
200
+ pricePence:
201
+ step.role === 'base'
202
+ ? (product.kitPricePence ?? product.pricePence)
203
+ : product.pricePence,
204
+ singleUnits: false,
205
+ });
206
+ details.push(
207
+ step.role === 'base' ? Parts.label(product) : `${step.title}: ${Parts.label(product)}`
208
+ );
209
+ }
210
+ }
211
+ if (parts.length === 0) throw Error400('Choose at least one product.');
212
+
213
+ const listPrice = parts.reduce((sum, p) => sum + p.pricePence * p.quantity, 0);
214
+ const pricePence = kit
215
+ ? kitPrice
216
+ : Math.round((listPrice * (100 - bundle.discountPercent)) / 100);
217
+ return {
218
+ bundle: { id: bundle.id, image: bundle.image, name: bundle.name, slug: bundle.slug },
219
+ details,
220
+ grouped: kit || bundle.discountPercent > 0,
221
+ kit,
222
+ listPricePence: listPrice,
223
+ massGrams: parts.reduce((sum, p) => sum + p.massGrams, 0),
224
+ parts: kit ? parts.map((p) => (p.singleUnits ? { ...p, pricePence: 0 } : p)) : parts,
225
+ pricePence,
226
+ };
227
+ }
228
+
92
229
  /** Creates or replaces a bundle and all its steps. Unknown SKUs are a 400 naming them. */
93
230
  async save(input: BundleInput, now = Date.now()): Promise<number> {
94
- const skus = [...new Set(input.steps.flatMap((s) => s.skus))];
231
+ const skus = [
232
+ ...new Set(input.steps.flatMap((s) => s.skus.map((entry) => BundleSku.parse(entry).sku))),
233
+ ];
95
234
  const skuRows = await Batches.rows(skus, (slice) =>
96
235
  this.db
97
236
  .select({ id: products.id, sku: products.sku })
@@ -107,6 +246,7 @@ export class BundleService {
107
246
  const values = {
108
247
  active: input.active,
109
248
  description: input.description,
249
+ discountPercent: input.discountPercent,
110
250
  image: input.image || null,
111
251
  name: input.name,
112
252
  slug: input.slug,
@@ -119,13 +259,18 @@ export class BundleService {
119
259
  sql<number>`(select ${bundles.id} from ${bundles} where ${bundles.slug} = ${input.slug})`;
120
260
  const stepId = (position: number) =>
121
261
  sql<number>`(select ${bundleSteps.id} from ${bundleSteps} where ${bundleSteps.bundleId} = ${bundleId} and ${bundleSteps.position} = ${position})`;
122
- const offered = input.steps.flatMap((step, position) =>
123
- [...new Set(step.skus)].map((sku, i) => ({
262
+ const offered = input.steps.flatMap((step, position) => {
263
+ const entries = new Map(
264
+ step.skus.map((entry) => [BundleSku.parse(entry).sku, BundleSku.parse(entry)])
265
+ );
266
+ return [...entries.values()].map((entry, i) => ({
124
267
  position: i,
125
- productId: found.get(sku)!,
268
+ pricePence: step.role === 'base' ? entry.pricePence : null,
269
+ productId: found.get(entry.sku)!,
270
+ slots: step.role === 'base' ? entry.slots : null,
126
271
  stepId: stepId(position),
127
- }))
128
- );
272
+ }));
273
+ });
129
274
 
130
275
  // One atomic batch: the bundle and all its steps are saved, or nothing is. Steps are replaced
131
276
  // whole: simpler than diffing, and nothing else points at a step.
@@ -139,8 +284,10 @@ export class BundleService {
139
284
  bundleId,
140
285
  description: step.description,
141
286
  maxChoices: step.maxChoices,
287
+ maxPerChoice: step.role === 'fill' ? step.maxPerChoice : null,
142
288
  minChoices: step.minChoices,
143
289
  position,
290
+ role: step.role,
144
291
  title: step.title,
145
292
  })
146
293
  ),
@@ -166,11 +313,16 @@ export class BundleService {
166
313
  .select({
167
314
  active: products.active,
168
315
  id: products.id,
316
+ kitPricePence: bundleStepProducts.pricePence,
317
+ massGrams: products.massGrams,
169
318
  name: products.name,
319
+ packSize: products.packSize,
170
320
  pricePence: products.pricePence,
171
321
  sku: products.sku,
322
+ slots: bundleStepProducts.slots,
172
323
  slug: products.slug,
173
324
  stepId: bundleStepProducts.stepId,
325
+ units: products.stock,
174
326
  variationLabel: products.variationLabel,
175
327
  })
176
328
  .from(bundleStepProducts)
@@ -1,9 +1,13 @@
1
1
  <script lang="ts">
2
2
  import { resolve } from '$app/paths';
3
- import { getAdminCategories } from '../admin.remote';
4
- import CategoryForm from './CategoryForm.svelte';
5
3
  import Boundary from '@zeyolabs/ui/boundary/Boundary.svelte';
6
4
  import Button from '@zeyolabs/ui/form/Button.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 { getAdminCategories } from '../admin.remote';
10
+ import CategoryForm from './CategoryForm.svelte';
7
11
 
8
12
  type Category = {
9
13
  description: string;
@@ -19,9 +23,9 @@
19
23
 
20
24
  <svelte:head><title>Categories · Admin</title></svelte:head>
21
25
 
22
- <p class="text-sm"><a href={resolve('/products')}>← Products</a></p>
26
+ <Text><a href={resolve('/products')}>← Products</a></Text>
23
27
  <div class="mt-2 flex items-center justify-between">
24
- <h1 class="text-2xl font-semibold">Categories</h1>
28
+ <Title level={1} size="md">Categories</Title>
25
29
  <Button onclick={() => (editing = null)}>New category</Button>
26
30
  </div>
27
31
 
@@ -33,21 +37,20 @@
33
37
 
34
38
  <Boundary message="Could not load categories.">
35
39
  {let rows = $derived(await getAdminCategories())}
36
- <ul class="mt-4 divide-y divide-[var(--line)] rounded-xl border border-[var(--line)] bg-white">
40
+ <ul class="mt-4 divide-y divide-[var(--bd)] rounded-xl border border-[var(--bd)] bg-white">
37
41
  {#each rows as row (row.id)}
38
42
  <li class="flex items-center justify-between gap-3 px-4 py-2 text-sm">
39
- <span
43
+ <Span
40
44
  ><strong>{row.name}</strong>
41
- <span class="text-[var(--ink-muted)]">/category/{row.slug} · {row.products} products</span
42
- ></span
45
+ <Span color="secondary">/category/{row.slug} · {row.products} products</Span></Span
43
46
  >
44
47
  <button class="underline" onclick={() => (editing = row)} type="button">Edit</button>
45
48
  </li>
46
49
  {:else}
47
- <li class="px-4 py-6 text-[var(--ink-muted)]">No categories yet.</li>
50
+ <li class="px-4 py-6 text-[var(--txs)]">No categories yet.</li>
48
51
  {/each}
49
52
  </ul>
50
53
  {#snippet pending()}
51
- <p class="mt-6 text-[var(--ink-muted)]">Loading…</p>
54
+ <Text class="mt-6" color="secondary">Loading…</Text>
52
55
  {/snippet}
53
56
  </Boundary>
@@ -1,9 +1,10 @@
1
1
  <script lang="ts">
2
- import { saveCategoryForm } from '../admin.remote';
3
- import { CategoryFormSchema } from '../schema';
4
2
  import { Form, MessageField, NumberField, TextField } from '@zeyolabs/ui/form';
5
3
  import Button from '@zeyolabs/ui/form/Button.svelte';
6
4
 
5
+ import { saveCategoryForm } from '../admin.remote';
6
+ import { CategoryFormSchema } from '../schema';
7
+
7
8
  type Category = {
8
9
  description: string;
9
10
  id: number;
@@ -26,7 +27,7 @@
26
27
  </script>
27
28
 
28
29
  <Form
29
- class="grid max-w-xl gap-3 rounded-xl border border-[var(--line)] bg-white p-5"
30
+ class="grid max-w-xl gap-3 rounded-xl border border-[var(--bd)] bg-white p-5"
30
31
  defaults={{
31
32
  description: category?.description ?? '',
32
33
  name: category?.name ?? '',
@@ -1,8 +1,11 @@
1
1
  <script lang="ts">
2
2
  import { resolve } from '$app/paths';
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
+
3
7
  import { getAdminProduct, getProductOptions } from '../admin.remote';
4
8
  import ProductForm from './ProductForm.svelte';
5
- import Boundary from '@zeyolabs/ui/boundary/Boundary.svelte';
6
9
 
7
10
  /** The product to edit; leave out for a new one. */
8
11
  let { id }: { id?: number } = $props();
@@ -10,8 +13,8 @@
10
13
 
11
14
  <svelte:head><title>{id ? 'Edit product' : 'New product'} · Admin</title></svelte:head>
12
15
 
13
- <p class="text-sm"><a href={resolve('/products')}>← Products</a></p>
14
- <h1 class="mt-2 mb-6 text-2xl font-semibold">{id ? 'Edit product' : 'New product'}</h1>
16
+ <Text><a href={resolve('/products')}>← Products</a></Text>
17
+ <Title class="mt-2 mb-6" level={1} size="md">{id ? 'Edit product' : 'New product'}</Title>
15
18
 
16
19
  <Boundary message="Could not load the product." statusMessages={{ 404: 'Product not found.' }}>
17
20
  {let options = $derived(await getProductOptions())}
@@ -20,6 +23,6 @@
20
23
  <ProductForm {options} {product} />
21
24
  {/key}
22
25
  {#snippet pending()}
23
- <p class="text-[var(--ink-muted)]">Loading…</p>
26
+ <Text color="secondary">Loading…</Text>
24
27
  {/snippet}
25
28
  </Boundary>
@@ -1,17 +1,21 @@
1
1
  <script lang="ts">
2
2
  import { goto } from '$app/navigation';
3
3
  import { resolve } from '$app/paths';
4
+ import { CheckboxField, Form, MessageField, NumberField, TextField } from '@zeyolabs/ui/form';
5
+ import Button from '@zeyolabs/ui/form/Button.svelte';
6
+ import Text from '@zeyolabs/ui/text/Text.svelte';
7
+ import Title from '@zeyolabs/ui/text/Title.svelte';
8
+
4
9
  import type { getAdminProduct, getProductOptions } from '../admin.remote';
5
- import { saveProductForm } from '../admin.remote';
10
+
6
11
  import { shopContext } from '../../context';
7
- import { Images } from '../../utils/images';
8
12
  import { FormInput } from '../../utils/form-input';
13
+ import { Images } from '../../utils/images';
14
+ import { saveProductForm } from '../admin.remote';
9
15
  import { ProductFormSchema } from '../schema';
10
- import { CheckboxField, Form, MessageField, NumberField, TextField } from '@zeyolabs/ui/form';
11
- import Button from '@zeyolabs/ui/form/Button.svelte';
12
16
 
13
- type Product = Awaited<ReturnType<typeof getAdminProduct>>;
14
17
  type Options = Awaited<ReturnType<typeof getProductOptions>>;
18
+ type Product = Awaited<ReturnType<typeof getAdminProduct>>;
15
19
 
16
20
  let { options, product }: { options: Options; product: null | Product } = $props();
17
21
 
@@ -34,8 +38,8 @@
34
38
  return next;
35
39
  }
36
40
 
37
- const input = 'w-full rounded-md border border-[var(--line)] bg-white px-3 py-1.5';
38
- const section = 'grid gap-4 rounded-xl border border-[var(--line)] bg-white p-5';
41
+ const input = 'w-full rounded-md border border-[var(--bd)] bg-white px-3 py-1.5';
42
+ const section = 'grid gap-4 rounded-xl border border-[var(--bd)] bg-white p-5';
39
43
  </script>
40
44
 
41
45
  <Form
@@ -69,7 +73,7 @@
69
73
  schema={ProductFormSchema}
70
74
  >
71
75
  <section class={section}>
72
- <h2 class="font-semibold">Basics</h2>
76
+ <Title level={2} size="sm">Basics</Title>
73
77
  <TextField name="name" {form}>Name</TextField>
74
78
  <div class="grid gap-4 sm:grid-cols-2">
75
79
  <TextField name="slug" {form} optional placeholder="made from the name">Slug (URL)</TextField>
@@ -79,14 +83,14 @@
79
83
  </div>
80
84
  <CheckboxField name="active" {form}>On sale in the shop</CheckboxField>
81
85
  {#if p && slug && p.slug !== slug}
82
- <p class="text-sm text-[var(--ink-muted)]">
86
+ <Text color="secondary">
83
87
  The old URL /product/{p.slug} will redirect to the new one.
84
- </p>
88
+ </Text>
85
89
  {/if}
86
90
  </section>
87
91
 
88
92
  <section class={section}>
89
- <h2 class="font-semibold">Description</h2>
93
+ <Title level={2} size="sm">Description</Title>
90
94
  <TextField name="shortDescription" {form} optional>
91
95
  Short description (search results, top of the page)
92
96
  </TextField>
@@ -97,17 +101,15 @@
97
101
 
98
102
  <section class={section}>
99
103
  <div>
100
- <h2 class="font-semibold">Images</h2>
101
- <p class="text-sm text-[var(--ink-muted)]">
102
- File names in the product image bucket. The first is the cover.
103
- </p>
104
+ <Title level={2} size="sm">Images</Title>
105
+ <Text color="secondary">File names in the product image bucket. The first is the cover.</Text>
104
106
  </div>
105
107
  <ul class="space-y-3">
106
108
  {#each imageRows as row, i (i)}
107
109
  <li class="flex flex-wrap items-center gap-3">
108
110
  {#if row.src}
109
111
  <img
110
- class="size-14 rounded-md border border-[var(--line)] object-cover"
112
+ class="size-14 rounded-md border border-[var(--bd)] object-cover"
111
113
  alt=""
112
114
  src={Images.url(context.imageBaseUrl, row.src)}
113
115
  />
@@ -128,7 +130,7 @@
128
130
  >Up</Button
129
131
  >
130
132
  <Button
131
- onclick={() => images.set(imageRows.filter((_, j) => j !== i))}
133
+ onclick={() => images.set(imageRows.filter((_: unknown, j: number) => j !== i))}
132
134
  size="sm"
133
135
  variant="secondary">Remove</Button
134
136
  >
@@ -143,7 +145,7 @@
143
145
  </section>
144
146
 
145
147
  <section class={section}>
146
- <h2 class="font-semibold">Categories</h2>
148
+ <Title level={2} size="sm">Categories</Title>
147
149
  <div class="grid gap-2 sm:grid-cols-2">
148
150
  {#each options.categories as category (category.id)}
149
151
  <label class="flex items-center gap-2 text-sm">
@@ -151,18 +153,18 @@
151
153
  {category.name}
152
154
  </label>
153
155
  {:else}
154
- <p class="text-sm text-[var(--ink-muted)]">No categories yet.</p>
156
+ <Text color="secondary">No categories yet.</Text>
155
157
  {/each}
156
158
  </div>
157
159
  </section>
158
160
 
159
161
  <section class={section}>
160
162
  <div>
161
- <h2 class="font-semibold">Variation</h2>
162
- <p class="text-sm text-[var(--ink-muted)]">
163
+ <Title level={2} size="sm">Variation</Title>
164
+ <Text color="secondary">
163
165
  Products in the same group show as options of each other, e.g. group "Colour", option
164
166
  "Black".
165
- </p>
167
+ </Text>
166
168
  </div>
167
169
  <div class="grid gap-4 sm:grid-cols-2">
168
170
  <label class="text-sm font-medium">
@@ -182,10 +184,10 @@
182
184
 
183
185
  <section class={section}>
184
186
  <div>
185
- <h2 class="font-semibold">Stock and shipping</h2>
186
- <p class="text-sm text-[var(--ink-muted)]">
187
+ <Title level={2} size="sm">Stock and shipping</Title>
188
+ <Text color="secondary">
187
189
  Stock itself is set on the Stock page{p ? ` (now ${p.stock} units)` : ''}.
188
- </p>
190
+ </Text>
189
191
  </div>
190
192
  <div class="grid gap-4 sm:grid-cols-3">
191
193
  <NumberField name="massGrams" {form} inputmode="numeric">Weight (g)</NumberField>
@@ -200,11 +202,11 @@
200
202
 
201
203
  <section class={section}>
202
204
  <div>
203
- <h2 class="font-semibold">Made of other products</h2>
204
- <p class="text-sm text-[var(--ink-muted)]">
205
+ <Title level={2} size="sm">Made of other products</Title>
206
+ <Text color="secondary">
205
207
  Leave empty for a normal product. A combined product has no stock of its own: it sells as
206
208
  many complete sets as its parts allow, and selling one takes stock from the parts.
207
- </p>
209
+ </Text>
208
210
  </div>
209
211
  <ul class="space-y-2">
210
212
  {#each componentRows as _, i (i)}
@@ -222,7 +224,7 @@
222
224
  min="1"
223
225
  />
224
226
  <Button
225
- onclick={() => components.set(componentRows.filter((_, j) => j !== i))}
227
+ onclick={() => components.set(componentRows.filter((_: unknown, j: number) => j !== i))}
226
228
  size="sm"
227
229
  variant="secondary">Remove</Button
228
230
  >
@@ -2,10 +2,13 @@
2
2
  import { goto } from '$app/navigation';
3
3
  import { resolve } from '$app/paths';
4
4
  import { page } from '$app/state';
5
- import { getAdminProducts } from '../admin.remote';
6
- import { Money } from '../../utils/money';
7
5
  import Badge from '@zeyolabs/ui/badge/Badge.svelte';
8
6
  import Boundary from '@zeyolabs/ui/boundary/Boundary.svelte';
7
+ import Text from '@zeyolabs/ui/text/Text.svelte';
8
+ import Title from '@zeyolabs/ui/text/Title.svelte';
9
+
10
+ import { Money } from '../../utils/money';
11
+ import { getAdminProducts } from '../admin.remote';
9
12
 
10
13
  const q = $derived(page.url.searchParams.get('q') ?? '');
11
14
  </script>
@@ -13,18 +16,17 @@
13
16
  <svelte:head><title>Products · Admin</title></svelte:head>
14
17
 
15
18
  <div class="flex flex-wrap items-center justify-between gap-3">
16
- <h1 class="text-2xl font-semibold">Products</h1>
19
+ <Title level={1} size="md">Products</Title>
17
20
  <div class="flex gap-2 text-sm">
18
21
  <a
19
- class="rounded-md border border-[var(--line)] bg-white px-3 py-1.5"
22
+ class="rounded-md border border-[var(--bd)] bg-white px-3 py-1.5"
20
23
  href={resolve('/categories')}>Categories</a
21
24
  >
22
- <a
23
- class="rounded-md border border-[var(--line)] bg-white px-3 py-1.5"
24
- href={resolve('/bundles')}>Bundles</a
25
+ <a class="rounded-md border border-[var(--bd)] bg-white px-3 py-1.5" href={resolve('/bundles')}
26
+ >Bundles</a
25
27
  >
26
28
  <a
27
- class="rounded-md bg-[var(--leaf-dark)] px-3 py-1.5 text-white no-underline"
29
+ class="rounded-md bg-[var(--acc)] px-3 py-1.5 text-white no-underline"
28
30
  href={resolve('/products/new')}>New product</a
29
31
  >
30
32
  </div>
@@ -44,7 +46,7 @@
44
46
  <input
45
47
  id="product-q"
46
48
  name="q"
47
- class="w-full max-w-sm rounded-md border border-[var(--line)] bg-white px-3 py-1.5"
49
+ class="w-full max-w-sm rounded-md border border-[var(--bd)] bg-white px-3 py-1.5"
48
50
  placeholder="Name or SKU"
49
51
  type="search"
50
52
  value={q}
@@ -53,9 +55,9 @@
53
55
 
54
56
  <Boundary message="Could not load products.">
55
57
  {let rows = $derived(await getAdminProducts(q))}
56
- <div class="mt-4 overflow-x-auto rounded-xl border border-[var(--line)] bg-white">
58
+ <div class="mt-4 overflow-x-auto rounded-xl border border-[var(--bd)] bg-white">
57
59
  <table class="w-full text-left text-sm">
58
- <thead class="border-b border-[var(--line)] text-[var(--ink-muted)]">
60
+ <thead class="border-b border-[var(--bd)] text-[var(--txs)]">
59
61
  <tr>
60
62
  <th class="px-4 py-2 font-medium">Product</th>
61
63
  <th class="px-4 py-2 font-medium">SKU</th>
@@ -63,7 +65,7 @@
63
65
  <th class="px-4 py-2 text-right font-medium">Stock</th>
64
66
  </tr>
65
67
  </thead>
66
- <tbody class="divide-y divide-[var(--line)]">
68
+ <tbody class="divide-y divide-[var(--bd)]">
67
69
  {#each rows as row (row.id)}
68
70
  <tr>
69
71
  <td class="px-4 py-2">
@@ -77,12 +79,12 @@
77
79
  <td class="px-4 py-2 text-right">{row.stock}</td>
78
80
  </tr>
79
81
  {:else}
80
- <tr><td class="px-4 py-6 text-[var(--ink-muted)]" colspan="4">No products found.</td></tr>
82
+ <tr><td class="px-4 py-6 text-[var(--txs)]" colspan="4">No products found.</td></tr>
81
83
  {/each}
82
84
  </tbody>
83
85
  </table>
84
86
  </div>
85
87
  {#snippet pending()}
86
- <p class="mt-6 text-[var(--ink-muted)]">Loading…</p>
88
+ <Text class="mt-6" color="secondary">Loading…</Text>
87
89
  {/snippet}
88
90
  </Boundary>