@profitstudio/booking-engine 0.0.0-stage → 2.0.0-beta.1

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 (114) hide show
  1. package/CHANGELOG.md +562 -0
  2. package/LICENSE +21 -0
  3. package/README.md +18 -2
  4. package/THIRD_PARTY_NOTICES.md +41 -0
  5. package/bin/booking-engine.mjs +575 -0
  6. package/bin/connect.mjs +408 -0
  7. package/bin/photos.mjs +82 -0
  8. package/dist/admin/BookingAdmin.d.ts +22 -0
  9. package/dist/admin/BookingAdmin.js +337 -0
  10. package/dist/admin/admin.css +1423 -0
  11. package/dist/admin/alerts.d.ts +10 -0
  12. package/dist/admin/alerts.js +11 -0
  13. package/dist/admin/booking-detail.d.ts +37 -0
  14. package/dist/admin/booking-detail.js +149 -0
  15. package/dist/admin/content-inputs.d.ts +15 -0
  16. package/dist/admin/content-inputs.js +105 -0
  17. package/dist/admin/context.d.ts +37 -0
  18. package/dist/admin/context.js +8 -0
  19. package/dist/admin/drawer.d.ts +14 -0
  20. package/dist/admin/drawer.js +56 -0
  21. package/dist/admin/feedback.d.ts +32 -0
  22. package/dist/admin/feedback.js +70 -0
  23. package/dist/admin/fields.d.ts +27 -0
  24. package/dist/admin/fields.js +146 -0
  25. package/dist/admin/fonts/OFL-Geist-Mono.txt +93 -0
  26. package/dist/admin/fonts/OFL-Geist.txt +93 -0
  27. package/dist/admin/fonts/geist-latin-wght-normal.woff2 +0 -0
  28. package/dist/admin/fonts/geist-mono-latin-wght-normal.woff2 +0 -0
  29. package/dist/admin/icons.d.ts +66 -0
  30. package/dist/admin/icons.js +72 -0
  31. package/dist/admin/image-upload.d.ts +58 -0
  32. package/dist/admin/image-upload.js +111 -0
  33. package/dist/admin/index.d.ts +6 -0
  34. package/dist/admin/index.js +6 -0
  35. package/dist/admin/lucide.generated.d.ts +521 -0
  36. package/dist/admin/lucide.generated.js +76 -0
  37. package/dist/admin/sections/BookingsSection.d.ts +1 -0
  38. package/dist/admin/sections/BookingsSection.js +137 -0
  39. package/dist/admin/sections/EmailSection.d.ts +8 -0
  40. package/dist/admin/sections/EmailSection.js +182 -0
  41. package/dist/admin/sections/HoursSection.d.ts +1 -0
  42. package/dist/admin/sections/HoursSection.js +110 -0
  43. package/dist/admin/sections/OverviewSection.d.ts +1 -0
  44. package/dist/admin/sections/OverviewSection.js +427 -0
  45. package/dist/admin/sections/ServicesSection.d.ts +1 -0
  46. package/dist/admin/sections/ServicesSection.js +236 -0
  47. package/dist/admin/sections/SettingsSection.d.ts +10 -0
  48. package/dist/admin/sections/SettingsSection.js +96 -0
  49. package/dist/admin/sections/WebsiteSection.d.ts +1 -0
  50. package/dist/admin/sections/WebsiteSection.js +228 -0
  51. package/dist/admin/sections.d.ts +22 -0
  52. package/dist/admin/sections.js +29 -0
  53. package/dist/admin/setup.d.ts +1 -0
  54. package/dist/admin/setup.js +45 -0
  55. package/dist/admin/today.d.ts +43 -0
  56. package/dist/admin/today.js +115 -0
  57. package/dist/admin/ui.d.ts +134 -0
  58. package/dist/admin/ui.js +220 -0
  59. package/dist/calendar.d.ts +64 -0
  60. package/dist/calendar.js +139 -0
  61. package/dist/client.d.ts +147 -0
  62. package/dist/client.js +507 -0
  63. package/dist/config.d.ts +25 -0
  64. package/dist/config.js +120 -0
  65. package/dist/content/image.d.ts +20 -0
  66. package/dist/content/image.js +90 -0
  67. package/dist/content/resolve.d.ts +12 -0
  68. package/dist/content/resolve.js +73 -0
  69. package/dist/content/schema.d.ts +119 -0
  70. package/dist/content/schema.js +53 -0
  71. package/dist/content/store.d.ts +48 -0
  72. package/dist/content/store.js +123 -0
  73. package/dist/content/validate.d.ts +33 -0
  74. package/dist/content/validate.js +177 -0
  75. package/dist/errors.d.ts +19 -0
  76. package/dist/errors.js +94 -0
  77. package/dist/generated/manifest.d.ts +6 -0
  78. package/dist/generated/manifest.js +7 -0
  79. package/dist/index.d.ts +20 -0
  80. package/dist/index.js +20 -0
  81. package/dist/presets/hair-salon.d.ts +8 -0
  82. package/dist/presets/hair-salon.js +94 -0
  83. package/dist/presets/index.d.ts +5 -0
  84. package/dist/presets/index.js +6 -0
  85. package/dist/preview.d.ts +18 -0
  86. package/dist/preview.js +134 -0
  87. package/dist/semver.d.ts +16 -0
  88. package/dist/semver.js +55 -0
  89. package/dist/time.d.ts +31 -0
  90. package/dist/time.js +138 -0
  91. package/dist/types.d.ts +477 -0
  92. package/dist/types.js +3 -0
  93. package/dist/vite.d.ts +52 -0
  94. package/dist/vite.js +150 -0
  95. package/docs/BUILD-A-SITE.md +203 -0
  96. package/docs/EMAIL-SETUP.md +224 -0
  97. package/docs/INTEGRATION.md +1109 -0
  98. package/engine.manifest.json +90 -0
  99. package/functions/booking-mailer/deno.json +6 -0
  100. package/functions/booking-mailer/index.ts +44 -0
  101. package/functions/booking-mailer/mailer.js +156 -0
  102. package/functions/booking-mailer/providers/index.js +42 -0
  103. package/functions/booking-mailer/providers/resend.js +75 -0
  104. package/functions/booking-mailer/templates.js +345 -0
  105. package/migrations/0001_core.sql +1673 -0
  106. package/migrations/0002_security_hardening.sql +711 -0
  107. package/migrations/0003_private_definers_and_holds.sql +808 -0
  108. package/migrations/0004_verified_requests.sql +1702 -0
  109. package/migrations/0005_scoped_mailer_credential.sql +347 -0
  110. package/migrations/0006_trusted_client_ip.sql +56 -0
  111. package/migrations/0007_site_content.sql +380 -0
  112. package/migrations/0008_service_images_opening_times.sql +328 -0
  113. package/package.json +85 -4
  114. package/templates/BOOKING_ENGINE.md +61 -0
