@composable-os/pack-bookings 0.1.0-beta.10 → 0.1.0-beta.13
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/dist/automations.d.ts +146 -0
- package/dist/automations.js +612 -0
- package/dist/blocks/bookings-class-list/class-list.d.ts +16 -0
- package/dist/blocks/bookings-class-list/class-list.js +62 -0
- package/dist/blocks/bookings-desk/desk.d.ts +7 -0
- package/dist/blocks/bookings-desk/desk.js +17 -1
- package/dist/blocks/bookings-drop-in/drop-in.d.ts +28 -0
- package/dist/blocks/bookings-drop-in/drop-in.js +137 -0
- package/dist/blocks/bookings-native-class-list/class-list-screen.d.ts +12 -0
- package/dist/blocks/bookings-native-class-list/class-list-screen.js +59 -0
- package/dist/blocks/bookings-native-timetable/timetable-screen.d.ts +7 -2
- package/dist/blocks/bookings-native-timetable/timetable-screen.js +90 -18
- package/dist/blocks/bookings-timetable/timetable.d.ts +9 -2
- package/dist/blocks/bookings-timetable/timetable.js +100 -11
- package/dist/client/index.d.ts +1270 -182
- package/dist/client/index.js +102 -3
- package/dist/dashboards.d.ts +5 -0
- package/dist/dashboards.js +157 -0
- package/dist/index.d.ts +2617 -407
- package/dist/index.js +1133 -68
- package/dist/routine-mail.d.ts +577 -0
- package/dist/routine-mail.js +443 -0
- package/dist/tools.d.ts +597 -0
- package/dist/tools.js +1628 -102
- package/package.json +3 -3
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { classTime, todayIn } from "@composable-os/pack-bookings/client";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Button } from "../ui-button/button.js";
|
|
5
|
+
/**
|
|
6
|
+
* A class's list as the product's admin shows it (stage 47): on a class's page, that class's
|
|
7
|
+
* list; opened from the navigation (a coach), today's classes in this browser's zone to choose
|
|
8
|
+
* one from. Which classes a coach may open (today's only) is the host's: it lists no others.
|
|
9
|
+
*/
|
|
10
|
+
export function TodayClassList({ bookings, classId, }) {
|
|
11
|
+
const [chosen, setChosen] = useState(null);
|
|
12
|
+
if (classId)
|
|
13
|
+
return _jsx(ClassList, { bookings: bookings, classId: classId });
|
|
14
|
+
if (chosen) {
|
|
15
|
+
return (_jsxs("div", { className: "grid gap-3", children: [_jsx(Button, { type: "button", variant: "outline", className: "w-fit", onClick: () => setChosen(null), children: "Today's classes" }), _jsx(ClassList, { bookings: bookings, classId: chosen })] }));
|
|
16
|
+
}
|
|
17
|
+
return _jsx(TodayClasses, { bookings: bookings, onOpen: setChosen });
|
|
18
|
+
}
|
|
19
|
+
function TodayClasses({ bookings, onOpen, }) {
|
|
20
|
+
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";
|
|
21
|
+
const day = bookings.useDay({ date: todayIn(timeZone), timeZone });
|
|
22
|
+
if (day.isPending)
|
|
23
|
+
return _jsx("p", { "aria-busy": "true", children: "Loading today's classes\u2026" });
|
|
24
|
+
if (day.error || !day.data)
|
|
25
|
+
return _jsx("p", { role: "alert", children: "We could not load today's classes." });
|
|
26
|
+
if (!day.data.classes.length)
|
|
27
|
+
return _jsx("p", { role: "status", children: "No classes today." });
|
|
28
|
+
return (_jsx("ul", { className: "grid gap-2", "aria-label": "Today's classes", children: day.data.classes.map((klass) => (_jsx("li", { children: _jsxs(Button, { type: "button", variant: "outline", className: "w-full justify-between", onClick: () => onOpen(klass.id), children: [_jsxs("span", { children: [klass.title ?? "Class", " \u00B7 ", classTime(klass)] }), _jsx("span", { children: klass.state === "scheduled" ? `${klass.booked} booked` : klass.state })] }) }, klass.id))) }));
|
|
29
|
+
}
|
|
30
|
+
const STATE_LABEL = {
|
|
31
|
+
booked: "Booked",
|
|
32
|
+
attended: "Came",
|
|
33
|
+
no_show: "Did not come",
|
|
34
|
+
waiting: "Waiting",
|
|
35
|
+
};
|
|
36
|
+
export function ClassList({ bookings, classId }) {
|
|
37
|
+
const list = bookings.useRoster({ classId });
|
|
38
|
+
const tick = bookings.useMarkAttended();
|
|
39
|
+
const untick = bookings.useUndoAttended();
|
|
40
|
+
const [message, setMessage] = useState(null);
|
|
41
|
+
if (list.isPending)
|
|
42
|
+
return _jsx("p", { "aria-busy": "true", children: "Loading the list\u2026" });
|
|
43
|
+
if (list.error || !list.data)
|
|
44
|
+
return _jsx("p", { role: "alert", children: "We could not load the list." });
|
|
45
|
+
const { class: klass } = list.data;
|
|
46
|
+
// Cancelled and moved bookings are not on the list a coach ticks.
|
|
47
|
+
const shown = list.data.bookings.filter((b) => b.state && b.state in STATE_LABEL);
|
|
48
|
+
const say = async (done) => {
|
|
49
|
+
setMessage(null);
|
|
50
|
+
try {
|
|
51
|
+
setMessage((await done).message);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
setMessage("That did not work. Try again.");
|
|
55
|
+
}
|
|
56
|
+
await list.refetch?.();
|
|
57
|
+
};
|
|
58
|
+
return (_jsxs("section", { className: "grid gap-3", "aria-label": "Class list", children: [_jsxs("h2", { className: "text-lg font-medium", children: [klass.title ?? "Class", " \u00B7 ", classTime(klass)] }), _jsxs("p", { children: [klass.booked, " booked of ", klass.places ?? "unlimited"] }), _jsx("ul", { className: "grid gap-2", children: shown.map((booking) => {
|
|
59
|
+
const name = booking.person?.name ?? "No name";
|
|
60
|
+
return (_jsxs("li", { className: "flex items-center justify-between gap-4 rounded-md border p-2", children: [_jsxs("span", { children: [name, " \u00B7 ", STATE_LABEL[booking.state ?? ""], booking.markedBy ? ` (${booking.markedBy})` : "", booking.healthNote ? (_jsx("span", { className: "ml-2 rounded border px-1 text-xs", "data-testid": "health-note", children: "Health note" })) : null] }), booking.state === "booked" || booking.state === "no_show" ? (_jsxs(Button, { type: "button", disabled: tick.isPending, onClick: () => say(tick.mutateAsync({ bookingId: booking.id })), children: ["Tick ", name] })) : booking.state === "attended" ? (_jsxs(Button, { type: "button", variant: "outline", disabled: untick.isPending, onClick: () => say(untick.mutateAsync({ bookingId: booking.id })), children: ["Untick ", name] })) : null] }, booking.id));
|
|
61
|
+
}) }), message ? _jsx("p", { role: "status", children: message }) : null] }));
|
|
62
|
+
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type { BookingsHooks } from "@composable-os/pack-bookings/client";
|
|
2
2
|
type Hooks = Pick<BookingsHooks, "useDay" | "useBookFor" | "useFindPeople">;
|
|
3
|
+
/**
|
|
4
|
+
* The front desk as the product's admin shows it (stage 47): today in the desk's own zone (the
|
|
5
|
+
* browser's), with a day to choose. The admin passes it nothing but the hooks.
|
|
6
|
+
*/
|
|
7
|
+
export declare function FrontDesk({ bookings }: {
|
|
8
|
+
bookings: Hooks;
|
|
9
|
+
}): import("react").JSX.Element;
|
|
3
10
|
export declare function Desk({ bookings, date, timeZone, }: {
|
|
4
11
|
bookings: Hooks;
|
|
5
12
|
/** The local date shown, YYYY-MM-DD. */
|
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { classTime } from "@composable-os/pack-bookings/client";
|
|
2
|
+
import { classTime, todayIn } from "@composable-os/pack-bookings/client";
|
|
3
3
|
import { useState } from "react";
|
|
4
4
|
import { Button } from "../ui-button/button.js";
|
|
5
5
|
import { Input } from "../ui-input/input.js";
|
|
6
6
|
import { Label } from "../ui-label/label.js";
|
|
7
|
+
/**
|
|
8
|
+
* The front desk as the product's admin shows it (stage 47): today in the desk's own zone (the
|
|
9
|
+
* browser's), with a day to choose. The admin passes it nothing but the hooks.
|
|
10
|
+
*/
|
|
11
|
+
export function FrontDesk({ bookings }) {
|
|
12
|
+
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";
|
|
13
|
+
const [date, setDate] = useState(() => todayIn(timeZone));
|
|
14
|
+
return (_jsxs("div", { className: "grid gap-4", children: [_jsxs("div", { className: "grid max-w-xs gap-1", children: [_jsx(Label, { htmlFor: "desk-date", children: "Day" }), _jsx(Input, { id: "desk-date", type: "date", value: date, onChange: (event) => {
|
|
15
|
+
if (event.target.value)
|
|
16
|
+
setDate(event.target.value);
|
|
17
|
+
} })] }), _jsx(Desk, { bookings: bookings, date: date, timeZone: timeZone })] }));
|
|
18
|
+
}
|
|
7
19
|
export function Desk({ bookings, date, timeZone, }) {
|
|
8
20
|
const day = bookings.useDay({ date, timeZone });
|
|
9
21
|
const bookFor = bookings.useBookFor();
|
|
@@ -41,6 +53,10 @@ export function Desk({ bookings, date, timeZone, }) {
|
|
|
41
53
|
setQuery("");
|
|
42
54
|
return;
|
|
43
55
|
}
|
|
56
|
+
if (done.result === "waiting") {
|
|
57
|
+
setMessage(done.message);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
44
60
|
setMatches(done.people ?? []);
|
|
45
61
|
setMessage(done.message);
|
|
46
62
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type AgreementsHooks } from "@composable-os/client";
|
|
2
|
+
import type { BookingsHooks } from "@composable-os/pack-bookings/client";
|
|
3
|
+
/** The agreements hooks the inline step uses: a member's (due, accept) and a visitor's (words). */
|
|
4
|
+
export type DropInAgreements = Pick<AgreementsHooks, "useDue" | "useAccept" | "useGuestVersions">;
|
|
5
|
+
type Hooks = Pick<BookingsHooks, "useTimetable" | "useBuy">;
|
|
6
|
+
/** What the buyer is shown before they leave for the provider's page. */
|
|
7
|
+
export interface StartedDropIn {
|
|
8
|
+
orderId: string;
|
|
9
|
+
bookingId: string;
|
|
10
|
+
token: string | null;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* `signedIn`: the buyer is a signed-in member (no email asked). `returnUrl`: where the provider
|
|
14
|
+
* sends them back, on one of the deployment's allowed sites; coming back books nothing, the
|
|
15
|
+
* verified payment does. `onStarted` is called before they leave (keep a guest's token).
|
|
16
|
+
* `agreements`: the agreements hooks, for what must be agreed to first (without them, a refusal
|
|
17
|
+
* only names the documents).
|
|
18
|
+
*/
|
|
19
|
+
export declare function DropIn({ bookings, agreements, signedIn, returnUrl, onStarted, from, to, }: {
|
|
20
|
+
bookings: Hooks;
|
|
21
|
+
agreements?: DropInAgreements;
|
|
22
|
+
signedIn: boolean;
|
|
23
|
+
returnUrl: string;
|
|
24
|
+
onStarted?: (started: StartedDropIn) => void;
|
|
25
|
+
from?: string;
|
|
26
|
+
to?: string;
|
|
27
|
+
}): import("react").JSX.Element;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// Paying for one class on a gym's site (stage 31a step 8, a drop-in): the week's classes for a
|
|
3
|
+
// visitor, each with "Pay for this class". The host holds a place while they pay, prices it, and
|
|
4
|
+
// books them when the payment provider confirms it; an unpaid order lets the place go after a few
|
|
5
|
+
// minutes. Whether a class can be paid for, its price, the places left and the rules are the
|
|
6
|
+
// host's: this shows its answers and sends the buyer to the provider's page. Web only: a native
|
|
7
|
+
// block never buys (the block lint).
|
|
8
|
+
//
|
|
9
|
+
// What must be agreed to first (a waiver, a health form: stage 44) is the host's answer too: when
|
|
10
|
+
// "Pay" is refused with it, the documents are shown inline (the web-agree block's step) and "Pay"
|
|
11
|
+
// is tried again. A visitor's agreements travel in the buying call and are recorded with the order;
|
|
12
|
+
// a member's are recorded as they agree. What a visitor typed, drew and answered is held in memory
|
|
13
|
+
// only until that call. A minor whose purchase needs the payer's agreement is told a parent or
|
|
14
|
+
// guardian buys it.
|
|
15
|
+
import { agreementRefusal, forgetAfter, purchaseErrorWords, withAgreements, } from "@composable-os/client";
|
|
16
|
+
import { classTime, formatAmount, placesLabel, refusalMessage, } from "@composable-os/pack-bookings/client";
|
|
17
|
+
import { useState } from "react";
|
|
18
|
+
import { Button } from "../ui-button/button.js";
|
|
19
|
+
import { Input } from "../ui-input/input.js";
|
|
20
|
+
import { Label } from "../ui-label/label.js";
|
|
21
|
+
import { useForgetOnLeave } from "../web-agree/agree.js";
|
|
22
|
+
import { GuestAgreementStep, MemberAgreementStep } from "../web-agree/agreement-step.js";
|
|
23
|
+
/**
|
|
24
|
+
* `signedIn`: the buyer is a signed-in member (no email asked). `returnUrl`: where the provider
|
|
25
|
+
* sends them back, on one of the deployment's allowed sites; coming back books nothing, the
|
|
26
|
+
* verified payment does. `onStarted` is called before they leave (keep a guest's token).
|
|
27
|
+
* `agreements`: the agreements hooks, for what must be agreed to first (without them, a refusal
|
|
28
|
+
* only names the documents).
|
|
29
|
+
*/
|
|
30
|
+
export function DropIn({ bookings, agreements, signedIn, returnUrl, onStarted, from, to, }) {
|
|
31
|
+
const timetable = bookings.useTimetable({ ...(from ? { from } : {}), ...(to ? { to } : {}) });
|
|
32
|
+
const [chosen, setChosen] = useState(null);
|
|
33
|
+
if (timetable.isPending)
|
|
34
|
+
return _jsx("p", { "aria-busy": "true", children: "Loading the timetable\u2026" });
|
|
35
|
+
if (timetable.error || !timetable.data) {
|
|
36
|
+
return _jsx("p", { role: "alert", children: "We could not load the timetable. Try again soon." });
|
|
37
|
+
}
|
|
38
|
+
if (chosen) {
|
|
39
|
+
return (_jsx(PayForm, { klass: chosen, bookings: bookings, agreements: agreements, signedIn: signedIn, returnUrl: returnUrl, onStarted: onStarted, onBack: () => setChosen(null) }));
|
|
40
|
+
}
|
|
41
|
+
return (_jsxs("section", { className: "grid gap-4", "aria-label": "Pay for a class", children: [timetable.data.classes.length === 0 ? _jsx("p", { children: "No classes in these days." }) : null, _jsx("ul", { className: "grid gap-2", children: timetable.data.classes.map((klass) => (_jsxs("li", { className: "flex flex-wrap items-center justify-between gap-3 rounded-md border p-3", children: [_jsxs("div", { className: "grid gap-1", children: [_jsx("strong", { children: klass.title ?? "Class" }), _jsx("span", { children: classTime(klass) }), _jsx("span", { className: "text-muted-foreground text-sm", children: [klass.coach?.name, klass.room?.name, placesLabel(klass.places)]
|
|
42
|
+
.filter(Boolean)
|
|
43
|
+
.join(" · ") })] }), _jsxs(Button, { variant: "outline", onClick: () => setChosen(klass), children: ["Pay for ", klass.title ?? "this class"] })] }, klass.id))) })] }));
|
|
44
|
+
}
|
|
45
|
+
function PayForm({ klass, bookings, agreements, signedIn, returnUrl, onStarted, onBack, }) {
|
|
46
|
+
const buy = bookings.useBuy();
|
|
47
|
+
const [email, setEmail] = useState("");
|
|
48
|
+
const [message, setMessage] = useState(null);
|
|
49
|
+
const [problem, setProblem] = useState(null);
|
|
50
|
+
// A member's "a copy is on its way", kept while the payment starts.
|
|
51
|
+
const [said, setSaid] = useState(null);
|
|
52
|
+
// What the host said must be agreed to first, and a minor's "a parent or guardian buys it".
|
|
53
|
+
const [due, setDue] = useState(null);
|
|
54
|
+
const [minor, setMinor] = useState(null);
|
|
55
|
+
// A visitor's agreements for this attempt: in this component's state only (never the app's
|
|
56
|
+
// cache), kept if the payment cannot start so nothing is typed twice, forgotten once it starts,
|
|
57
|
+
// when they go back, and when they leave the page.
|
|
58
|
+
const [agreed, setAgreed] = useState(null);
|
|
59
|
+
const [busy, setBusy] = useState(false);
|
|
60
|
+
useForgetOnLeave(() => setAgreed(null));
|
|
61
|
+
const name = klass.title ?? "Class";
|
|
62
|
+
/** Starts the order (with a visitor's agreements, once given) and opens the payment page. */
|
|
63
|
+
async function pay(given = agreed) {
|
|
64
|
+
setMessage(null);
|
|
65
|
+
setProblem(null);
|
|
66
|
+
setBusy(true);
|
|
67
|
+
try {
|
|
68
|
+
const outcome = await withAgreements((previous) => forgetAfter(buy.start, {
|
|
69
|
+
classId: klass.id,
|
|
70
|
+
...(signedIn ? {} : { email }),
|
|
71
|
+
// A version replaced meanwhile: ask again with none, and the host names what is due now.
|
|
72
|
+
...(!signedIn && given && previous?.kind !== "read_again" ? { agreements: given } : {}),
|
|
73
|
+
}));
|
|
74
|
+
if (outcome.kind === "due") {
|
|
75
|
+
setAgreed(null);
|
|
76
|
+
if (agreements)
|
|
77
|
+
setDue(outcome.documents);
|
|
78
|
+
else {
|
|
79
|
+
setProblem(`Something must be agreed to first: ${outcome.documents.map((d) => d.title).join(", ")}.`);
|
|
80
|
+
}
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (outcome.kind === "minor_payer") {
|
|
84
|
+
setAgreed(null);
|
|
85
|
+
setMinor(outcome.message);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const held = outcome.value;
|
|
89
|
+
if (held.result === "refused") {
|
|
90
|
+
setMessage(refusalMessage(held, klass.timeZone));
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
// Recorded with the order: nothing of it is kept here any more.
|
|
94
|
+
setAgreed(null);
|
|
95
|
+
onStarted?.({ orderId: held.orderId, bookingId: held.bookingId, token: held.token });
|
|
96
|
+
setMessage(`Your place is held. ${formatAmount(held.total, held.currency)} to pay.`);
|
|
97
|
+
const page = await forgetAfter(buy.checkout, {
|
|
98
|
+
id: held.orderId,
|
|
99
|
+
...(held.token ? { token: held.token } : {}),
|
|
100
|
+
returnUrl,
|
|
101
|
+
});
|
|
102
|
+
window.location.assign(page.url);
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
const refusal = agreementRefusal(error);
|
|
106
|
+
if (refusal?.kind === "read_again" || refusal?.kind === "changed")
|
|
107
|
+
setAgreed(null);
|
|
108
|
+
setProblem(purchaseErrorWords(error) ?? "We could not start the payment. Try again soon.");
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
setBusy(false);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async function submit(e) {
|
|
115
|
+
e.preventDefault();
|
|
116
|
+
await pay();
|
|
117
|
+
}
|
|
118
|
+
if (minor) {
|
|
119
|
+
return (_jsxs("section", { className: "grid gap-3", "aria-label": `Pay for ${name}`, children: [_jsx("p", { role: "alert", children: minor }), _jsx(Button, { type: "button", variant: "outline", onClick: onBack, children: "Back" })] }));
|
|
120
|
+
}
|
|
121
|
+
if (due && agreements) {
|
|
122
|
+
const back = () => setDue(null);
|
|
123
|
+
return signedIn ? (_jsx(MemberAgreementStep, { agreements: agreements, documents: due, continueLabel: "Agree and pay", onCancel: back, onAgreed: (copy) => {
|
|
124
|
+
setDue(null);
|
|
125
|
+
setSaid(copy);
|
|
126
|
+
void pay(null);
|
|
127
|
+
} })) : (_jsx(GuestAgreementStep, { agreements: agreements, documents: due, onCancel: back, onAgreed: (given) => {
|
|
128
|
+
setDue(null);
|
|
129
|
+
setAgreed(given);
|
|
130
|
+
void pay(given);
|
|
131
|
+
} }));
|
|
132
|
+
}
|
|
133
|
+
return (_jsxs("form", { onSubmit: submit, className: "grid gap-4", "aria-label": `Pay for ${name}`, children: [_jsxs("div", { className: "grid gap-1", children: [_jsx("strong", { children: name }), _jsx("span", { children: classTime(klass) })] }), signedIn ? null : (_jsxs("div", { className: "grid gap-1", children: [_jsx(Label, { htmlFor: "drop-in-email", children: "Your email" }), _jsx(Input, { id: "drop-in-email", type: "email", autoComplete: "email", required: true, value: email, onChange: (e) => setEmail(e.target.value) })] })), said ? _jsx("p", { role: "status", children: said }) : null, agreed ? (_jsx("p", { className: "text-sm", "data-agreed": agreed.length, children: "What you agreed to is kept for this payment: press Pay to try again." })) : null, message ? _jsx("p", { role: "status", children: message }) : null, problem ? _jsx("p", { role: "alert", children: problem }) : null, _jsxs("div", { className: "flex flex-wrap gap-2", children: [_jsx(Button, { type: "submit", disabled: busy, children: busy ? "Opening the payment page…" : "Pay" }), _jsx(Button, { type: "button", variant: "outline", onClick: () => {
|
|
134
|
+
setAgreed(null);
|
|
135
|
+
onBack();
|
|
136
|
+
}, children: "Back" })] })] }));
|
|
137
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { BookingsHooks } from "@composable-os/pack-bookings/client";
|
|
2
|
+
type Hooks = Pick<BookingsHooks, "useDay" | "useRoster" | "useMarkAttended" | "useUndoAttended" | "useMarkNoShow">;
|
|
3
|
+
/**
|
|
4
|
+
* `date` is today's date where the gym is (YYYY-MM-DD) and `timeZone` the gym's zone: the app
|
|
5
|
+
* passes them; which classes a coach may see is the host's (its role's today).
|
|
6
|
+
*/
|
|
7
|
+
export declare function ClassListScreen({ bookings, date, timeZone, }: {
|
|
8
|
+
bookings: Hooks;
|
|
9
|
+
date: string;
|
|
10
|
+
timeZone: string;
|
|
11
|
+
}): import("react").JSX.Element;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { classTime } from "@composable-os/pack-bookings/client";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { View } from "react-native";
|
|
5
|
+
import { Button } from "../native-base/button.js";
|
|
6
|
+
import { List } from "../native-base/list.js";
|
|
7
|
+
import { Row } from "../native-base/row.js";
|
|
8
|
+
import { Screen } from "../native-base/screen.js";
|
|
9
|
+
import { Text } from "../native-base/text.js";
|
|
10
|
+
const STATE_LABEL = {
|
|
11
|
+
booked: "Booked",
|
|
12
|
+
attended: "Came",
|
|
13
|
+
no_show: "Did not come",
|
|
14
|
+
waiting: "Waiting",
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* `date` is today's date where the gym is (YYYY-MM-DD) and `timeZone` the gym's zone: the app
|
|
18
|
+
* passes them; which classes a coach may see is the host's (its role's today).
|
|
19
|
+
*/
|
|
20
|
+
export function ClassListScreen({ bookings, date, timeZone, }) {
|
|
21
|
+
const day = bookings.useDay({ date, timeZone });
|
|
22
|
+
const [classId, setClassId] = useState(null);
|
|
23
|
+
if (classId) {
|
|
24
|
+
return _jsx(ClassRoster, { bookings: bookings, classId: classId, onBack: () => setClassId(null) });
|
|
25
|
+
}
|
|
26
|
+
return (_jsxs(Screen, { title: "Today's classes", children: [day.isPending ? (_jsx(Text, { tone: "muted", accessibilityRole: "progressbar", children: "Loading the classes\u2026" })) : null, day.error ? _jsx(Text, { accessibilityRole: "alert", children: "We could not load today's classes." }) : null, day.data ? (_jsx(List, { empty: "No classes today.", children: day.data.classes.map((klass) => (_jsx(Row, { title: klass.title ?? "Class", detail: [
|
|
27
|
+
classTime(klass),
|
|
28
|
+
klass.room,
|
|
29
|
+
`${klass.booked} booked of ${klass.places ?? "unlimited"}`,
|
|
30
|
+
klass.state === "cancelled" ? "Cancelled" : null,
|
|
31
|
+
]
|
|
32
|
+
.filter(Boolean)
|
|
33
|
+
.join(" · "), onPress: () => setClassId(klass.id) }, klass.id))) })) : null] }));
|
|
34
|
+
}
|
|
35
|
+
function ClassRoster({ bookings, classId, onBack, }) {
|
|
36
|
+
const list = bookings.useRoster({ classId });
|
|
37
|
+
const tick = bookings.useMarkAttended();
|
|
38
|
+
const untick = bookings.useUndoAttended();
|
|
39
|
+
const noShow = bookings.useMarkNoShow();
|
|
40
|
+
const [message, setMessage] = useState(null);
|
|
41
|
+
const say = async (done) => {
|
|
42
|
+
setMessage(null);
|
|
43
|
+
try {
|
|
44
|
+
setMessage((await done).message);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
setMessage("That did not work. Try again.");
|
|
48
|
+
}
|
|
49
|
+
await list.refetch?.();
|
|
50
|
+
};
|
|
51
|
+
const busy = tick.isPending || untick.isPending || noShow.isPending;
|
|
52
|
+
return (_jsxs(Screen, { title: list.data?.class.title ?? "Class list", children: [_jsx(Button, { label: "Back to today's classes", quiet: true, onPress: onBack }), list.isPending ? (_jsx(Text, { tone: "muted", accessibilityRole: "progressbar", children: "Loading the list\u2026" })) : null, list.error ? _jsx(Text, { accessibilityRole: "alert", children: "We could not load the list." }) : null, message ? _jsx(Text, { accessibilityRole: "alert", children: message }) : null, list.data ? (_jsxs(View, { children: [_jsxs(Text, { children: [classTime(list.data.class), " \u00B7 ", list.data.class.booked, " booked of", " ", list.data.class.places ?? "unlimited"] }), _jsx(List, { empty: "Nobody is booked yet.", children: list.data.bookings
|
|
53
|
+
// Cancelled and moved bookings are not on the list a coach ticks.
|
|
54
|
+
.filter((b) => b.state && b.state in STATE_LABEL)
|
|
55
|
+
.map((booking) => {
|
|
56
|
+
const name = booking.person?.name ?? "No name";
|
|
57
|
+
return (_jsxs(View, { children: [_jsx(Row, { title: name, detail: `${STATE_LABEL[booking.state ?? ""]}${booking.markedBy ? ` (${booking.markedBy})` : ""}${booking.healthNote ? " · Health note" : ""}` }), booking.state === "booked" || booking.state === "no_show" ? (_jsx(Button, { label: `Tick ${name}`, busy: busy, onPress: () => say(tick.mutateAsync({ bookingId: booking.id })) })) : null, booking.state === "booked" ? (_jsx(Button, { label: `${name} did not come`, quiet: true, busy: busy, onPress: () => say(noShow.mutateAsync({ bookingId: booking.id })) })) : null, booking.state === "attended" ? (_jsx(Button, { label: `Untick ${name}`, quiet: true, busy: busy, onPress: () => say(untick.mutateAsync({ bookingId: booking.id })) })) : null] }, booking.id));
|
|
58
|
+
}) })] })) : null] }));
|
|
59
|
+
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import { type AgreementsHooks } from "@composable-os/client";
|
|
1
2
|
import type { BookingsHooks } from "@composable-os/pack-bookings/client";
|
|
2
|
-
type Hooks = Pick<BookingsHooks, "useTimetable" | "useMyBookings" | "useBook" | "useCancel">;
|
|
3
|
-
|
|
3
|
+
type Hooks = Pick<BookingsHooks, "useTimetable" | "useMyBookings" | "useBook" | "useCancel" | "useFamily">;
|
|
4
|
+
/** The agreements hooks the inline step uses. */
|
|
5
|
+
export type TimetableAgreements = Pick<AgreementsHooks, "useDue" | "useAccept">;
|
|
6
|
+
export declare function TimetableScreen({ bookings, agreements, }: {
|
|
4
7
|
bookings: Hooks;
|
|
8
|
+
/** For what must be agreed to first, shown inline. Without it, the refusal is only named. */
|
|
9
|
+
agreements?: TimetableAgreements;
|
|
5
10
|
}): import("react").JSX.Element;
|
|
6
11
|
export {};
|
|
@@ -1,49 +1,121 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// The timetable in the gym's app (stage 31a, decision 9): book and cancel with the membership or
|
|
3
|
+
// pass a member already holds. Nothing is bought here: a member with nothing to spend is told so
|
|
4
|
+
// by the host, and buys on the website. Whether booking is open, the places left and whether a
|
|
5
|
+
// cancel is in time are the host's answers, shown as they come. A parent the gym linked to a child
|
|
6
|
+
// picks who they are booking for (ADR 0540); the child's own membership or pass pays.
|
|
7
|
+
//
|
|
8
|
+
// What must be agreed to first (stage 44) is the host's answer too: when "Book" is refused with
|
|
9
|
+
// it, the documents are shown in the class's place (the native-agree block's step), agreed to one
|
|
10
|
+
// by one, and "Book" is tried again.
|
|
11
|
+
import { purchaseErrorWords, withAgreements, } from "@composable-os/client";
|
|
2
12
|
import { bookingFor, classTime, placesLabel, refusalMessage, } from "@composable-os/pack-bookings/client";
|
|
3
13
|
import { useState } from "react";
|
|
4
|
-
import {
|
|
14
|
+
import { View } from "react-native";
|
|
15
|
+
import { AgreementStepModal } from "../native-agree/agreement-step.js";
|
|
5
16
|
import { Button } from "../native-base/button.js";
|
|
6
17
|
import { List } from "../native-base/list.js";
|
|
7
18
|
import { Row } from "../native-base/row.js";
|
|
8
19
|
import { Screen } from "../native-base/screen.js";
|
|
9
|
-
|
|
20
|
+
import { Text } from "../native-base/text.js";
|
|
21
|
+
export function TimetableScreen({ bookings, agreements, }) {
|
|
10
22
|
const timetable = bookings.useTimetable({});
|
|
11
|
-
const
|
|
23
|
+
const family = bookings.useFamily();
|
|
24
|
+
const people = family.data?.people ?? [];
|
|
25
|
+
const [personId, setPersonId] = useState(null);
|
|
26
|
+
const chosen = people.find((p) => p.personId === personId && !p.self);
|
|
27
|
+
const mine = bookings.useMyBookings(chosen ? { personId: chosen.personId } : {});
|
|
12
28
|
const [message, setMessage] = useState(null);
|
|
13
29
|
const done = (text) => {
|
|
14
30
|
setMessage(text);
|
|
15
31
|
timetable.refetch?.();
|
|
16
32
|
mine.refetch?.();
|
|
17
33
|
};
|
|
18
|
-
return (_jsxs(Screen, { title: "Timetable", children: [
|
|
34
|
+
return (_jsxs(Screen, { title: "Timetable", children: [people.length > 1 ? (_jsxs(View, { children: [_jsx(Text, { children: "Booking for" }), people.map((person) => (_jsx(Button, { label: person.self ? "Me" : person.name, quiet: (chosen?.personId ?? null) !== (person.self ? null : person.personId), onPress: () => {
|
|
35
|
+
setPersonId(person.self ? null : person.personId);
|
|
36
|
+
setMessage(null);
|
|
37
|
+
} }, person.personId)))] })) : null, message ? _jsx(Text, { accessibilityRole: "alert", children: message }) : null, timetable.isPending ? (_jsx(Text, { tone: "muted", accessibilityRole: "progressbar", children: "Loading the timetable\u2026" })) : null, timetable.error ? (_jsx(Text, { accessibilityRole: "alert", children: "We could not load the timetable." })) : null, timetable.data ? (_jsx(List, { empty: "No classes in these days.", children: timetable.data.classes.map((klass) => (_jsx(ClassItem
|
|
38
|
+
// One item per person and class: a cancel started for one person is never confirmed
|
|
39
|
+
// for another after "Booking for" changes (as the web timetable).
|
|
40
|
+
, { klass: klass, booking: bookingFor(klass.id, mine.data?.bookings), forPerson: chosen ? { id: chosen.personId, name: chosen.name } : null, bookings: bookings, agreements: agreements, onDone: done }, `${chosen?.personId ?? "self"}:${klass.id}`))) })) : null] }));
|
|
19
41
|
}
|
|
20
|
-
|
|
42
|
+
/** When a cancel fails with no answer to show (offline, the host down): it can be tried again. */
|
|
43
|
+
const CANCEL_FAILED = "We could not cancel that just now. Check the connection and try again.";
|
|
44
|
+
function ClassItem({ klass, booking, forPerson, bookings, agreements, onDone, }) {
|
|
21
45
|
const book = bookings.useBook();
|
|
22
46
|
const cancel = bookings.useCancel();
|
|
23
47
|
const [preview, setPreview] = useState(null);
|
|
48
|
+
// What the host said must be agreed to first.
|
|
49
|
+
const [due, setDue] = useState(null);
|
|
24
50
|
const name = klass.title ?? "Class";
|
|
25
|
-
|
|
51
|
+
/** Books; `said` is what agreeing just now told them (where the copy went), said first. */
|
|
52
|
+
async function bookIt(said = null) {
|
|
53
|
+
const first = said ? `${said} ` : "";
|
|
54
|
+
let outcome;
|
|
55
|
+
try {
|
|
56
|
+
outcome = await withAgreements(() => book.mutateAsync({
|
|
57
|
+
classId: klass.id,
|
|
58
|
+
...(forPerson ? { forPersonId: forPerson.id } : {}),
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
onDone(`${first}${purchaseErrorWords(error) ?? "We could not book that just now. Try again soon."}`);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (outcome.kind === "due") {
|
|
66
|
+
if (agreements)
|
|
67
|
+
setDue(outcome.documents);
|
|
68
|
+
else {
|
|
69
|
+
onDone(`Something must be agreed to first: ${outcome.documents.map((d) => d.title).join(", ")}.`);
|
|
70
|
+
}
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (outcome.kind === "minor_payer") {
|
|
74
|
+
onDone(outcome.message);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const result = outcome.value;
|
|
78
|
+
onDone(first +
|
|
79
|
+
(result.result === "booked"
|
|
80
|
+
? `Booked${forPerson ? ` for ${forPerson.name}` : ""}: ${name}, ${classTime(klass)}.`
|
|
81
|
+
: result.result === "waiting"
|
|
82
|
+
? `${name}: ${result.message}`
|
|
83
|
+
: refusalMessage(result, klass.timeZone)));
|
|
84
|
+
}
|
|
85
|
+
return (_jsxs(View, { children: [due && agreements ? (_jsx(AgreementStepModal, { agreements: agreements, documents: due, continueLabel: "Agree and book", onCancel: () => setDue(null), onAgreed: (said) => {
|
|
86
|
+
setDue(null);
|
|
87
|
+
void bookIt(said);
|
|
88
|
+
} })) : null, _jsx(Row, { title: name, detail: [classTime(klass), klass.coach?.name, placesLabel(klass.places)]
|
|
26
89
|
.filter(Boolean)
|
|
27
90
|
.join(" · ") }), booking && preview ? (_jsxs(View, { children: [_jsx(Text, { children: preview.message }), _jsx(Button, { label: "Confirm cancel", busy: cancel.isPending, onPress: async () => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
91
|
+
let result;
|
|
92
|
+
try {
|
|
93
|
+
result = await cancel.mutateAsync({
|
|
94
|
+
bookingId: booking.id,
|
|
95
|
+
confirm: true,
|
|
96
|
+
expect: preview.state,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
onDone(CANCEL_FAILED);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
33
103
|
setPreview(null);
|
|
34
104
|
onDone(result.result === "refused"
|
|
35
105
|
? refusalMessage(result, klass.timeZone)
|
|
36
106
|
: `${name}: ${result.message}`);
|
|
37
107
|
} }), _jsx(Button, { label: "Keep it", quiet: true, onPress: () => setPreview(null) })] })) : booking ? (_jsx(Button, { label: "Cancel", quiet: true, busy: cancel.isPending, onPress: async () => {
|
|
38
|
-
|
|
108
|
+
let asked;
|
|
109
|
+
try {
|
|
110
|
+
asked = await cancel.mutateAsync({ bookingId: booking.id });
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
onDone(CANCEL_FAILED);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
39
116
|
if (asked.result === "refused")
|
|
40
117
|
onDone(refusalMessage(asked, klass.timeZone));
|
|
41
118
|
else
|
|
42
119
|
setPreview({ state: asked.state, message: asked.message });
|
|
43
|
-
} })) : (_jsx(Button, { label: "Book", busy: book.isPending, onPress:
|
|
44
|
-
const result = await book.mutateAsync({ classId: klass.id });
|
|
45
|
-
onDone(result.result === "booked"
|
|
46
|
-
? `Booked: ${name}, ${classTime(klass)}.`
|
|
47
|
-
: refusalMessage(result, klass.timeZone));
|
|
48
|
-
} }))] }));
|
|
120
|
+
} })) : (_jsx(Button, { label: "Book", busy: book.isPending, onPress: () => void bookIt() }))] }));
|
|
49
121
|
}
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
import { type AgreementsHooks } from "@composable-os/client";
|
|
1
2
|
import type { BookingsHooks } from "@composable-os/pack-bookings/client";
|
|
2
|
-
|
|
3
|
-
export
|
|
3
|
+
/** The agreements hooks the inline step uses. */
|
|
4
|
+
export type TimetableAgreements = Pick<AgreementsHooks, "useDue" | "useAccept">;
|
|
5
|
+
type Hooks = Pick<BookingsHooks, "useTimetable" | "useMyBookings" | "useBook" | "useCancel" | "useFamily" | "useBuy">;
|
|
6
|
+
export declare function Timetable({ bookings, agreements, from, to, payReturnUrl, }: {
|
|
4
7
|
bookings: Hooks;
|
|
8
|
+
/** For what must be agreed to first, shown inline. Without it, the refusal is only named. */
|
|
9
|
+
agreements?: TimetableAgreements;
|
|
5
10
|
/** The first moment shown (ISO 8601); the host's default is now. */
|
|
6
11
|
from?: string;
|
|
7
12
|
to?: string;
|
|
13
|
+
/** Where the payment provider sends a member back after paying for a class (a drop-in). */
|
|
14
|
+
payReturnUrl?: string;
|
|
8
15
|
}): import("react").JSX.Element;
|
|
9
16
|
export {};
|