@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.
- package/CHANGELOG.md +562 -0
- package/LICENSE +21 -0
- package/README.md +18 -2
- package/THIRD_PARTY_NOTICES.md +41 -0
- package/bin/booking-engine.mjs +575 -0
- package/bin/connect.mjs +408 -0
- package/bin/photos.mjs +82 -0
- package/dist/admin/BookingAdmin.d.ts +22 -0
- package/dist/admin/BookingAdmin.js +337 -0
- package/dist/admin/admin.css +1423 -0
- package/dist/admin/alerts.d.ts +10 -0
- package/dist/admin/alerts.js +11 -0
- package/dist/admin/booking-detail.d.ts +37 -0
- package/dist/admin/booking-detail.js +149 -0
- package/dist/admin/content-inputs.d.ts +15 -0
- package/dist/admin/content-inputs.js +105 -0
- package/dist/admin/context.d.ts +37 -0
- package/dist/admin/context.js +8 -0
- package/dist/admin/drawer.d.ts +14 -0
- package/dist/admin/drawer.js +56 -0
- package/dist/admin/feedback.d.ts +32 -0
- package/dist/admin/feedback.js +70 -0
- package/dist/admin/fields.d.ts +27 -0
- package/dist/admin/fields.js +146 -0
- package/dist/admin/fonts/OFL-Geist-Mono.txt +93 -0
- package/dist/admin/fonts/OFL-Geist.txt +93 -0
- package/dist/admin/fonts/geist-latin-wght-normal.woff2 +0 -0
- package/dist/admin/fonts/geist-mono-latin-wght-normal.woff2 +0 -0
- package/dist/admin/icons.d.ts +66 -0
- package/dist/admin/icons.js +72 -0
- package/dist/admin/image-upload.d.ts +58 -0
- package/dist/admin/image-upload.js +111 -0
- package/dist/admin/index.d.ts +6 -0
- package/dist/admin/index.js +6 -0
- package/dist/admin/lucide.generated.d.ts +521 -0
- package/dist/admin/lucide.generated.js +76 -0
- package/dist/admin/sections/BookingsSection.d.ts +1 -0
- package/dist/admin/sections/BookingsSection.js +137 -0
- package/dist/admin/sections/EmailSection.d.ts +8 -0
- package/dist/admin/sections/EmailSection.js +182 -0
- package/dist/admin/sections/HoursSection.d.ts +1 -0
- package/dist/admin/sections/HoursSection.js +110 -0
- package/dist/admin/sections/OverviewSection.d.ts +1 -0
- package/dist/admin/sections/OverviewSection.js +427 -0
- package/dist/admin/sections/ServicesSection.d.ts +1 -0
- package/dist/admin/sections/ServicesSection.js +236 -0
- package/dist/admin/sections/SettingsSection.d.ts +10 -0
- package/dist/admin/sections/SettingsSection.js +96 -0
- package/dist/admin/sections/WebsiteSection.d.ts +1 -0
- package/dist/admin/sections/WebsiteSection.js +228 -0
- package/dist/admin/sections.d.ts +22 -0
- package/dist/admin/sections.js +29 -0
- package/dist/admin/setup.d.ts +1 -0
- package/dist/admin/setup.js +45 -0
- package/dist/admin/today.d.ts +43 -0
- package/dist/admin/today.js +115 -0
- package/dist/admin/ui.d.ts +134 -0
- package/dist/admin/ui.js +220 -0
- package/dist/calendar.d.ts +64 -0
- package/dist/calendar.js +139 -0
- package/dist/client.d.ts +147 -0
- package/dist/client.js +507 -0
- package/dist/config.d.ts +25 -0
- package/dist/config.js +120 -0
- package/dist/content/image.d.ts +20 -0
- package/dist/content/image.js +90 -0
- package/dist/content/resolve.d.ts +12 -0
- package/dist/content/resolve.js +73 -0
- package/dist/content/schema.d.ts +119 -0
- package/dist/content/schema.js +53 -0
- package/dist/content/store.d.ts +48 -0
- package/dist/content/store.js +123 -0
- package/dist/content/validate.d.ts +33 -0
- package/dist/content/validate.js +177 -0
- package/dist/errors.d.ts +19 -0
- package/dist/errors.js +94 -0
- package/dist/generated/manifest.d.ts +6 -0
- package/dist/generated/manifest.js +7 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +20 -0
- package/dist/presets/hair-salon.d.ts +8 -0
- package/dist/presets/hair-salon.js +94 -0
- package/dist/presets/index.d.ts +5 -0
- package/dist/presets/index.js +6 -0
- package/dist/preview.d.ts +18 -0
- package/dist/preview.js +134 -0
- package/dist/semver.d.ts +16 -0
- package/dist/semver.js +55 -0
- package/dist/time.d.ts +31 -0
- package/dist/time.js +138 -0
- package/dist/types.d.ts +477 -0
- package/dist/types.js +3 -0
- package/dist/vite.d.ts +52 -0
- package/dist/vite.js +150 -0
- package/docs/BUILD-A-SITE.md +203 -0
- package/docs/EMAIL-SETUP.md +224 -0
- package/docs/INTEGRATION.md +1109 -0
- package/engine.manifest.json +90 -0
- package/functions/booking-mailer/deno.json +6 -0
- package/functions/booking-mailer/index.ts +44 -0
- package/functions/booking-mailer/mailer.js +156 -0
- package/functions/booking-mailer/providers/index.js +42 -0
- package/functions/booking-mailer/providers/resend.js +75 -0
- package/functions/booking-mailer/templates.js +345 -0
- package/migrations/0001_core.sql +1673 -0
- package/migrations/0002_security_hardening.sql +711 -0
- package/migrations/0003_private_definers_and_holds.sql +808 -0
- package/migrations/0004_verified_requests.sql +1702 -0
- package/migrations/0005_scoped_mailer_credential.sql +347 -0
- package/migrations/0006_trusted_client_ip.sql +56 -0
- package/migrations/0007_site_content.sql +380 -0
- package/migrations/0008_service_images_opening_times.sql +328 -0
- package/package.json +85 -4
- package/templates/BOOKING_ENGINE.md +61 -0
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
// "Today": the landing page. The requests waiting for an answer come first;
|
|
3
|
+
// then the day in numbers, the day's schedule, who is in now and next, the
|
|
4
|
+
// closures ahead and whether everything is working. Every number comes from
|
|
5
|
+
// the engine and links to where it is handled.
|
|
6
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
7
|
+
import { addDays, formatClockTime, formatDate, formatDateTime, formatMoney, formatTime, localTimeLabel, timeZoneLabel, todayInTimeZone } from '../../time.js';
|
|
8
|
+
import { ALERTS_VIEW, alertsAddress } from '../alerts.js';
|
|
9
|
+
import { BookingDrawer, actionsFor, dayWord, priceText, useBookingActions } from '../booking-detail.js';
|
|
10
|
+
import { useAdmin } from '../context.js';
|
|
11
|
+
import { Icon } from '../icons.js';
|
|
12
|
+
import { SetupChecklist } from '../setup.js';
|
|
13
|
+
import { OCCUPYING, bookingSpan, byUrgency, closuresOn, freeSpans, holdRunning, holdState, openSpans, overlapMinutes, toMinutes, total, weekStart, } from '../today.js';
|
|
14
|
+
import { Button, ErrorNotice, Meter, Notice, Ring, STATUS_LABELS, StatusBadge, firstName, formatAgo, formatMinutes, formatSpan, useMediaQuery, useNow, useResult } from '../ui.js';
|
|
15
|
+
export function OverviewSection() {
|
|
16
|
+
const { engine, settings } = useAdmin();
|
|
17
|
+
const tz = settings.timezone;
|
|
18
|
+
const locale = settings.locale;
|
|
19
|
+
const now = useNow(20_000);
|
|
20
|
+
const today = todayInTimeZone(tz, new Date(now));
|
|
21
|
+
const [range, reloadRange] = useResult(() => engine.admin.listBookings({ from: addDays(today, -13), to: addDays(today, 30), statuses: ['pending', 'expired', 'confirmed', 'completed', 'no_show'] }), [today]);
|
|
22
|
+
const [requests, reloadRequests] = useResult(() => engine.admin.listBookings({ from: today, to: addDays(today, 365), statuses: ['pending', 'expired'] }), [today]);
|
|
23
|
+
const [services] = useResult(() => engine.admin.listServices(), []);
|
|
24
|
+
const [hours] = useResult(() => engine.admin.getWorkingHours(), []);
|
|
25
|
+
const [closures] = useResult(() => engine.admin.listExceptions(), []);
|
|
26
|
+
const [email] = useResult(() => engine.admin.emailStatus(), []);
|
|
27
|
+
const [open, setOpen] = useState(null);
|
|
28
|
+
const reload = () => {
|
|
29
|
+
reloadRange();
|
|
30
|
+
reloadRequests();
|
|
31
|
+
};
|
|
32
|
+
const svc = services.state === 'ready' ? services.data : null;
|
|
33
|
+
const all = range.state === 'ready' ? range.data : null;
|
|
34
|
+
const week = hours.state === 'ready' ? hours.data : null;
|
|
35
|
+
const off = closures.state === 'ready' ? closures.data : null;
|
|
36
|
+
const reqs = requests.state === 'ready' ? [...requests.data].sort(byUrgency(now)) : null;
|
|
37
|
+
const mailer = email.state === 'ready' ? email.data : null;
|
|
38
|
+
const nowLabel = formatTime(new Date(now).toISOString(), tz, locale);
|
|
39
|
+
return (_jsxs("section", { "aria-label": "Today", className: "pbe-page", children: [_jsxs("header", { className: "pbe-page-head", children: [_jsxs("div", { children: [_jsxs("h1", { id: "pbe-overview-title", className: "pbe-page-title", children: [_jsx("span", { className: "pbe-phone-only", children: "Today" }), _jsx("span", { className: "pbe-desktop-only", children: formatDate(today, locale) })] }), _jsxs("p", { className: "pbe-page-sub pbe-phone-only", children: [formatDate(today, locale), " \u00B7 ", nowLabel, " ", timeZoneLabel(tz, locale)] })] }), _jsx(Health, { email: mailer })] }), requests.state === 'error' ? _jsx(ErrorNotice, { error: requests.error, onRetry: reload }) : null, reqs ? _jsx(Requests, { requests: reqs, services: svc, now: now, onOpen: setOpen, onAnswered: reload }) : null, _jsx(SetupChecklist, {}), range.state === 'error' ? _jsx(ErrorNotice, { error: range.error, onRetry: reload }) : null, all && week && off ? (_jsx(Kpis, { all: all, services: svc, week: week, closures: off, today: today })) : range.state !== 'error' ? (_jsx("div", { className: "pbe-kpis", "aria-hidden": "true", children: [0, 1, 2, 3].map((i) => (_jsxs("div", { className: "pbe-card pbe-sk-card", children: [_jsx("span", { className: "pbe-sk", style: { width: '42%' } }), _jsx("span", { className: "pbe-sk pbe-sk--value" }), _jsx("span", { className: "pbe-sk", style: { width: '70%' } })] }, i))) })) : null, all && week && off ? (_jsx(Schedule, { all: all, week: week, closures: off, today: today, now: now, onOpen: setOpen })) : range.state !== 'error' ? (_jsxs("div", { className: "pbe-card pbe-card--pad", children: [_jsx("span", { className: "pbe-sr-only", role: "status", children: "Loading today\u2019s schedule\u2026" }), _jsxs("div", { className: "pbe-skeleton", "aria-hidden": "true", children: [_jsx("span", { className: "pbe-sk pbe-sk--title" }), _jsx("span", { className: "pbe-sk", style: { height: 64, borderRadius: 10 } })] })] })) : null, _jsxs("div", { className: "pbe-split", children: [_jsx(NowNext, { all: all, services: svc, now: now, onOpen: setOpen }), _jsx(ClosuresAhead, { closures: off, today: today })] }), _jsx(HealthCard, { email: mailer }), open ? (_jsx(BookingDrawer, { booking: open, services: svc, onClose: () => setOpen(null), onChanged: (b) => {
|
|
40
|
+
setOpen(b);
|
|
41
|
+
reload();
|
|
42
|
+
} })) : null] }));
|
|
43
|
+
}
|
|
44
|
+
// ------------------------------------------------------------ requests ---
|
|
45
|
+
/** How many requests the panel shows before "Show all": a glance, not the whole list. */
|
|
46
|
+
const FIRST_REQUESTS = { wide: 3, phone: 2 };
|
|
47
|
+
/**
|
|
48
|
+
* The requests waiting for an answer, most urgent first: the count, the
|
|
49
|
+
* first few as compact rows (countdown, who, what, when, Decline / Confirm),
|
|
50
|
+
* the rest one "Show all" away, and every detail one click or tap away (the
|
|
51
|
+
* booking drawer). When nothing waits, the same place says so, calmly.
|
|
52
|
+
*/
|
|
53
|
+
function Requests({ requests, services, now, onOpen, onAnswered, }) {
|
|
54
|
+
const { settings, go } = useAdmin();
|
|
55
|
+
const run = useBookingActions();
|
|
56
|
+
const phone = useMediaQuery('(max-width: 899px)');
|
|
57
|
+
const [expanded, setExpanded] = useState(false);
|
|
58
|
+
const [busy, setBusy] = useState(null);
|
|
59
|
+
const [errors, setErrors] = useState({});
|
|
60
|
+
const panel = useRef(null);
|
|
61
|
+
const refocus = useRef(null);
|
|
62
|
+
const tz = settings.timezone;
|
|
63
|
+
const locale = settings.locale;
|
|
64
|
+
const n = requests.length;
|
|
65
|
+
const limit = phone ? FIRST_REQUESTS.phone : FIRST_REQUESTS.wide;
|
|
66
|
+
const shown = expanded ? requests : requests.slice(0, limit);
|
|
67
|
+
const running = requests.filter((r) => holdRunning(r, now));
|
|
68
|
+
const ended = n - running.length;
|
|
69
|
+
const soonest = running[0] ?? null;
|
|
70
|
+
// An answered request leaves the list (once the reloaded list arrives):
|
|
71
|
+
// focus goes to the one that took its place, or to the panel's title,
|
|
72
|
+
// unless the owner has already moved on.
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
const answered = refocus.current;
|
|
75
|
+
if (!answered || requests.some((r) => r.id === answered.id))
|
|
76
|
+
return;
|
|
77
|
+
refocus.current = null;
|
|
78
|
+
const active = document.activeElement;
|
|
79
|
+
if (active && active !== document.body && document.contains(active))
|
|
80
|
+
return;
|
|
81
|
+
const names = panel.current?.querySelectorAll('.pbe-request-name');
|
|
82
|
+
const next = names?.length ? names[Math.min(answered.index, names.length - 1)] : document.getElementById('pbe-urgent-title');
|
|
83
|
+
next?.focus({ preventScroll: true });
|
|
84
|
+
}, [requests]);
|
|
85
|
+
async function act(b, a, index) {
|
|
86
|
+
setErrors((e) => ({ ...e, [b.id]: '' }));
|
|
87
|
+
const r = await run(b, a, () => setBusy({ id: b.id, status: a.status }));
|
|
88
|
+
setBusy(null);
|
|
89
|
+
if (r.error)
|
|
90
|
+
setErrors((e) => ({ ...e, [b.id]: r.error }));
|
|
91
|
+
if (r.booking) {
|
|
92
|
+
refocus.current = { id: b.id, index };
|
|
93
|
+
onAnswered();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const until = (iso) => {
|
|
97
|
+
const sameDay = todayInTimeZone(tz, new Date(Date.parse(iso))) === todayInTimeZone(tz, new Date(now));
|
|
98
|
+
return formatDateTime(iso, tz, locale, sameDay ? { hour: 'numeric', minute: '2-digit' } : { weekday: 'short', hour: 'numeric', minute: '2-digit' });
|
|
99
|
+
};
|
|
100
|
+
if (!n) {
|
|
101
|
+
return (_jsxs("section", { ref: panel, className: "pbe-urgent pbe-urgent--calm", "aria-labelledby": "pbe-urgent-title", children: [_jsx("span", { className: "pbe-calm-icon", "aria-hidden": "true", children: _jsx(Icon, { name: "check", size: 18 }) }), _jsxs("div", { className: "pbe-calm-text", children: [_jsx("h2", { id: "pbe-urgent-title", className: "pbe-calm-title", tabIndex: -1, children: "No requests waiting" }), _jsx("p", { className: "pbe-calm-sub", children: "New requests from your website appear here, with their time held until you answer." })] }), _jsx(Button, { size: "sm", variant: "quiet", iconAfter: "arrow", onClick: () => go('bookings'), children: "Open Bookings" })] }));
|
|
102
|
+
}
|
|
103
|
+
return (_jsxs("section", { ref: panel, className: "pbe-urgent", "aria-labelledby": "pbe-urgent-title", children: [_jsxs("div", { className: "pbe-urgent-head", children: [_jsx("span", { className: "pbe-urgent-number", "aria-hidden": "true", children: n }), _jsxs("div", { className: "pbe-urgent-text", children: [_jsxs("h2", { id: "pbe-urgent-title", className: "pbe-urgent-title", tabIndex: -1, children: [_jsxs("span", { className: "pbe-sr-only", children: [n, " "] }), n === 1 ? 'request needs your answer' : 'requests need your answer'] }), _jsx("p", { className: "pbe-urgent-sub", children: soonest ? (_jsxs(_Fragment, { children: ["Times stay held until you answer or the hold ends. Next to expire: ", _jsx("b", { children: firstName(soonest.customer.name) }), ", at", ' ', _jsx("b", { children: until(soonest.holdExpiresAt) }), ".", ended ? (_jsxs(_Fragment, { children: [' ', _jsxs("span", { className: "pbe-urgent-ended", children: [ended === 1 ? '1 hold has ended' : `${ended} holds have ended`, ": confirm ", ended === 1 ? 'it' : 'them', " if the time is still free."] })] })) : null] })) : n === 1 ? ('Its hold has ended, so the time is open to others again. Confirm it if the time is still free.') : ('Their holds have ended, so the times are open to others again. Confirm the ones that are still free.') })] }), _jsx(Button, { size: "sm", className: "pbe-urgent-link", iconAfter: "arrow", onClick: () => go('bookings', 'pending'), children: "Open in Bookings" })] }), _jsxs("div", { className: "pbe-requests", children: [_jsx("ul", { className: "pbe-requests-list", id: "pbe-requests-list", "aria-labelledby": "pbe-urgent-title", children: shown.map((b, index) => {
|
|
104
|
+
const hold = holdState(b, settings.pendingHoldMinutes, now);
|
|
105
|
+
const isEnded = !holdRunning(b, now);
|
|
106
|
+
const actions = actionsFor(b, now);
|
|
107
|
+
const decline = actions.find((a) => a.status === 'cancelled');
|
|
108
|
+
const confirm = actions.find((a) => a.status === 'confirmed');
|
|
109
|
+
const error = errors[b.id];
|
|
110
|
+
return (_jsxs("li", { className: `pbe-request${hold?.soon ? ' pbe-request--soon' : ''}${isEnded ? ' pbe-request--ended' : ''}${error ? ' pbe-request--error' : ''}`, children: [_jsx(Ring, { size: 24, fraction: hold?.fraction ?? 0, tone: isEnded ? 'ended' : hold?.soon ? 'soon' : 'pending' }), _jsxs("span", { className: "pbe-request-hold", children: [_jsx("span", { className: "pbe-request-left", children: isEnded ? 'Hold ended' : `${formatSpan(hold.left)} left` }), _jsx("span", { className: "pbe-request-until", children: isEnded
|
|
111
|
+
? b.holdExpiresAt
|
|
112
|
+
? `${formatSpan(now - Date.parse(b.holdExpiresAt))} ago · confirm if free`
|
|
113
|
+
: 'confirm if free'
|
|
114
|
+
: `until ${until(b.holdExpiresAt)}` })] }), _jsx("button", { type: "button", className: "pbe-request-name", onClick: () => onOpen(b), children: b.customer.name }), _jsxs("span", { className: "pbe-request-meta", children: [_jsxs("span", { className: "pbe-request-svc", children: [b.serviceName, " \u00B7 ", priceText(b, services, locale)] }), _jsxs("span", { className: "pbe-request-when", children: [dayWord(b.date, tz, locale), " \u00B7 ", formatClockTime(b.time, locale)] })] }), _jsxs("span", { className: "pbe-request-actions", children: [_jsx(Button, { size: "sm", "aria-label": `Decline ${b.customer.name}`, loading: busy?.id === b.id && busy.status === 'cancelled', disabled: busy !== null && busy.id !== b.id, onClick: () => void act(b, decline, index), children: "Decline" }), _jsx(Button, { size: "sm", variant: "primary", icon: "check", "aria-label": `Confirm ${b.customer.name}`, loading: busy?.id === b.id && busy.status === 'confirmed', disabled: busy !== null && busy.id !== b.id, onClick: () => void act(b, confirm, index), children: "Confirm" })] }), error ? (_jsx("div", { className: "pbe-request-error", children: _jsx(Notice, { kind: "error", children: error }) })) : null] }, b.id));
|
|
115
|
+
}) }), n > limit ? (_jsxs("button", { type: "button", className: "pbe-requests-more", "aria-expanded": expanded, "aria-controls": "pbe-requests-list", onClick: () => setExpanded((x) => !x), children: [expanded ? 'Show fewer' : `Show all ${n}`, _jsx(Icon, { name: expanded ? 'up' : 'down' })] })) : null] })] }));
|
|
116
|
+
}
|
|
117
|
+
// ---------------------------------------------------------------- KPIs ---
|
|
118
|
+
function Bars({ days, wide, caption }) {
|
|
119
|
+
// No bookings in the window: no chart (an empty baseline says nothing).
|
|
120
|
+
if (!days.some((d) => d.n > 0))
|
|
121
|
+
return null;
|
|
122
|
+
const max = Math.max(1, ...days.map((d) => d.n));
|
|
123
|
+
return (_jsxs("span", { className: "pbe-kpi-viz", children: [_jsx("span", { className: `pbe-bars${wide ? ' pbe-bars--wide' : ''}`, "aria-hidden": "true", children: days.map((d, i) => (_jsx("span", { className: d.closed && !d.n ? 'pbe-bar--closed' : d.now ? 'pbe-bar--now' : undefined, style: { height: d.closed && !d.n ? undefined : `${Math.max(2, Math.round((d.n / max) * 36))}px` } }, i))) }), _jsx("span", { className: "pbe-bars-caption", "aria-hidden": "true", children: caption })] }));
|
|
124
|
+
}
|
|
125
|
+
function Kpis({ all, services, week, closures, today, }) {
|
|
126
|
+
const { settings, go } = useAdmin();
|
|
127
|
+
const locale = settings.locale;
|
|
128
|
+
const occupying = all.filter((b) => OCCUPYING.has(b.status));
|
|
129
|
+
const on = (date) => occupying.filter((b) => b.date === date);
|
|
130
|
+
const closedOn = (date) => openSpans(date, week, closures).length === 0;
|
|
131
|
+
const short = (date) => formatDate(date, locale, { weekday: 'short' });
|
|
132
|
+
// Today
|
|
133
|
+
const todays = on(today);
|
|
134
|
+
const requested = todays.filter((b) => b.status === 'pending').length;
|
|
135
|
+
const lastWeek = on(addDays(today, -7)).filter((b) => b.status !== 'pending').length;
|
|
136
|
+
const past = Array.from({ length: 14 }, (_, i) => addDays(today, i - 13)).map((d) => ({ n: on(d).length, closed: closedOn(d), now: d === today }));
|
|
137
|
+
// Next 7 days (tomorrow onwards)
|
|
138
|
+
const ahead = Array.from({ length: 7 }, (_, i) => addDays(today, i + 1)).map((d) => ({ date: d, n: on(d).length, closed: closedOn(d) }));
|
|
139
|
+
const aheadTotal = ahead.reduce((s, d) => s + d.n, 0);
|
|
140
|
+
const busiest = ahead.reduce((best, d) => (d.n > (best?.n ?? 0) ? d : best), null);
|
|
141
|
+
const closedDays = ahead.filter((d) => d.closed).length;
|
|
142
|
+
// Booked time today: booked minutes against open minutes (weekly hours minus closures).
|
|
143
|
+
const openToday = openSpans(today, week, closures);
|
|
144
|
+
const openMinutes = total(openToday);
|
|
145
|
+
const bookedMinutes = overlapMinutes(todays.map(bookingSpan), openToday);
|
|
146
|
+
const share = openMinutes ? bookedMinutes / openMinutes : 0;
|
|
147
|
+
// Booked value this week (Monday to Sunday): confirmed and done appointments, at their listed prices.
|
|
148
|
+
const monday = weekStart(today);
|
|
149
|
+
const sunday = addDays(monday, 6);
|
|
150
|
+
const inWeek = all.filter((b) => b.date >= monday && b.date <= sunday);
|
|
151
|
+
const booked = inWeek.filter((b) => b.status === 'confirmed' || b.status === 'completed');
|
|
152
|
+
const value = booked.reduce((s, b) => s + (b.priceCents ?? 0), 0);
|
|
153
|
+
const hasFrom = booked.some((b) => services?.find((s) => s.id === b.serviceId)?.priceFrom);
|
|
154
|
+
const onRequest = booked.filter((b) => b.priceCents === null).length;
|
|
155
|
+
const waitingValue = inWeek.filter((b) => b.status === 'pending').reduce((s, b) => s + (b.priceCents ?? 0), 0);
|
|
156
|
+
const money = (cents) => formatMoney(cents, settings.currency, locale);
|
|
157
|
+
const weekLabel = `${formatDate(monday, locale, { weekday: 'short', month: 'short', day: 'numeric' })} – ${formatDate(sunday, locale, { weekday: 'short', month: 'short', day: 'numeric' })}`;
|
|
158
|
+
return (_jsxs("div", { className: "pbe-kpis", children: [_jsxs("button", { type: "button", className: "pbe-kpi", onClick: () => go('bookings'), children: [_jsxs("span", { className: "pbe-kpi-label", children: ["Today", _jsx("span", { className: "pbe-arrow", children: _jsx(Icon, { name: "external" }) })] }), _jsxs("span", { className: "pbe-kpi-row", children: [_jsxs("span", { className: "pbe-kpi-value", children: [todays.length, _jsx("small", { children: todays.length === 1 ? 'appointment' : 'appointments' })] }), _jsx(Bars, { days: past, caption: "Last 14 days" })] }), _jsxs("span", { className: "pbe-kpi-sub", children: [_jsxs("b", { children: [todays.length - requested, " confirmed"] }), requested ? ` · ${requested} ${requested === 1 ? 'request' : 'requests'}` : '', " \u00B7 ", lastWeek, " last ", short(addDays(today, -7))] })] }), _jsxs("button", { type: "button", className: "pbe-kpi", onClick: () => go('bookings'), children: [_jsxs("span", { className: "pbe-kpi-label", children: ["Next 7 days", _jsx("span", { className: "pbe-arrow", children: _jsx(Icon, { name: "external" }) })] }), _jsxs("span", { className: "pbe-kpi-row", children: [_jsxs("span", { className: "pbe-kpi-value", children: [aheadTotal, _jsx("small", { children: aheadTotal === 1 ? 'appointment' : 'appointments' })] }), _jsx(Bars, { days: ahead, wide: true, caption: `${short(ahead[0].date)} – ${short(ahead[6].date)}` })] }), _jsxs("span", { className: "pbe-kpi-sub", children: [busiest ? (_jsxs(_Fragment, { children: ["Busiest ", _jsx("b", { children: formatDate(busiest.date, locale, { weekday: 'short', month: 'short', day: 'numeric' }) })] })) : ('Nothing booked yet'), closedDays ? ` · ${closedDays} ${closedDays === 1 ? 'day' : 'days'} closed` : ''] })] }), _jsxs("button", { type: "button", className: "pbe-kpi", onClick: () => go('hours'), children: [_jsxs("span", { className: "pbe-kpi-label", children: ["Booked time today", _jsx("span", { className: "pbe-arrow", children: _jsx(Icon, { name: "external" }) })] }), openMinutes ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "pbe-kpi-row", children: _jsxs("span", { className: "pbe-kpi-value", children: [Math.round(share * 100), "%", _jsx("small", { children: "of open time" })] }) }), _jsx(Meter, { value: share, label: `${Math.round(share * 100)}% of today's open time is booked` }), _jsxs("span", { className: "pbe-kpi-sub", children: [_jsx("b", { children: formatMinutes(bookedMinutes) }), " of ", formatMinutes(openMinutes), " open"] })] })) : (_jsxs(_Fragment, { children: [_jsx("span", { className: "pbe-kpi-row", children: _jsx("span", { className: "pbe-kpi-value pbe-kpi-value--muted", children: "Closed" }) }), _jsx("span", { className: "pbe-kpi-sub", children: "No opening hours today" })] }))] }), _jsxs("button", { type: "button", className: "pbe-kpi", onClick: () => go('bookings'), children: [_jsxs("span", { className: "pbe-kpi-label", children: ["Booked value \u00B7 this week", _jsx("span", { className: "pbe-arrow", children: _jsx(Icon, { name: "external" }) })] }), _jsx("span", { className: "pbe-kpi-row", children: _jsxs("span", { className: "pbe-kpi-value", children: [hasFrom ? _jsx("span", { className: "pbe-kpi-prefix", children: "from" }) : null, money(value)] }) }), _jsxs("span", { className: "pbe-kpi-sub", children: [weekLabel, waitingValue ? ` · + ${money(waitingValue)} in requests` : '', onRequest ? ` · ${onRequest} on request` : ''] })] })] }));
|
|
159
|
+
}
|
|
160
|
+
// ------------------------------------------------------------ schedule ---
|
|
161
|
+
/** Width in CSS pixels of `text` set in `font` (measured once per pair, with a canvas). */
|
|
162
|
+
const textWidths = new Map();
|
|
163
|
+
let measurer;
|
|
164
|
+
function textWidth(text, font) {
|
|
165
|
+
const key = `${font}|${text}`;
|
|
166
|
+
const known = textWidths.get(key);
|
|
167
|
+
if (known !== undefined)
|
|
168
|
+
return known;
|
|
169
|
+
if (measurer === undefined)
|
|
170
|
+
measurer = typeof document === 'undefined' ? null : document.createElement('canvas').getContext('2d');
|
|
171
|
+
if (!measurer)
|
|
172
|
+
return text.length * 8;
|
|
173
|
+
measurer.font = font;
|
|
174
|
+
const width = measurer.measureText(text).width;
|
|
175
|
+
textWidths.set(key, width);
|
|
176
|
+
return width;
|
|
177
|
+
}
|
|
178
|
+
/** Measure again once the dashboard's own font has loaded (earlier measurements may have used a fallback). */
|
|
179
|
+
function useFontsLoaded() {
|
|
180
|
+
const [tick, setTick] = useState(0);
|
|
181
|
+
useEffect(() => {
|
|
182
|
+
const fonts = typeof document !== 'undefined' ? document.fonts : undefined;
|
|
183
|
+
if (!fonts)
|
|
184
|
+
return;
|
|
185
|
+
let alive = true;
|
|
186
|
+
const remeasure = () => {
|
|
187
|
+
textWidths.clear();
|
|
188
|
+
if (alive)
|
|
189
|
+
setTick((t) => t + 1);
|
|
190
|
+
};
|
|
191
|
+
void fonts.ready.then(remeasure);
|
|
192
|
+
fonts.addEventListener('loadingdone', remeasure);
|
|
193
|
+
return () => {
|
|
194
|
+
alive = false;
|
|
195
|
+
fonts.removeEventListener('loadingdone', remeasure);
|
|
196
|
+
};
|
|
197
|
+
}, []);
|
|
198
|
+
return tick;
|
|
199
|
+
}
|
|
200
|
+
/** An element's width and font family, kept current (width 0 while it is hidden, e.g. on phones). */
|
|
201
|
+
function useMeasure() {
|
|
202
|
+
const [size, setSize] = useState({ width: 0, family: '' });
|
|
203
|
+
const observer = useRef(null);
|
|
204
|
+
const ref = useCallback((el) => {
|
|
205
|
+
observer.current?.disconnect();
|
|
206
|
+
observer.current = null;
|
|
207
|
+
if (!el)
|
|
208
|
+
return;
|
|
209
|
+
const read = () => {
|
|
210
|
+
const width = el.getBoundingClientRect().width;
|
|
211
|
+
const family = getComputedStyle(el).fontFamily;
|
|
212
|
+
setSize((s) => (s.width === width && s.family === family ? s : { width, family }));
|
|
213
|
+
};
|
|
214
|
+
read();
|
|
215
|
+
if (typeof ResizeObserver !== 'undefined') {
|
|
216
|
+
observer.current = new ResizeObserver(read);
|
|
217
|
+
observer.current.observe(el);
|
|
218
|
+
}
|
|
219
|
+
}, []);
|
|
220
|
+
return [ref, size];
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* The richest label that fits a block whole — never a name or a time cut
|
|
224
|
+
* short. `options` run from richest to barest; each is [title, line, tight].
|
|
225
|
+
* Without a measured width yet, the richest one (the stylesheet clips it).
|
|
226
|
+
*/
|
|
227
|
+
function fitLabel(width, family, options) {
|
|
228
|
+
if (!width || !family)
|
|
229
|
+
return { title: options[0]?.[0] ?? null, line: options[0]?.[1] ?? null };
|
|
230
|
+
const titleFont = `600 13px ${family}`;
|
|
231
|
+
const lineFont = `400 12px ${family}`;
|
|
232
|
+
for (const [title, line, tight] of options) {
|
|
233
|
+
const room = width - (tight ? 13 : 20) - 2;
|
|
234
|
+
if ((title === null || textWidth(title, titleFont) <= room) && (line === null || textWidth(line, lineFont) <= room))
|
|
235
|
+
return { title, line, tight };
|
|
236
|
+
}
|
|
237
|
+
return { title: null, line: null, tight: true };
|
|
238
|
+
}
|
|
239
|
+
function Schedule({ all, week, closures, today, now, onOpen, }) {
|
|
240
|
+
const { settings } = useAdmin();
|
|
241
|
+
const [laneRef, lane] = useMeasure();
|
|
242
|
+
useFontsLoaded();
|
|
243
|
+
const tz = settings.timezone;
|
|
244
|
+
const locale = settings.locale;
|
|
245
|
+
const time = (minutes) => formatClockTime(`${String(Math.floor(minutes / 60) % 24).padStart(2, '0')}:${String(minutes % 60).padStart(2, '0')}`, locale);
|
|
246
|
+
const nowMin = toMinutes(localTimeLabel(now, tz));
|
|
247
|
+
const todays = all.filter((b) => b.date === today && OCCUPYING.has(b.status)).sort((a, b) => a.startsAt.localeCompare(b.startsAt));
|
|
248
|
+
const open = openSpans(today, week, closures);
|
|
249
|
+
const { allDay, partial } = closuresOn(today, closures);
|
|
250
|
+
const spans = todays.map(bookingSpan);
|
|
251
|
+
const dayStart = Math.min(open[0]?.[0] ?? Infinity, ...spans.map((s) => s[0]));
|
|
252
|
+
const dayEnd = Math.max(open.at(-1)?.[1] ?? -Infinity, ...spans.map((s) => s[1]));
|
|
253
|
+
const openLabel = open.length ? open.map(([a, b]) => `${time(a)} – ${time(b)}`).join(', ') : 'Closed today';
|
|
254
|
+
// What comes next, for the closed and "day is done" states.
|
|
255
|
+
const nextDay = (() => {
|
|
256
|
+
for (let i = 1; i <= 21; i++) {
|
|
257
|
+
const d = addDays(today, i);
|
|
258
|
+
const hoursThatDay = openSpans(d, week, closures);
|
|
259
|
+
if (!hoursThatDay.length)
|
|
260
|
+
continue;
|
|
261
|
+
const bookings = all.filter((b) => b.date === d && OCCUPYING.has(b.status)).sort((a, b) => a.startsAt.localeCompare(b.startsAt));
|
|
262
|
+
return { date: d, opens: hoursThatDay[0][0], bookings };
|
|
263
|
+
}
|
|
264
|
+
return null;
|
|
265
|
+
})();
|
|
266
|
+
const nextText = nextDay
|
|
267
|
+
? `${dayWord(nextDay.date, tz, locale)}: ${nextDay.bookings.length
|
|
268
|
+
? `${nextDay.bookings.length} ${nextDay.bookings.length === 1 ? 'appointment' : 'appointments'}, the first at ${formatClockTime(nextDay.bookings[0].time, locale)}`
|
|
269
|
+
: `open from ${time(nextDay.opens)}, nothing booked yet`}.`
|
|
270
|
+
: 'No opening hours in the next three weeks.';
|
|
271
|
+
const head = (legend) => (_jsxs("div", { className: "pbe-card-head", children: [_jsx("h2", { className: "pbe-card-title", children: "Today\u2019s schedule" }), _jsx("span", { className: "pbe-card-sub", children: openLabel }), _jsxs("div", { className: "pbe-card-actions pbe-schedule-legend", "aria-hidden": "true", hidden: !legend, children: [_jsxs("span", { children: [_jsx("i", { className: "pbe-swatch pbe-swatch--confirmed" }), " Confirmed"] }), _jsxs("span", { children: [_jsx("i", { className: "pbe-swatch pbe-swatch--request" }), " Request"] }), _jsxs("span", { children: [_jsx("i", { className: "pbe-swatch pbe-swatch--open" }), " Open"] })] })] }));
|
|
272
|
+
if (!todays.length && !open.length) {
|
|
273
|
+
return (_jsxs("section", { className: "pbe-card", "aria-label": "Today\u2019s schedule", children: [head(false), _jsxs("div", { className: "pbe-day-state", children: [_jsx("span", { className: "pbe-day-state-icon", "aria-hidden": "true", children: _jsx(Icon, { name: "closure", size: 20 }) }), _jsxs("div", { className: "pbe-day-state-text", children: [_jsxs("p", { className: "pbe-day-state-title", children: ["Closed today", allDay?.reason ? ` · ${allDay.reason}` : ''] }), _jsx("p", { className: "pbe-day-state-sub", children: nextText })] })] })] }));
|
|
274
|
+
}
|
|
275
|
+
if (nowMin >= dayEnd) {
|
|
276
|
+
return (_jsxs("section", { className: "pbe-card", "aria-label": "Today\u2019s schedule", children: [head(false), _jsxs("div", { className: "pbe-day-state", children: [_jsx("span", { className: "pbe-day-state-icon", "aria-hidden": "true", children: _jsx(Icon, { name: "morning", size: 20 }) }), _jsxs("div", { className: "pbe-day-state-text", children: [_jsx("p", { className: "pbe-day-state-title", children: todays.length ? `Today is done · ${todays.length} ${todays.length === 1 ? 'appointment' : 'appointments'}` : 'Today is done' }), _jsx("p", { className: "pbe-day-state-sub", children: nextText })] })] })] }));
|
|
277
|
+
}
|
|
278
|
+
const rs = Math.floor(dayStart / 60) * 60;
|
|
279
|
+
const re = Math.ceil(dayEnd / 60) * 60;
|
|
280
|
+
const pct = (m) => ((Math.min(Math.max(m, rs), re) - rs) / (re - rs)) * 100;
|
|
281
|
+
const free = freeSpans(open, spans, Math.max(nowMin, rs)).filter(([a, b]) => b - a >= 30);
|
|
282
|
+
const breaks = [];
|
|
283
|
+
for (let i = 1; i < open.length; i++) {
|
|
284
|
+
const span = [open[i - 1][1], open[i][0]];
|
|
285
|
+
breaks.push({ span, reason: partial.find((p) => p.span[0] <= span[0] && p.span[1] >= span[1])?.reason ?? null });
|
|
286
|
+
}
|
|
287
|
+
let laneEnd = -1;
|
|
288
|
+
const lanes = spans.map(([s, e]) => {
|
|
289
|
+
const second = s < laneEnd;
|
|
290
|
+
laneEnd = Math.max(laneEnd, e);
|
|
291
|
+
return second;
|
|
292
|
+
});
|
|
293
|
+
const ticks = [];
|
|
294
|
+
for (let m = rs; m <= re; m += 60)
|
|
295
|
+
ticks.push(m);
|
|
296
|
+
const tick = (m, i) => {
|
|
297
|
+
const h = Math.floor(m / 60) % 24;
|
|
298
|
+
const label = formatClockTime(`${String(h).padStart(2, '0')}:00`, locale, { hour: 'numeric' });
|
|
299
|
+
const bare = i !== 0 && i !== ticks.length - 1 && h !== 12 ? label.replace(/\s?(AM|PM|am|pm|a\.m\.|p\.m\.)$/, '') : label;
|
|
300
|
+
return bare;
|
|
301
|
+
};
|
|
302
|
+
const nowPct = pct(nowMin);
|
|
303
|
+
const showNow = nowMin > rs && nowMin < re;
|
|
304
|
+
/** A block's width in pixels on the lane as drawn (0 until measured). */
|
|
305
|
+
const px = (a, b) => (lane.width ? ((pct(b) - pct(a)) / 100) * lane.width - 4 : 0);
|
|
306
|
+
const labelled = (label) => (_jsxs(_Fragment, { children: [label.title ? _jsx("b", { children: label.title }) : null, label.line ? _jsx("span", { children: label.line }) : null] }));
|
|
307
|
+
return (_jsxs("section", { className: "pbe-card", "aria-label": "Today\u2019s schedule", children: [head(true), _jsx("div", { className: "pbe-timeline", children: _jsxs("div", { className: "pbe-timeline-track", children: [_jsx("div", { className: "pbe-timeline-now-row" }), _jsxs("div", { className: "pbe-lane", ref: laneRef, children: [ticks.slice(1, -1).map((m) => (_jsx("span", { className: "pbe-lane-hour", style: { left: `${pct(m)}%` } }, m))), breaks.map(({ span: [a, b], reason }) => {
|
|
308
|
+
const label = fitLabel(px(a, b), lane.family, [['Closed', reason ?? `${time(a)} – ${time(b)}`], ['Closed', null], ['Closed', null, true], [null, null, true]]);
|
|
309
|
+
return (_jsx("div", { className: `pbe-block pbe-block--closed${label.tight ? ' pbe-block--tight' : ''}`, style: { left: `calc(${pct(a)}% + 2px)`, width: `calc(${pct(b) - pct(a)}% - 4px)` }, children: labelled(label) }, `c${a}`));
|
|
310
|
+
}), free.map(([a, b]) => {
|
|
311
|
+
const label = fitLabel(px(a, b), lane.family, [['Open', `${time(a)} – ${time(b)}`], ['Open', null], ['Open', null, true], [null, null, true]]);
|
|
312
|
+
return (_jsx("div", { className: `pbe-block pbe-block--open${label.tight ? ' pbe-block--tight' : ''}`, style: { left: `calc(${pct(a)}% + 2px)`, width: `calc(${pct(b) - pct(a)}% - 4px)` }, children: labelled(label) }, `f${a}`));
|
|
313
|
+
}), todays.map((b, i) => {
|
|
314
|
+
const [s, e] = spans[i];
|
|
315
|
+
const width = pct(e) - pct(s);
|
|
316
|
+
const state = e <= nowMin ? 'past' : s <= nowMin ? 'now' : null;
|
|
317
|
+
const at = formatClockTime(b.time, locale);
|
|
318
|
+
const bare = at.replace(/\s?(AM|PM|am|pm|a\.m\.|p\.m\.)$/, '');
|
|
319
|
+
const first = firstName(b.customer.name);
|
|
320
|
+
const detail = b.status === 'pending' ? `Request · ${at}` : `${b.serviceName} · ${at}`;
|
|
321
|
+
// Richest first: who, what and when → who and when → first name and when → when → a bare mark.
|
|
322
|
+
const label = fitLabel(px(s, e), lane.family, [
|
|
323
|
+
...(lanes[i]
|
|
324
|
+
? [[`${first} · ${at}`, null]]
|
|
325
|
+
: [
|
|
326
|
+
[b.customer.name, detail],
|
|
327
|
+
...(b.status === 'pending' ? [[first, detail]] : []),
|
|
328
|
+
[b.customer.name, at],
|
|
329
|
+
[first, at],
|
|
330
|
+
]),
|
|
331
|
+
[at, null, true],
|
|
332
|
+
...(bare !== at ? [[bare, null, true]] : []),
|
|
333
|
+
]);
|
|
334
|
+
const cls = ['pbe-block', `pbe-block--${b.status}`];
|
|
335
|
+
if (state)
|
|
336
|
+
cls.push(`pbe-block--${state}`);
|
|
337
|
+
if (lanes[i])
|
|
338
|
+
cls.push('pbe-block--lane2');
|
|
339
|
+
if (label.tight)
|
|
340
|
+
cls.push('pbe-block--tight');
|
|
341
|
+
const description = `${b.customer.name}, ${b.serviceName}, ${at} to ${formatClockTime(b.endTime, locale)}, ${STATUS_LABELS[b.status]}`;
|
|
342
|
+
return (_jsx("button", { type: "button", className: cls.join(' '), style: { left: `calc(${pct(s)}% + 2px)`, width: `calc(${width}% - 4px)`, ['--d']: Math.round(pct(s) * 3) }, "aria-label": description, title: description, onClick: () => onOpen(b), children: labelled(label) }, b.id));
|
|
343
|
+
})] }), _jsx("div", { className: "pbe-axis", "aria-hidden": "true", children: ticks.map((m, i) => (_jsx("span", { className: `pbe-axis-tick${i === 0 ? ' pbe-axis-tick--first' : i === ticks.length - 1 ? ' pbe-axis-tick--last' : ''}`, style: { left: `${pct(m)}%` }, children: tick(m, i) }, m))) }), showNow ? (_jsxs("div", { className: "pbe-now", style: { left: `${nowPct}%` }, "aria-hidden": "true", children: [_jsxs("span", { className: "pbe-now-label", style: nowPct < 6 ? { transform: 'none' } : nowPct > 94 ? { transform: 'translateX(-100%)' } : undefined, children: ["Now ", time(nowMin)] }), _jsx("span", { className: "pbe-now-line" }), _jsx("span", { className: "pbe-now-dot" })] })) : null] }) }), _jsx("ul", { className: "pbe-agenda", children: todays.length ? (todays.map((b, i) => {
|
|
344
|
+
const [s, e] = spans[i];
|
|
345
|
+
const state = e <= nowMin ? ' pbe-agenda-row--past' : s <= nowMin ? ' pbe-agenda-row--now' : '';
|
|
346
|
+
return (_jsx("li", { children: _jsxs("button", { type: "button", className: `pbe-agenda-row${state}`, onClick: () => onOpen(b), children: [_jsxs("span", { className: "pbe-agenda-time", children: [formatClockTime(b.time, locale), _jsx("span", { children: formatClockTime(b.endTime, locale) })] }), _jsxs("span", { className: "pbe-agenda-main", children: [_jsx("span", { children: b.customer.name }), _jsx("span", { children: b.serviceName })] }), _jsx(StatusBadge, { status: b.status })] }) }, b.id));
|
|
347
|
+
})) : (_jsxs("li", { className: "pbe-day-state", children: [_jsx("span", { className: "pbe-day-state-icon", "aria-hidden": "true", children: _jsx(Icon, { name: "bookings", size: 20 }) }), _jsxs("span", { className: "pbe-day-state-text", children: [_jsx("span", { className: "pbe-day-state-title", children: "No appointments yet today" }), _jsxs("span", { className: "pbe-day-state-sub", children: ["Open ", openLabel] })] })] })) })] }));
|
|
348
|
+
}
|
|
349
|
+
// ---------------------------------------------------------- now & next ---
|
|
350
|
+
function NowNext({ all, services, now, onOpen }) {
|
|
351
|
+
const { settings, go } = useAdmin();
|
|
352
|
+
const tz = settings.timezone;
|
|
353
|
+
const locale = settings.locale;
|
|
354
|
+
if (!all) {
|
|
355
|
+
return (_jsxs("section", { className: "pbe-card pbe-card--pad", "aria-label": "Now and next", children: [_jsx("span", { className: "pbe-sr-only", role: "status", children: "Loading\u2026" }), _jsxs("div", { className: "pbe-skeleton", "aria-hidden": "true", children: [_jsx("span", { className: "pbe-sk pbe-sk--title" }), _jsx("span", { className: "pbe-sk", style: { height: 52, borderRadius: 10 } }), _jsx("span", { className: "pbe-sk" })] })] }));
|
|
356
|
+
}
|
|
357
|
+
const list = all.filter((b) => OCCUPYING.has(b.status)).sort((a, b) => a.startsAt.localeCompare(b.startsAt));
|
|
358
|
+
const current = list.find((b) => b.status !== 'pending' && Date.parse(b.startsAt) <= now && now < Date.parse(b.endsAt)) ?? null;
|
|
359
|
+
const next = list.find((b) => Date.parse(b.startsAt) > now) ?? null;
|
|
360
|
+
const clock = (b) => `${formatClockTime(b.time, locale)} – ${formatClockTime(b.endTime, locale)}`;
|
|
361
|
+
const inMinutes = next ? Date.parse(next.startsAt) - now : 0;
|
|
362
|
+
const nextWhen = next
|
|
363
|
+
? next.date === todayInTimeZone(tz, new Date(now))
|
|
364
|
+
? `Next · in ${formatSpan(inMinutes)}`
|
|
365
|
+
: `Next · ${dayWord(next.date, tz, locale)}, ${formatClockTime(next.time, locale)}`
|
|
366
|
+
: null;
|
|
367
|
+
return (_jsxs("section", { className: "pbe-card pbe-nownext", "aria-labelledby": "pbe-nownext-title", children: [_jsx("div", { className: "pbe-card-head", children: _jsx("h2", { id: "pbe-nownext-title", className: "pbe-card-title", children: "Now & next" }) }), current ? (_jsxs("button", { type: "button", className: "pbe-now-card", onClick: () => onOpen(current), children: [_jsx(Ring, { size: 36, tone: "accent", fraction: (now - Date.parse(current.startsAt)) / (Date.parse(current.endsAt) - Date.parse(current.startsAt)) }), _jsxs("span", { children: [_jsx("span", { className: "pbe-kicker", children: "Now" }), _jsx("span", { className: "pbe-now-who", children: current.customer.name }), _jsxs("span", { className: "pbe-now-meta", children: [current.serviceName, " \u00B7 ", clock(current)] })] }), _jsxs("span", { className: "pbe-now-left", children: [formatSpan(Date.parse(current.endsAt) - now), " left"] })] })) : null, next ? (_jsxs("div", { className: "pbe-next", children: [_jsxs("div", { className: "pbe-next-top", children: [_jsxs("div", { children: [_jsx("p", { className: "pbe-kicker", children: nextWhen }), _jsx("p", { className: "pbe-next-name", children: next.customer.name })] }), _jsx(StatusBadge, { status: next.status })] }), _jsxs("p", { className: "pbe-next-meta", children: [next.serviceName, " \u00B7 ", clock(next), " \u00B7 ", priceText(next, services, locale)] }), next.notes ? (_jsxs("p", { className: "pbe-note", children: [_jsx(Icon, { name: "note" }), _jsxs("span", { children: ["\u201C", next.notes, "\u201D"] })] })) : null, _jsxs("div", { className: "pbe-next-actions", children: [_jsxs("a", { className: "pbe-button pbe-button--sm", href: `mailto:${next.customer.email}`, children: [_jsx(Icon, { name: "email" }), "Email"] }), next.customer.phone ? (_jsxs("a", { className: "pbe-button pbe-button--sm", href: `tel:${next.customer.phone.replace(/[^\d+]/g, '')}`, children: [_jsx(Icon, { name: "phone" }), "Call"] })) : null, _jsx(Button, { size: "sm", variant: "quiet", onClick: () => onOpen(next), children: "Details" }), _jsx("span", { className: "pbe-mono", children: next.reference })] })] })) : !current ? (_jsxs("div", { className: "pbe-next", children: [_jsx("p", { className: "pbe-next-meta", children: "Nothing booked in the next 30 days." }), _jsx("div", { className: "pbe-next-actions", children: _jsx(Button, { size: "sm", iconAfter: "arrow", onClick: () => go('bookings'), children: "Open Bookings" }) })] })) : null] }));
|
|
368
|
+
}
|
|
369
|
+
// -------------------------------------------------------- closures ahead ---
|
|
370
|
+
function ClosuresAhead({ closures, today }) {
|
|
371
|
+
const { settings, go } = useAdmin();
|
|
372
|
+
const locale = settings.locale;
|
|
373
|
+
const upcoming = (closures ?? []).filter((c) => c.endsOn >= today).sort((a, b) => a.startsOn.localeCompare(b.startsOn)).slice(0, 4);
|
|
374
|
+
const date = (d) => formatDate(d, locale, { weekday: 'short', month: 'short', day: 'numeric' });
|
|
375
|
+
return (_jsxs("section", { className: "pbe-card", "aria-labelledby": "pbe-closures-ahead-title", children: [_jsxs("div", { className: "pbe-card-head", children: [_jsx("h2", { id: "pbe-closures-ahead-title", className: "pbe-card-title", children: "Closures ahead" }), _jsx("div", { className: "pbe-card-actions", children: _jsxs("button", { type: "button", className: "pbe-link-button pbe-link-button--quiet", onClick: () => go('hours'), children: ["Hours & closures ", _jsx(Icon, { name: "arrow" })] }) })] }), closures === null ? (_jsx("div", { className: "pbe-card-body", children: _jsxs("div", { className: "pbe-skeleton", "aria-hidden": "true", children: [_jsx("span", { className: "pbe-sk" }), _jsx("span", { className: "pbe-sk" })] }) })) : upcoming.length ? (_jsx("ul", { className: "pbe-list-rows", children: upcoming.map((c) => (_jsxs("li", { className: "pbe-list-row", children: [_jsx("span", { className: "pbe-list-row-date", children: date(c.startsOn) }), _jsxs("span", { className: "pbe-list-row-main", children: [_jsx("span", { children: c.endsOn !== c.startsOn ? `Until ${date(c.endsOn)}` : c.startTime ? `${formatClockTime(c.startTime, locale)} – ${formatClockTime(c.endTime ?? '24:00', locale)}` : 'All day' }), _jsx("span", { children: c.reason ?? 'No note' })] })] }, c.id))) })) : (_jsx("div", { className: "pbe-card-body", children: _jsx("p", { className: "pbe-help", children: "No closures planned. Add holidays and time off so nobody can book them." }) }))] }));
|
|
376
|
+
}
|
|
377
|
+
function useHealth(email) {
|
|
378
|
+
const { settings, contentSchema, website } = useAdmin();
|
|
379
|
+
const items = [];
|
|
380
|
+
if (email) {
|
|
381
|
+
const { lastSuccessAt, lastFailureAt } = email.mailer;
|
|
382
|
+
const failing = Boolean(lastFailureAt && (!lastSuccessAt || Date.parse(lastFailureAt) > Date.parse(lastSuccessAt)));
|
|
383
|
+
items.push(failing
|
|
384
|
+
? { key: 'email', tone: 'bad', text: 'Booking emails failing', section: 'email' }
|
|
385
|
+
: lastSuccessAt
|
|
386
|
+
? { key: 'email', tone: 'ok', text: 'Booking emails working', detail: `last sent ${formatAgo(lastSuccessAt)}`, section: 'email' }
|
|
387
|
+
: { key: 'email', tone: 'warn', text: 'Booking emails not set up yet', section: 'email' });
|
|
388
|
+
}
|
|
389
|
+
// Only when missing: without an address nobody is told about a new request.
|
|
390
|
+
if (!alertsAddress(settings)) {
|
|
391
|
+
items.push({
|
|
392
|
+
key: 'alerts',
|
|
393
|
+
tone: settings.onlineBookingEnabled ? 'bad' : 'warn',
|
|
394
|
+
text: 'New-request alerts: no address',
|
|
395
|
+
section: 'email',
|
|
396
|
+
view: ALERTS_VIEW,
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
if (contentSchema && website) {
|
|
400
|
+
items.push(website.hasUnpublishedChanges
|
|
401
|
+
? { key: 'website', tone: 'warn', text: 'Website has unpublished changes', section: 'website' }
|
|
402
|
+
: website.version > 0
|
|
403
|
+
? {
|
|
404
|
+
key: 'website',
|
|
405
|
+
tone: 'ok',
|
|
406
|
+
text: 'Website live',
|
|
407
|
+
detail: `version ${website.version}${website.publishedAt ? `, ${formatDateTime(website.publishedAt, settings.timezone, settings.locale, { month: 'short', day: 'numeric' })}` : ''}`,
|
|
408
|
+
section: 'website',
|
|
409
|
+
}
|
|
410
|
+
: { key: 'website', tone: 'off', text: 'Website shows its built-in text', section: 'website' });
|
|
411
|
+
}
|
|
412
|
+
items.push(settings.onlineBookingEnabled
|
|
413
|
+
? { key: 'online', tone: 'ok', text: 'Online booking on', section: 'email' }
|
|
414
|
+
: { key: 'online', tone: 'off', text: 'Online booking off', section: 'email' });
|
|
415
|
+
return items;
|
|
416
|
+
}
|
|
417
|
+
function Health({ email }) {
|
|
418
|
+
const { go } = useAdmin();
|
|
419
|
+
const items = useHealth(email);
|
|
420
|
+
return (_jsx("ul", { className: "pbe-health", "aria-label": "System status", children: items.map((i) => (_jsx("li", { children: _jsxs("button", { type: "button", className: "pbe-health-item", onClick: () => go(i.section, i.view), children: [_jsx("span", { className: `pbe-dot pbe-dot--${i.tone}`, "aria-hidden": "true" }), i.text, i.detail ? _jsxs("span", { className: "pbe-muted", children: ["\u00B7 ", i.detail] }) : null] }) }, i.key))) }));
|
|
421
|
+
}
|
|
422
|
+
/** Phones: the same status as a card at the end of the page. */
|
|
423
|
+
function HealthCard({ email }) {
|
|
424
|
+
const { go } = useAdmin();
|
|
425
|
+
const items = useHealth(email);
|
|
426
|
+
return (_jsxs("section", { className: "pbe-card pbe-health-card", "aria-labelledby": "pbe-health-title", children: [_jsx("div", { className: "pbe-card-head", children: _jsx("h2", { id: "pbe-health-title", className: "pbe-card-title", children: "Everything running?" }) }), _jsx("ul", { className: "pbe-list-rows", children: items.map((i) => (_jsx("li", { children: _jsxs("button", { type: "button", className: "pbe-list-row pbe-health-row", onClick: () => go(i.section, i.view), children: [_jsx("span", { className: `pbe-dot pbe-dot--${i.tone}`, "aria-hidden": "true" }), _jsxs("span", { className: "pbe-list-row-main", children: [_jsx("span", { children: i.text }), i.detail ? _jsx("span", { children: i.detail }) : null] }), _jsx(Icon, { name: "right" })] }) }, i.key))) })] }));
|
|
427
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function ServicesSection(): import("react").JSX.Element;
|