@@ -0,0 +1,236 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import { formatMoney } from '../../time.js';
4
+ import { useAdmin } from '../context.js';
5
+ import { Drawer } from '../drawer.js';
6
+ import { Icon } from '../icons.js';
7
+ import { IMAGE_PREPARATION_TEXT, IMAGE_TYPES_TEXT, ImageDropZone, ImageFrame, UploadProblem, useImageUpload } from '../image-upload.js';
8
+ import { Badge, Button, EmptyState, ErrorNotice, Field, IconButton, Notice, PageHeader, SkeletonRows, Switch, centsToInput, formatMinutes, inputToCents, useResult } from '../ui.js';
9
+ const EMPTY = {
10
+ name: '',
11
+ description: '',
12
+ durationMinutes: '60',
13
+ bufferAfterMinutes: '0',
14
+ price: '',
15
+ priceFrom: false,
16
+ isActive: true,
17
+ sortOrder: '0',
18
+ photo: null,
19
+ savedPhoto: null,
20
+ };
21
+ const ALT_MAX = 300;
22
+ /** Uploads younger than this are never tidied away: another admin may be editing with them. */
23
+ const TIDY_AFTER_MS = 24 * 3600_000;
24
+ const fromImage = (image) => image ? { path: image.path, alt: image.alt, width: image.width, height: image.height, url: image.url } : null;
25
+ const oneLine = (text) => text.replace(/\s+/g, ' ').trim();
26
+ const samePhoto = (a, b) => (a?.path ?? null) === (b?.path ?? null) && oneLine(a?.alt ?? '') === oneLine(b?.alt ?? '');
27
+ function toDraft(s) {
28
+ const photo = fromImage(s.image);
29
+ return {
30
+ id: s.id,
31
+ name: s.name,
32
+ description: s.description ?? '',
33
+ durationMinutes: String(s.durationMinutes),
34
+ bufferAfterMinutes: String(s.bufferAfterMinutes),
35
+ price: centsToInput(s.priceCents),
36
+ priceFrom: s.priceFrom,
37
+ isActive: s.isActive,
38
+ sortOrder: String(s.sortOrder),
39
+ photo,
40
+ savedPhoto: photo,
41
+ };
42
+ }
43
+ export function ServicesSection() {
44
+ const { engine, settings, presets, refreshSettings, toast, confirm } = useAdmin();
45
+ const [load, reload] = useResult(() => engine.admin.listServices(), []);
46
+ const [draft, setDraft] = useState(null);
47
+ const [error, setError] = useState(null);
48
+ const [photoProblem, setPhotoProblem] = useState(null);
49
+ const [pageError, setPageError] = useState(null);
50
+ const [busy, setBusy] = useState(null);
51
+ const nameRef = useRef(null);
52
+ function edit(next) {
53
+ setDraft(next);
54
+ setError(null);
55
+ setPhotoProblem(null);
56
+ }
57
+ /**
58
+ * Delete service photos no service uses any more — only files older than a
59
+ * day, so an upload another admin has not saved yet is never taken away.
60
+ * Quiet: a failure leaves a file behind for the next tidy-up.
61
+ */
62
+ async function tidyPhotos() {
63
+ try {
64
+ const [services, files] = await Promise.all([engine.admin.listServices(), engine.admin.listServiceImages()]);
65
+ if (!services.ok || !files.ok)
66
+ return;
67
+ const used = new Set(services.data.map((s) => s.image?.path).filter(Boolean));
68
+ const stale = files.data.filter((f) => !used.has(f.path) && f.createdAt && Date.now() - Date.parse(f.createdAt) > TIDY_AFTER_MS);
69
+ if (stale.length)
70
+ await engine.admin.deleteServiceImages(stale.map((f) => f.path));
71
+ }
72
+ catch {
73
+ // Nothing to tell the owner: the next tidy-up tries again.
74
+ }
75
+ }
76
+ async function save(event) {
77
+ event.preventDefault();
78
+ if (!draft || busy)
79
+ return;
80
+ const priceCents = inputToCents(draft.price);
81
+ if (priceCents === undefined) {
82
+ setError({ text: 'Enter the price as a number, e.g. 65 or 65.50.', field: 'price' });
83
+ return;
84
+ }
85
+ // The photo is sent only when it changed: an untouched service saves the same on any database.
86
+ const photoChanged = !samePhoto(draft.photo, draft.savedPhoto);
87
+ const input = {
88
+ ...(draft.id ? { id: draft.id } : {}),
89
+ name: draft.name,
90
+ description: draft.description || null,
91
+ durationMinutes: Number(draft.durationMinutes),
92
+ bufferAfterMinutes: Number(draft.bufferAfterMinutes || 0),
93
+ priceCents,
94
+ priceFrom: draft.priceFrom,
95
+ isActive: draft.isActive,
96
+ sortOrder: Number(draft.sortOrder || 0),
97
+ ...(photoChanged
98
+ ? {
99
+ image: draft.photo
100
+ ? {
101
+ path: draft.photo.path,
102
+ alt: oneLine(draft.photo.alt),
103
+ ...(draft.photo.width ? { width: draft.photo.width } : {}),
104
+ ...(draft.photo.height ? { height: draft.photo.height } : {}),
105
+ }
106
+ : null,
107
+ }
108
+ : {}),
109
+ };
110
+ setBusy('save');
111
+ setPhotoProblem(null);
112
+ const r = await engine.admin.saveService(input);
113
+ setBusy(null);
114
+ if (!r.ok) {
115
+ if (r.error.code === 'SCHEMA_INCOMPATIBLE') {
116
+ // The database cannot store photos yet: say so in the Photo field and let
117
+ // the next Save store everything else (the unsaved photo change is dropped).
118
+ setPhotoProblem(r.error);
119
+ setError(null);
120
+ setDraft((d) => (d ? { ...d, photo: d.savedPhoto } : d));
121
+ }
122
+ else if (r.error.field === 'image') {
123
+ setPhotoProblem(r.error);
124
+ setError(null);
125
+ }
126
+ else
127
+ setError({ text: r.error.message, field: r.error.field });
128
+ return;
129
+ }
130
+ toast({ title: `“${r.data.name}” saved.`, detail: r.data.isActive ? 'Live on your website' : 'Not bookable online' });
131
+ const replacedOrRemoved = photoChanged && draft.savedPhoto !== null && draft.savedPhoto.path !== draft.photo?.path;
132
+ setDraft(null);
133
+ reload();
134
+ if (replacedOrRemoved)
135
+ void tidyPhotos();
136
+ }
137
+ async function remove() {
138
+ if (!draft?.id)
139
+ return;
140
+ const ok = await confirm({
141
+ title: `Delete “${draft.name}”?`,
142
+ body: 'This cannot be undone. A service that already has bookings cannot be deleted: switch off “Bookable online” instead.',
143
+ confirmLabel: 'Delete service',
144
+ cancelLabel: 'Keep it',
145
+ });
146
+ if (!ok)
147
+ return;
148
+ setBusy('delete');
149
+ const r = await engine.admin.deleteService(draft.id);
150
+ setBusy(null);
151
+ if (!r.ok) {
152
+ setError({
153
+ text: r.error.code === 'CONFLICT' ? 'This service has bookings, so it cannot be deleted. Switch off “Bookable online” to stop new bookings.' : r.error.message,
154
+ });
155
+ return;
156
+ }
157
+ toast({ title: `“${draft.name}” deleted.` });
158
+ setDraft(null);
159
+ reload();
160
+ void tidyPhotos();
161
+ }
162
+ async function applyPreset(preset) {
163
+ const ok = await confirm({
164
+ title: `Add the ${preset.label} starter set?`,
165
+ body: `It adds ${preset.services.length} services with example prices, replaces your opening hours and sets the booking policies. You can edit everything afterwards.`,
166
+ confirmLabel: 'Add the starter set',
167
+ tone: 'primary',
168
+ });
169
+ if (!ok)
170
+ return;
171
+ setBusy(preset.id);
172
+ setPageError(null);
173
+ const r = await engine.admin.applyPreset(preset);
174
+ setBusy(null);
175
+ if (!r.ok) {
176
+ setPageError(r.error.message);
177
+ return;
178
+ }
179
+ toast({ title: `${r.data.servicesAdded} services added.`, detail: 'Review the prices before you go live' });
180
+ await refreshSettings();
181
+ reload();
182
+ }
183
+ const services = load.state === 'ready' ? load.data : [];
184
+ const fieldError = (name) => (error?.field === name ? error.text : null);
185
+ const price = (s) => s.priceCents === null ? 'On request' : `${s.priceFrom ? 'from ' : ''}${formatMoney(s.priceCents, settings.currency, settings.locale)}`;
186
+ return (_jsxs("section", { "aria-labelledby": "pbe-services-title", className: "pbe-page", children: [_jsx(PageHeader, { id: "pbe-services-title", title: "Services", sub: "What customers can book on your website, how long it takes and what it costs.", actions: _jsx(Button, { variant: "primary", icon: "add", onClick: () => edit({ ...EMPTY, sortOrder: String((services.at(-1)?.sortOrder ?? -1) + 1) }), children: "Add service" }) }), pageError ? _jsx(Notice, { kind: "error", children: pageError }) : null, load.state === 'error' ? _jsx(ErrorNotice, { error: load.error, onRetry: reload }) : null, load.state === 'loading' ? (_jsx("div", { className: "pbe-card", children: _jsx(SkeletonRows, { rows: 4, label: "Loading services\u2026" }) })) : null, load.state === 'ready' && services.length === 0 ? (_jsx(EmptyState, { icon: "services", title: "No services yet", variant: "card", action: _jsxs(_Fragment, { children: [presets.map((p) => (_jsxs(Button, { variant: "primary", loading: busy === p.id, onClick: () => void applyPreset(p), children: ["Use the ", p.label, " starter set"] }, p.id))), _jsx(Button, { icon: "add", onClick: () => edit({ ...EMPTY }), children: "Add your own" })] }), children: "Start from a starter set and adjust it, or add your own services one by one." })) : null, services.length > 0 ? (_jsxs("table", { className: "pbe-table pbe-table--card pbe-svc-table", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", children: "Service" }), _jsx("th", { scope: "col", children: "Duration" }), _jsx("th", { scope: "col", children: "Price" }), _jsx("th", { scope: "col", children: "Online" }), _jsx("th", { scope: "col", children: _jsx("span", { className: "pbe-sr-only", children: "Actions" }) })] }) }), _jsx("tbody", { children: services.map((s) => (_jsxs("tr", { className: s.isActive ? undefined : 'pbe-row-muted', children: [_jsx("td", { children: _jsxs("div", { className: "pbe-svc-cell", children: [_jsx(ServiceThumb, { image: s.image }), _jsxs("div", { className: "pbe-cell-main", children: [_jsx("strong", { children: s.name }), s.description ? _jsx("span", { className: "pbe-cell-sub", children: s.description }) : null] })] }) }), _jsxs("td", { className: "pbe-nowrap", children: [formatMinutes(s.durationMinutes), s.bufferAfterMinutes ? _jsxs("div", { className: "pbe-cell-sub", children: ["+ ", s.bufferAfterMinutes, " min cleanup"] }) : null] }), _jsx("td", { className: "pbe-nowrap pbe-tnum", children: price(s) }), _jsx("td", { children: s.isActive ? _jsx(Badge, { tone: "ok", children: "Bookable" }) : _jsx("span", { className: "pbe-tag", children: "Not bookable" }) }), _jsx("td", { className: "pbe-cell-actions", children: _jsx(Button, { size: "sm", icon: "edit", "aria-label": `Edit ${s.name}`, onClick: () => edit(toDraft(s)), children: "Edit" }) })] }, s.id))) })] })) : null, draft ? (_jsx(Drawer, { onClose: () => edit(null), labelledBy: "pbe-svc-title", focusRef: nameRef, children: _jsxs("form", { className: "pbe-drawer-form", onSubmit: save, "aria-label": draft.id ? 'Edit service' : 'New service', children: [_jsxs("div", { className: "pbe-drawer-bar", children: [_jsx("h2", { id: "pbe-svc-title", className: "pbe-drawer-heading", children: draft.id ? 'Edit service' : 'New service' }), _jsx("div", { className: "pbe-drawer-nav", children: _jsx(IconButton, { icon: "close", label: "Close", onClick: () => edit(null) }) })] }), _jsxs("div", { className: "pbe-drawer-body", children: [error && !error.field ? _jsx(Notice, { kind: "error", children: error.text }) : null, _jsx(Field, { id: "svc-name", label: "Name", error: fieldError('name'), children: _jsx("input", { id: "svc-name", ref: nameRef, required: true, maxLength: 120, value: draft.name, onChange: (e) => setDraft({ ...draft, name: e.target.value }) }) }), _jsx(Field, { id: "svc-description", label: "Description", help: "Optional. Shown on the website.", error: fieldError('description'), children: _jsx("textarea", { id: "svc-description", maxLength: 2000, rows: 3, value: draft.description, onChange: (e) => setDraft({ ...draft, description: e.target.value }) }) }), _jsx(PhotoField, { photo: draft.photo, saved: draft.savedPhoto, problem: photoProblem, onChange: (photo) => {
187
+ setPhotoProblem(null);
188
+ setDraft((d) => (d ? { ...d, photo } : d));
189
+ } }), _jsxs("div", { className: "pbe-grid-2", children: [_jsx(Field, { id: "svc-duration", label: "Duration (minutes)", help: "How long the customer is booked for.", error: fieldError('durationMinutes'), children: _jsx("input", { id: "svc-duration", type: "number", min: 5, max: 720, step: 5, required: true, value: draft.durationMinutes, onChange: (e) => setDraft({ ...draft, durationMinutes: e.target.value }) }) }), _jsx(Field, { id: "svc-buffer", label: "Cleanup after (minutes)", help: "Blocks your calendar after the service. Not shown to customers.", error: fieldError('bufferAfterMinutes'), children: _jsx("input", { id: "svc-buffer", type: "number", min: 0, max: 240, step: 5, value: draft.bufferAfterMinutes, onChange: (e) => setDraft({ ...draft, bufferAfterMinutes: e.target.value }) }) }), _jsx(Field, { id: "svc-price", label: `Price (${settings.currency})`, help: "Leave empty for \u201Cprice on request\u201D.", error: fieldError('price') ?? fieldError('priceCents'), children: _jsx("input", { id: "svc-price", inputMode: "decimal", value: draft.price, onChange: (e) => setDraft({ ...draft, price: e.target.value }) }) }), _jsx(Field, { id: "svc-order", label: "Display order", help: "Lower numbers appear first.", error: fieldError('sortOrder'), children: _jsx("input", { id: "svc-order", type: "number", value: draft.sortOrder, onChange: (e) => setDraft({ ...draft, sortOrder: e.target.value }) }) })] }), _jsx(Switch, { id: "svc-from", label: "Starting price", help: "Shown as \u201Cfrom \u2026\u201D, for services whose price depends on the customer.", checked: draft.priceFrom, onChange: (v) => setDraft({ ...draft, priceFrom: v }) }), _jsx(Switch, { id: "svc-active", label: "Bookable online", help: "Off: the service stays in your list but customers cannot book it.", checked: draft.isActive, onChange: (v) => setDraft({ ...draft, isActive: v }) })] }), _jsx("div", { className: "pbe-drawer-foot", children: _jsxs("div", { className: "pbe-form-actions", children: [draft.id ? (_jsx(Button, { variant: "danger-quiet", icon: "remove", loading: busy === 'delete', disabled: busy === 'save', onClick: () => void remove(), children: "Delete" })) : null, _jsx("span", { className: "pbe-push" }), _jsx(Button, { onClick: () => edit(null), disabled: busy !== null, children: "Cancel" }), _jsx(Button, { type: "submit", variant: "primary", loading: busy === 'save', disabled: busy === 'delete', children: "Save" })] }) })] }) })) : null] }));
190
+ }
191
+ /** The list's small photo: the owner's photo, or a quiet empty tile (never a stand-in image). */
192
+ function ServiceThumb({ image }) {
193
+ return image ? (_jsx("span", { className: "pbe-svc-thumb", children: _jsx("img", { src: image.url, alt: "", width: 40, height: 40, loading: "lazy", decoding: "async" }) })) : (_jsxs("span", { className: "pbe-svc-thumb pbe-svc-thumb--none", children: [_jsx(Icon, { name: "image" }), _jsx("span", { className: "pbe-sr-only", children: "No photo" })] }));
194
+ }
195
+ /**
196
+ * The service's optional photo: add one (choose or drop a file), replace or
197
+ * remove it, and describe it for people who cannot see it. Nothing is stored
198
+ * until the service is saved.
199
+ */
200
+ function PhotoField({ photo, saved, problem, onChange, }) {
201
+ const { engine } = useAdmin();
202
+ const box = useRef(null);
203
+ // The control the owner used disappears when the field changes state (add ↔ photo):
204
+ // focus moves to the one that took its place.
205
+ const focusNext = useRef(null);
206
+ const hasPhoto = photo !== null;
207
+ useEffect(() => {
208
+ const target = focusNext.current;
209
+ focusNext.current = null;
210
+ if (target)
211
+ box.current?.querySelector(target === 'add' ? '.pbe-dropzone' : '[data-photo-action="replace"]')?.focus();
212
+ }, [hasPhoto]);
213
+ const focusWithin = () => {
214
+ const active = document.activeElement;
215
+ return !active || active === document.body || Boolean(box.current?.contains(active));
216
+ };
217
+ const upload = useImageUpload((file) => engine.admin.uploadServiceImage(file), (image) => {
218
+ if (focusWithin())
219
+ focusNext.current = 'replace';
220
+ onChange({ path: image.path, alt: photo?.alt ?? '', width: image.width, height: image.height, url: engine.mediaUrl(image.path) });
221
+ });
222
+ const shown = problem ?? upload.error;
223
+ const outdated = shown?.code === 'SCHEMA_INCOMPATIBLE';
224
+ const fresh = photo !== null && photo.path !== saved?.path;
225
+ const removed = photo === null && saved !== null;
226
+ const alt = photo?.alt ?? '';
227
+ return (_jsxs("fieldset", { ref: box, className: `pbe-fieldset pbe-photo${shown && !outdated ? ' pbe-photo--error' : ''}`, "aria-describedby": "svc-photo-help", children: [_jsx("legend", { className: "pbe-photo-legend", children: "Photo" }), _jsx("p", { className: "pbe-help pbe-photo-help", id: "svc-photo-help", children: "Optional. Your website decides how \u2014 and whether \u2014 to show it; nothing about booking depends on it." }), outdated ? (_jsxs(Notice, { kind: "info", children: [_jsx("strong", { children: "Photos need a database update." }), " ", shown.message, " Everything else about this service saves as usual."] })) : photo ? (_jsxs(_Fragment, { children: [_jsxs("div", { className: `pbe-photo-row${upload.over ? ' pbe-photo-row--over' : ''}`, ...upload.dropTarget, children: [_jsx(ImageFrame, { src: photo.url, ratio: 1, className: "pbe-photo-frame" }), upload.input, _jsxs("div", { className: "pbe-form-actions pbe-photo-actions", children: [_jsx(Button, { size: "sm", icon: "upload", "data-photo-action": "replace", "aria-describedby": "svc-photo-note", loading: upload.busy, onClick: upload.choose, children: "Replace photo" }), _jsx(Button, { size: "sm", variant: "danger-quiet", icon: "remove", disabled: upload.busy, onClick: () => {
228
+ focusNext.current = 'add';
229
+ upload.clearError();
230
+ onChange(null);
231
+ }, children: "Remove" })] }), _jsx("p", { className: "pbe-help pbe-photo-note", id: "svc-photo-note", "aria-live": "polite", children: fresh ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "pbe-photo-state", children: "New photo" }), " Saved with the service when you press Save."] })) : (`${IMAGE_TYPES_TEXT}. ${IMAGE_PREPARATION_TEXT}`) })] }), _jsxs("div", { className: "pbe-field", children: [_jsxs("div", { className: "pbe-field-head", children: [_jsx("label", { htmlFor: "svc-photo-alt", children: "Description for screen readers" }), _jsxs("span", { className: `pbe-counter${alt.length > ALT_MAX ? ' pbe-counter--over' : ''}`, "aria-hidden": "true", children: [alt.length, "/", ALT_MAX] })] }), _jsx("input", { id: "svc-photo-alt", type: "text", maxLength: ALT_MAX, value: alt, "aria-describedby": "svc-photo-alt-help", onChange: (e) => onChange({ ...photo, alt: e.target.value }) }), _jsx("p", { className: "pbe-help", id: "svc-photo-alt-help", children: "Your website uses it as the photo\u2019s text alternative. Leave it empty if the photo only illustrates the service." })] })] })) : (_jsxs(_Fragment, { children: [upload.input, _jsx(ImageDropZone, { upload: upload, title: "Add a photo", hint: `Choose a file or drop it here · ${IMAGE_TYPES_TEXT}`, describedBy: `svc-photo-prep${removed ? ' svc-photo-removed' : ''}` }), _jsx("p", { className: "pbe-help", id: "svc-photo-prep", children: IMAGE_PREPARATION_TEXT }), removed ? (_jsxs("div", { className: "pbe-photo-undo", children: [_jsx("p", { className: "pbe-help", id: "svc-photo-removed", children: "The photo is removed when you press Save." }), _jsx(Button, { size: "sm", variant: "quiet", icon: "reset", onClick: () => {
232
+ focusNext.current = 'replace';
233
+ upload.clearError();
234
+ onChange(saved);
235
+ }, children: "Undo" })] })) : null] })), shown && !outdated ? _jsx(UploadProblem, { error: shown }) : null] }));
236
+ }
@@ -0,0 +1,10 @@
1
+ import { type SettingGroup } from '../fields.js';
2
+ /**
3
+ * One settings group, rendered from the field schema: each setting as a row
4
+ * (what it is and what it does on the left, the control on the right). Saves
5
+ * only the fields that changed.
6
+ */
7
+ export declare function SettingsSection({ group, embedded }: {
8
+ group: SettingGroup;
9
+ embedded?: boolean;
10
+ }): import("react").JSX.Element;
@@ -0,0 +1,96 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useMemo, useState } from 'react';
3
+ import { deviceTimeZone } from '../../time.js';
4
+ import { useAdmin } from '../context.js';
5
+ import { CURRENCY_SUGGESTIONS } from '../fields.js';
6
+ import { Icon } from '../icons.js';
7
+ import { Button, Notice, PageHeader } from '../ui.js';
8
+ function initialValues(group, settings) {
9
+ const values = {};
10
+ for (const f of group.fields) {
11
+ const v = settings[f.key];
12
+ values[f.key] = v === null || v === undefined ? '' : v;
13
+ }
14
+ return values;
15
+ }
16
+ function timeZones(current) {
17
+ const all = typeof Intl.supportedValuesOf === 'function' ? Intl.supportedValuesOf('timeZone') : [];
18
+ return Array.from(new Set(['UTC', current, ...all])).sort();
19
+ }
20
+ /** The value a field would save, normalised like the database stores it. */
21
+ function normalise(f, value) {
22
+ let next = value;
23
+ if (f.kind === 'number' || f.kind === 'select')
24
+ next = Number(value);
25
+ if (typeof next === 'string')
26
+ next = next.trim() === '' ? null : next.trim();
27
+ if (f.kind === 'currency' && typeof next === 'string')
28
+ next = next.toUpperCase();
29
+ return next;
30
+ }
31
+ /**
32
+ * One settings group, rendered from the field schema: each setting as a row
33
+ * (what it is and what it does on the left, the control on the right). Saves
34
+ * only the fields that changed.
35
+ */
36
+ export function SettingsSection({ group, embedded = false }) {
37
+ const { engine, settings, refreshSettings, toast } = useAdmin();
38
+ const [values, setValues] = useState(() => initialValues(group, settings));
39
+ const [error, setError] = useState(null);
40
+ const [busy, setBusy] = useState(false);
41
+ const zones = useMemo(() => timeZones(settings.timezone), [settings.timezone]);
42
+ const device = deviceTimeZone();
43
+ const patch = {};
44
+ for (const f of group.fields) {
45
+ const next = normalise(f, values[f.key]);
46
+ if (next !== settings[f.key])
47
+ patch[f.key] = next;
48
+ }
49
+ const dirty = Object.keys(patch).length > 0;
50
+ async function save(event) {
51
+ event.preventDefault();
52
+ if (!dirty || busy)
53
+ return;
54
+ setBusy(true);
55
+ setError(null);
56
+ const r = await engine.admin.updateSettings(patch);
57
+ setBusy(false);
58
+ if (!r.ok) {
59
+ setError({ text: r.error.message, field: r.error.field });
60
+ return;
61
+ }
62
+ await refreshSettings();
63
+ toast({ title: 'Saved.', detail: 'Changes apply to new bookings immediately.' });
64
+ }
65
+ function row(f) {
66
+ const id = `set-${f.key}`;
67
+ const value = values[f.key];
68
+ const set = (v) => setValues({ ...values, [f.key]: v });
69
+ const helpId = `${id}-help`;
70
+ const fieldError = error?.field === f.key ? error.text : null;
71
+ if (f.kind === 'boolean') {
72
+ return (_jsxs("div", { className: "pbe-setting pbe-setting--switch", children: [_jsxs("div", { className: "pbe-setting-text", children: [_jsx("label", { htmlFor: id, children: f.label }), _jsx("p", { className: "pbe-help", id: helpId, children: f.help })] }), _jsx("input", { id: id, type: "checkbox", role: "switch", className: "pbe-switch", "aria-describedby": helpId, checked: Boolean(value), onChange: (e) => set(e.target.checked) })] }, f.key));
73
+ }
74
+ let control;
75
+ switch (f.kind) {
76
+ case 'select':
77
+ control = (_jsx("select", { id: id, "aria-describedby": helpId, "aria-invalid": fieldError ? true : undefined, value: String(value), onChange: (e) => set(e.target.value), children: (f.options ?? []).map((o) => (_jsx("option", { value: o.value, children: o.label }, o.value))) }));
78
+ break;
79
+ case 'timezone':
80
+ control = (_jsxs(_Fragment, { children: [_jsx("select", { id: id, "aria-describedby": helpId, "aria-invalid": fieldError ? true : undefined, value: String(value), onChange: (e) => set(e.target.value), children: zones.map((z) => (_jsx("option", { value: z, children: z.replace(/_/g, ' ') }, z))) }), device && device !== value ? (_jsxs("button", { type: "button", className: "pbe-link-button", onClick: () => set(device), children: ["Use this device\u2019s zone (", device.replace(/_/g, ' '), ")"] })) : null] }));
81
+ break;
82
+ case 'textarea':
83
+ control = (_jsx("textarea", { id: id, "aria-describedby": helpId, "aria-invalid": fieldError ? true : undefined, rows: 3, maxLength: f.maxLength, value: String(value), onChange: (e) => set(e.target.value) }));
84
+ break;
85
+ default:
86
+ control = (_jsxs(_Fragment, { children: [_jsx("input", { id: id, "aria-describedby": helpId, "aria-invalid": fieldError ? true : undefined, type: f.kind === 'number' ? 'number' : f.kind === 'email' ? 'email' : f.kind === 'tel' ? 'tel' : 'text', min: f.min, max: f.max, maxLength: f.maxLength, placeholder: f.placeholder, list: f.kind === 'currency' ? `${id}-list` : undefined, value: String(value), onChange: (e) => set(e.target.value) }), f.kind === 'currency' ? (_jsx("datalist", { id: `${id}-list`, children: CURRENCY_SUGGESTIONS.map((c) => (_jsx("option", { value: c }, c))) })) : null] }));
87
+ }
88
+ return (_jsxs("div", { className: `pbe-setting${fieldError ? ' pbe-field--error' : ''}`, children: [_jsxs("div", { className: "pbe-setting-text", children: [_jsx("label", { htmlFor: id, children: f.label }), _jsx("p", { className: "pbe-help", id: helpId, children: f.help })] }), _jsxs("div", { className: "pbe-setting-control", children: [control, fieldError ? (_jsxs("p", { className: "pbe-field-error", children: [_jsx(Icon, { name: "error" }), fieldError] })) : null] })] }, f.key));
89
+ }
90
+ const titleId = `pbe-${group.id}-title`;
91
+ const form = (_jsxs("form", { className: "pbe-card pbe-settings", onSubmit: save, "aria-labelledby": titleId, children: [error && !error.field ? (_jsx("div", { className: "pbe-settings-error", children: _jsx(Notice, { kind: "error", children: error.text }) })) : null, group.fields.map(row), _jsxs("div", { className: "pbe-settings-foot", children: [_jsx("span", { className: "pbe-settings-state", "aria-live": "polite", children: dirty ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "pbe-dot pbe-dot--warn", "aria-hidden": "true" }), "Unsaved changes"] })) : ('No unsaved changes') }), _jsx(Button, { type: "submit", variant: "primary", loading: busy, disabled: !dirty, children: "Save" })] })] }));
92
+ if (embedded) {
93
+ return (_jsxs("section", { "aria-labelledby": titleId, className: "pbe-stack", children: [_jsxs("div", { children: [_jsx("h2", { id: titleId, className: "pbe-section-title", children: group.title }), _jsx("p", { className: "pbe-section-sub", children: group.intro })] }), form] }));
94
+ }
95
+ return (_jsxs("section", { "aria-labelledby": titleId, className: "pbe-page", children: [_jsx(PageHeader, { id: titleId, title: group.title, sub: group.intro }), form] }));
96
+ }
@@ -0,0 +1 @@
1
+ export declare function WebsiteSection(): import("react").JSX.Element;
@@ -0,0 +1,228 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ // "Website": the owner edits the content the website declared (its
3
+ // SiteContentSchema), saves a draft, previews it on the real site, publishes.
4
+ import { useEffect, useMemo, useState } from 'react';
5
+ import { allFields } from '../../content/schema.js';
6
+ import { checkFieldValue } from '../../content/validate.js';
7
+ import { ContentInput } from '../content-inputs.js';
8
+ import { useAdmin } from '../context.js';
9
+ import { Badge, Button, EmptyState, ErrorNotice, Notice, PageHeader, SkeletonBlock, useResult } from '../ui.js';
10
+ const same = (a, b) => JSON.stringify(a ?? null) === JSON.stringify(b ?? null);
11
+ function ago(iso) {
12
+ if (!iso)
13
+ return '';
14
+ const minutes = Math.round((Date.now() - Date.parse(iso)) / 60000);
15
+ if (minutes < 1)
16
+ return 'just now';
17
+ if (minutes < 60)
18
+ return `${minutes} min ago`;
19
+ const hours = Math.round(minutes / 60);
20
+ return hours < 48 ? `${hours} h ago` : new Date(iso).toLocaleDateString();
21
+ }
22
+ /** Problems that need the owner (empty image descriptions are checked here, not in the database). */
23
+ function problemsOf(fields, values) {
24
+ const out = {};
25
+ for (const field of fields) {
26
+ if (!(field.id in values))
27
+ continue;
28
+ const checked = checkFieldValue(field, values[field.id]);
29
+ if (!checked.ok) {
30
+ out[field.id] = checked.problem;
31
+ continue;
32
+ }
33
+ const missingAlt = (v) => Boolean(v && typeof v === 'object' && 'path' in v && !String(v.alt ?? '').trim());
34
+ if (field.type === 'image' && missingAlt(values[field.id]))
35
+ out[field.id] = 'Describe the image for people who cannot see it.';
36
+ if (field.type === 'list') {
37
+ const list = values[field.id];
38
+ const imageFields = field.fields.filter((f) => f.type === 'image');
39
+ list.forEach((item, i) => {
40
+ for (const f of imageFields)
41
+ if (missingAlt(item[f.id]))
42
+ out[field.id] = `${field.itemLabel} ${i + 1}: describe the image.`;
43
+ });
44
+ }
45
+ }
46
+ return out;
47
+ }
48
+ /** Every image path a document refers to. */
49
+ function imagePaths(values) {
50
+ const found = [];
51
+ const visit = (v) => {
52
+ if (Array.isArray(v))
53
+ v.forEach(visit);
54
+ else if (v && typeof v === 'object') {
55
+ const o = v;
56
+ if (typeof o.path === 'string')
57
+ found.push(o.path);
58
+ else
59
+ Object.values(o).forEach(visit);
60
+ }
61
+ };
62
+ Object.values(values).forEach(visit);
63
+ return found;
64
+ }
65
+ export function WebsiteSection() {
66
+ const { engine, contentSchema, siteUrl, refreshWebsite, confirm } = useAdmin();
67
+ const [load, reload] = useResult(() => engine.admin.getSiteContent(), [engine]);
68
+ const [saved, setSaved] = useState(null);
69
+ const [values, setValues] = useState({});
70
+ const [sectionId, setSectionId] = useState(contentSchema?.sections[0]?.id ?? '');
71
+ const [busy, setBusy] = useState(null);
72
+ const [message, setMessage] = useState(null);
73
+ useEffect(() => {
74
+ if (load.state === 'ready') {
75
+ setSaved(load.data);
76
+ setValues(load.data.draft);
77
+ }
78
+ }, [load]);
79
+ const fields = useMemo(() => (contentSchema ? allFields(contentSchema) : []), [contentSchema]);
80
+ const dirty = saved ? !same(values, saved.draft) : false;
81
+ const problems = useMemo(() => problemsOf(fields, values), [fields, values]);
82
+ const hasProblems = Object.keys(problems).length > 0;
83
+ useEffect(() => {
84
+ if (!dirty)
85
+ return;
86
+ const warn = (e) => {
87
+ e.preventDefault();
88
+ e.returnValue = '';
89
+ };
90
+ window.addEventListener('beforeunload', warn);
91
+ return () => window.removeEventListener('beforeunload', warn);
92
+ }, [dirty]);
93
+ if (!contentSchema || contentSchema.sections.length === 0) {
94
+ return (_jsxs("section", { "aria-labelledby": "pbe-website-title", className: "pbe-page", children: [_jsx(PageHeader, { id: "pbe-website-title", title: "Website" }), _jsx(EmptyState, { icon: "website", title: "Nothing to edit here yet", variant: "card", children: "This website has no editable content yet. Its developer adds it by declaring a content schema and passing it to the dashboard (INTEGRATION.md, \u201CWebsite content\u201D)." })] }));
95
+ }
96
+ if (load.state === 'error') {
97
+ return (_jsxs("section", { "aria-labelledby": "pbe-website-title", className: "pbe-page", children: [_jsx(PageHeader, { id: "pbe-website-title", title: "Website" }), _jsx(ErrorNotice, { error: load.error, onRetry: reload })] }));
98
+ }
99
+ // The section list comes from the website's schema, so the page is laid out at once;
100
+ // only the fields wait for the saved values.
101
+ const current = load.state === 'ready' ? saved : null;
102
+ const section = contentSchema.sections.find((s) => s.id === sectionId) ?? contentSchema.sections[0];
103
+ const sectionChanged = (id) => current !== null && contentSchema.sections.find((s) => s.id === id).fields.some((f) => !same(values[f.id], current.published[f.id]));
104
+ function setField(id, value) {
105
+ setMessage(null);
106
+ setValues((prev) => ({ ...prev, [id]: value }));
107
+ }
108
+ function resetField(id) {
109
+ setMessage(null);
110
+ setValues((prev) => {
111
+ const next = { ...prev };
112
+ delete next[id];
113
+ return next;
114
+ });
115
+ }
116
+ /** The value an input shows: the owner's, or the website's default (images: none stored). */
117
+ function shown(field) {
118
+ if (field.id in values)
119
+ return values[field.id];
120
+ if (field.type === 'image')
121
+ return null;
122
+ if (field.type === 'list')
123
+ return field.default.map((item) => ({ ...item }));
124
+ return field.default;
125
+ }
126
+ async function save() {
127
+ if (hasProblems) {
128
+ setMessage({ kind: 'error', text: 'Fix the highlighted fields first.' });
129
+ return null;
130
+ }
131
+ if (!current)
132
+ return null;
133
+ const r = await engine.admin.saveSiteContentDraft(values, current.draftRevision);
134
+ if (!r.ok) {
135
+ setMessage({
136
+ kind: 'error',
137
+ text: r.error.code === 'CONFLICT'
138
+ ? 'Someone else saved changes in the meantime. Copy what you need, then reload to see their version.'
139
+ : r.error.message,
140
+ });
141
+ return null;
142
+ }
143
+ setSaved(r.data);
144
+ setValues(r.data.draft);
145
+ refreshWebsite();
146
+ return r.data;
147
+ }
148
+ async function onSave() {
149
+ setBusy('save');
150
+ const r = await save();
151
+ setBusy(null);
152
+ if (r)
153
+ setMessage({ kind: 'success', text: 'Draft saved. Visitors still see the published version until you publish.' });
154
+ }
155
+ async function onPreview() {
156
+ setBusy('preview');
157
+ const r = dirty ? await save() : current;
158
+ setBusy(null);
159
+ if (!r)
160
+ return;
161
+ const url = new URL(siteUrl, window.location.href);
162
+ url.searchParams.set('preview', 'draft');
163
+ window.open(url.href, '_blank', 'noopener');
164
+ }
165
+ async function onPublish() {
166
+ setBusy('publish');
167
+ const base = dirty ? await save() : current;
168
+ if (!base) {
169
+ setBusy(null);
170
+ return;
171
+ }
172
+ const r = await engine.admin.publishSiteContent(base.draftRevision);
173
+ setBusy(null);
174
+ if (!r.ok) {
175
+ setMessage({ kind: 'error', text: r.error.code === 'CONFLICT' ? 'Someone else saved changes just now. Reload and check before publishing.' : r.error.message });
176
+ return;
177
+ }
178
+ setSaved(r.data);
179
+ setValues(r.data.draft);
180
+ refreshWebsite();
181
+ setMessage({ kind: 'success', text: 'Published. Visitors see the new version on their next visit or refresh.' });
182
+ // Tidy up images nothing refers to any more (older than a day, so nothing an editor still holds).
183
+ const keep = new Set([...imagePaths(r.data.draft), ...imagePaths(r.data.published)]);
184
+ const all = await engine.admin.listSiteImages();
185
+ if (all.ok) {
186
+ const stale = all.data.filter((f) => !keep.has(f.path) && f.createdAt && Date.now() - Date.parse(f.createdAt) > 24 * 3600_000);
187
+ if (stale.length)
188
+ void engine.admin.deleteSiteImages(stale.map((f) => f.path));
189
+ }
190
+ }
191
+ async function onDiscard() {
192
+ const ok = await confirm({
193
+ title: 'Discard your unpublished changes?',
194
+ body: 'The editor goes back to what visitors see now. Saved drafts and unsaved edits are both thrown away.',
195
+ confirmLabel: 'Discard changes',
196
+ cancelLabel: 'Keep editing',
197
+ });
198
+ if (!ok)
199
+ return;
200
+ setBusy('discard');
201
+ const r = await engine.admin.discardSiteContentDraft();
202
+ setBusy(null);
203
+ if (!r.ok) {
204
+ setMessage({ kind: 'error', text: r.error.message });
205
+ return;
206
+ }
207
+ setSaved(r.data);
208
+ setValues(r.data.draft);
209
+ refreshWebsite();
210
+ setMessage({ kind: 'info', text: 'Back to the published version.' });
211
+ }
212
+ // Sections holding a field that blocks saving: named in the bar, marked in the tabs.
213
+ const problemSections = contentSchema.sections.filter((s) => s.fields.some((f) => f.id in problems));
214
+ const problemCount = Object.keys(problems).length;
215
+ const status = hasProblems
216
+ ? `${problemCount === 1 ? '1 field needs' : `${problemCount} fields need`} fixing before you can save — ${problemSections.map((s) => s.label).join(', ')}`
217
+ : dirty
218
+ ? 'Unsaved changes'
219
+ : !current
220
+ ? 'Loading…'
221
+ : current.hasUnpublishedChanges
222
+ ? `Draft saved ${ago(current.draftUpdatedAt)} · not published yet`
223
+ : current.version > 0
224
+ ? `Published ${ago(current.publishedAt)} · everything is live`
225
+ : 'Not published yet — the website shows its built-in text';
226
+ const live = (current?.version ?? 0) > 0;
227
+ return (_jsxs("section", { "aria-labelledby": "pbe-website-title", className: "pbe-page", children: [_jsx(PageHeader, { id: "pbe-website-title", title: "Website", sub: "The text, images and brand of your website. Changes stay private until you publish; preview them on the real site first.", actions: _jsx(_Fragment, { children: !current ? null : live ? _jsx(Badge, { tone: current.hasUnpublishedChanges ? 'warn' : 'ok', children: `Version ${current.version}${current.hasUnpublishedChanges ? ' · draft changes' : ' · live'}` }) : _jsx(Badge, { children: "Never published" }) }) }), _jsxs("div", { className: "pbe-content-layout", children: [_jsxs("div", { className: "pbe-content-picker", children: [_jsx("label", { htmlFor: "pbe-content-section", className: "pbe-label", children: "Section" }), _jsx("select", { id: "pbe-content-section", value: section.id, onChange: (e) => setSectionId(e.target.value), children: contentSchema.sections.map((s) => (_jsxs("option", { value: s.id, children: [s.label, problemSections.includes(s) ? ' — needs fixing' : sectionChanged(s.id) ? ' — changed' : ''] }, s.id))) })] }), _jsx("nav", { className: "pbe-content-nav", "aria-label": "Website sections", children: contentSchema.sections.map((s) => (_jsxs("button", { type: "button", "aria-current": s.id === section.id ? 'true' : undefined, onClick: () => setSectionId(s.id), children: [s.label, problemSections.includes(s) ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "pbe-dot pbe-dot--error", "aria-hidden": "true" }), _jsx("span", { className: "pbe-sr-only", children: " (needs fixing)" })] })) : sectionChanged(s.id) ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "pbe-dot", "aria-hidden": "true" }), _jsx("span", { className: "pbe-sr-only", children: " (changed, not published)" })] })) : null] }, s.id))) }), _jsxs("div", { className: "pbe-card pbe-content-card", role: "region", "aria-labelledby": "pbe-website-section-title", children: [_jsxs("div", { className: "pbe-content-card-head", children: [_jsx("h2", { id: "pbe-website-section-title", className: "pbe-card-title", children: section.label }), section.description ? _jsx("p", { className: "pbe-help", children: section.description }) : null] }), !current ? _jsx(SkeletonBlock, { lines: 6, label: "Loading your website content\u2026" }) : null, (current ? section.fields : []).map((field) => (_jsx(ContentInput, { field: field, value: shown(field), onChange: (v) => setField(field.id, v), onReset: () => resetField(field.id), isDefault: !(field.id in values), problem: problems[field.id], engine: engine }, field.id)))] })] }), current ? (_jsxs("div", { className: "pbe-content-bar", role: "region", "aria-label": "Save and publish", children: [message ? _jsx(Notice, { kind: message.kind, children: message.text }) : null, _jsxs("div", { className: "pbe-content-bar-row", children: [_jsxs("span", { className: hasProblems ? 'pbe-status-pill pbe-status-pill--error' : 'pbe-status-pill', "aria-live": "polite", children: [hasProblems ? (_jsx("span", { className: "pbe-dot pbe-dot--error", "aria-hidden": "true" })) : dirty || current.hasUnpublishedChanges ? (_jsx("span", { className: "pbe-dot", "aria-hidden": "true" })) : live ? (_jsx("span", { className: "pbe-dot pbe-dot--ok", "aria-hidden": "true" })) : null, _jsxs("span", { children: [status, hasProblems && problemSections[0] && problemSections[0].id !== section.id ? (_jsxs(_Fragment, { children: [' ', _jsx("button", { type: "button", className: "pbe-link-button", onClick: () => setSectionId(problemSections[0].id), children: "Show" })] })) : null] })] }), current.hasUnpublishedChanges || dirty ? (_jsx(Button, { variant: "danger-quiet", loading: busy === 'discard', disabled: busy !== null && busy !== 'discard', onClick: () => void onDiscard(), children: "Discard changes" })) : null, _jsx(Button, { loading: busy === 'save', disabled: (busy !== null && busy !== 'save') || !dirty, onClick: () => void onSave(), children: "Save draft" }), _jsx(Button, { icon: "preview", loading: busy === 'preview', disabled: (busy !== null && busy !== 'preview') || hasProblems, onClick: () => void onPreview(), children: "Preview" }), _jsx(Button, { variant: "primary", icon: "send", loading: busy === 'publish', disabled: (busy !== null && busy !== 'publish') || hasProblems || (!dirty && !current.hasUnpublishedChanges), onClick: () => void onPublish(), children: "Publish" })] })] })) : null] }));
228
+ }
@@ -0,0 +1,22 @@
1
+ import type { ComponentType } from 'react';
2
+ import type { IconName } from './icons.js';
3
+ export interface AdminSection {
4
+ id: string;
5
+ label: string;
6
+ icon: IconName;
7
+ /** Shown in the phone tab bar; the others are under "More". */
8
+ primary?: boolean;
9
+ /** Navigation group: the day's work, the website, or setup. */
10
+ group?: 'run' | 'online' | 'setup';
11
+ component: ComponentType;
12
+ }
13
+ /**
14
+ * Dashboard sections, in navigation order. "Today" is the landing page.
15
+ * "Website" edits the content the website declared (its SiteContentSchema,
16
+ * passed to <BookingAdmin content>).
17
+ */
18
+ export declare const ADMIN_SECTIONS: AdminSection[];
19
+ export declare const NAV_GROUPS: Array<{
20
+ id: NonNullable<AdminSection['group']>;
21
+ label: string | null;
22
+ }>;