@composable-os/pack-bookings 0.1.0-beta.10 → 0.1.0-beta.11
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/blocks/bookings-class-list/class-list.d.ts +7 -0
- package/dist/blocks/bookings-class-list/class-list.js +37 -0
- package/dist/blocks/bookings-desk/desk.js +4 -0
- package/dist/blocks/bookings-drop-in/drop-in.d.ts +22 -0
- package/dist/blocks/bookings-drop-in/drop-in.js +54 -0
- package/dist/blocks/bookings-native-timetable/timetable-screen.d.ts +1 -1
- package/dist/blocks/bookings-native-timetable/timetable-screen.js +18 -6
- package/dist/blocks/bookings-timetable/timetable.d.ts +4 -2
- package/dist/blocks/bookings-timetable/timetable.js +39 -8
- package/dist/client/index.d.ts +1210 -162
- package/dist/client/index.js +74 -2
- package/dist/index.d.ts +555 -12
- package/dist/index.js +338 -34
- package/dist/tools.d.ts +338 -0
- package/dist/tools.js +887 -62
- package/package.json +3 -3
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BookingsHooks } from "@composable-os/pack-bookings/client";
|
|
2
|
+
type Hooks = Pick<BookingsHooks, "useRoster" | "useMarkAttended" | "useUndoAttended">;
|
|
3
|
+
export declare function ClassList({ bookings, classId }: {
|
|
4
|
+
bookings: Hooks;
|
|
5
|
+
classId: string;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
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 { Button } from "../ui-button/button.js";
|
|
5
|
+
const STATE_LABEL = {
|
|
6
|
+
booked: "Booked",
|
|
7
|
+
attended: "Came",
|
|
8
|
+
no_show: "Did not come",
|
|
9
|
+
waiting: "Waiting",
|
|
10
|
+
};
|
|
11
|
+
export function ClassList({ bookings, classId }) {
|
|
12
|
+
const list = bookings.useRoster({ classId });
|
|
13
|
+
const tick = bookings.useMarkAttended();
|
|
14
|
+
const untick = bookings.useUndoAttended();
|
|
15
|
+
const [message, setMessage] = useState(null);
|
|
16
|
+
if (list.isPending)
|
|
17
|
+
return _jsx("p", { "aria-busy": "true", children: "Loading the list\u2026" });
|
|
18
|
+
if (list.error || !list.data)
|
|
19
|
+
return _jsx("p", { role: "alert", children: "We could not load the list." });
|
|
20
|
+
const { class: klass } = list.data;
|
|
21
|
+
// Cancelled and moved bookings are not on the list a coach ticks.
|
|
22
|
+
const shown = list.data.bookings.filter((b) => b.state && b.state in STATE_LABEL);
|
|
23
|
+
const say = async (done) => {
|
|
24
|
+
setMessage(null);
|
|
25
|
+
try {
|
|
26
|
+
setMessage((await done).message);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
setMessage("That did not work. Try again.");
|
|
30
|
+
}
|
|
31
|
+
await list.refetch?.();
|
|
32
|
+
};
|
|
33
|
+
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) => {
|
|
34
|
+
const name = booking.person?.name ?? "No name";
|
|
35
|
+
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.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));
|
|
36
|
+
}) }), message ? _jsx("p", { role: "status", children: message }) : null] }));
|
|
37
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { BookingsHooks } from "@composable-os/pack-bookings/client";
|
|
2
|
+
type Hooks = Pick<BookingsHooks, "useTimetable" | "useBuy">;
|
|
3
|
+
/** What the buyer is shown before they leave for the provider's page. */
|
|
4
|
+
export interface StartedDropIn {
|
|
5
|
+
orderId: string;
|
|
6
|
+
bookingId: string;
|
|
7
|
+
token: string | null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* `signedIn`: the buyer is a signed-in member (no email asked). `returnUrl`: where the provider
|
|
11
|
+
* sends them back, on one of the deployment's allowed sites; coming back books nothing, the
|
|
12
|
+
* verified payment does. `onStarted` is called before they leave (keep a guest's token).
|
|
13
|
+
*/
|
|
14
|
+
export declare function DropIn({ bookings, signedIn, returnUrl, onStarted, from, to, }: {
|
|
15
|
+
bookings: Hooks;
|
|
16
|
+
signedIn: boolean;
|
|
17
|
+
returnUrl: string;
|
|
18
|
+
onStarted?: (started: StartedDropIn) => void;
|
|
19
|
+
from?: string;
|
|
20
|
+
to?: string;
|
|
21
|
+
}): import("react").JSX.Element;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { classTime, formatAmount, placesLabel, refusalMessage, } from "@composable-os/pack-bookings/client";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Button } from "../ui-button/button.js";
|
|
5
|
+
import { Input } from "../ui-input/input.js";
|
|
6
|
+
import { Label } from "../ui-label/label.js";
|
|
7
|
+
/**
|
|
8
|
+
* `signedIn`: the buyer is a signed-in member (no email asked). `returnUrl`: where the provider
|
|
9
|
+
* sends them back, on one of the deployment's allowed sites; coming back books nothing, the
|
|
10
|
+
* verified payment does. `onStarted` is called before they leave (keep a guest's token).
|
|
11
|
+
*/
|
|
12
|
+
export function DropIn({ bookings, signedIn, returnUrl, onStarted, from, to, }) {
|
|
13
|
+
const timetable = bookings.useTimetable({ ...(from ? { from } : {}), ...(to ? { to } : {}) });
|
|
14
|
+
const [chosen, setChosen] = useState(null);
|
|
15
|
+
if (timetable.isPending)
|
|
16
|
+
return _jsx("p", { "aria-busy": "true", children: "Loading the timetable\u2026" });
|
|
17
|
+
if (timetable.error || !timetable.data) {
|
|
18
|
+
return _jsx("p", { role: "alert", children: "We could not load the timetable. Try again soon." });
|
|
19
|
+
}
|
|
20
|
+
if (chosen) {
|
|
21
|
+
return (_jsx(PayForm, { klass: chosen, bookings: bookings, signedIn: signedIn, returnUrl: returnUrl, onStarted: onStarted, onBack: () => setChosen(null) }));
|
|
22
|
+
}
|
|
23
|
+
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)]
|
|
24
|
+
.filter(Boolean)
|
|
25
|
+
.join(" · ") })] }), _jsxs(Button, { variant: "outline", onClick: () => setChosen(klass), children: ["Pay for ", klass.title ?? "this class"] })] }, klass.id))) })] }));
|
|
26
|
+
}
|
|
27
|
+
function PayForm({ klass, bookings, signedIn, returnUrl, onStarted, onBack, }) {
|
|
28
|
+
const buy = bookings.useBuy();
|
|
29
|
+
const [email, setEmail] = useState("");
|
|
30
|
+
const [message, setMessage] = useState(null);
|
|
31
|
+
const name = klass.title ?? "Class";
|
|
32
|
+
const busy = buy.start.isPending || buy.checkout.isPending;
|
|
33
|
+
async function submit(e) {
|
|
34
|
+
e.preventDefault();
|
|
35
|
+
setMessage(null);
|
|
36
|
+
const held = await buy.start.mutateAsync({
|
|
37
|
+
classId: klass.id,
|
|
38
|
+
...(signedIn ? {} : { email }),
|
|
39
|
+
});
|
|
40
|
+
if (held.result === "refused") {
|
|
41
|
+
setMessage(refusalMessage(held, klass.timeZone));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
onStarted?.({ orderId: held.orderId, bookingId: held.bookingId, token: held.token });
|
|
45
|
+
setMessage(`Your place is held. ${formatAmount(held.total, held.currency)} to pay.`);
|
|
46
|
+
const page = await buy.checkout.mutateAsync({
|
|
47
|
+
id: held.orderId,
|
|
48
|
+
...(held.token ? { token: held.token } : {}),
|
|
49
|
+
returnUrl,
|
|
50
|
+
});
|
|
51
|
+
window.location.assign(page.url);
|
|
52
|
+
}
|
|
53
|
+
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) })] })), message ? _jsx("p", { role: "status", children: message }) : null, buy.start.error || buy.checkout.error ? (_jsx("p", { role: "alert", children: "We could not start the payment. Try again soon." })) : 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: onBack, children: "Back" })] })] }));
|
|
54
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BookingsHooks } from "@composable-os/pack-bookings/client";
|
|
2
|
-
type Hooks = Pick<BookingsHooks, "useTimetable" | "useMyBookings" | "useBook" | "useCancel">;
|
|
2
|
+
type Hooks = Pick<BookingsHooks, "useTimetable" | "useMyBookings" | "useBook" | "useCancel" | "useFamily">;
|
|
3
3
|
export declare function TimetableScreen({ bookings }: {
|
|
4
4
|
bookings: Hooks;
|
|
5
5
|
}): import("react").JSX.Element;
|
|
@@ -8,16 +8,23 @@ import { Row } from "../native-base/row.js";
|
|
|
8
8
|
import { Screen } from "../native-base/screen.js";
|
|
9
9
|
export function TimetableScreen({ bookings }) {
|
|
10
10
|
const timetable = bookings.useTimetable({});
|
|
11
|
-
const
|
|
11
|
+
const family = bookings.useFamily();
|
|
12
|
+
const people = family.data?.people ?? [];
|
|
13
|
+
const [personId, setPersonId] = useState(null);
|
|
14
|
+
const chosen = people.find((p) => p.personId === personId && !p.self);
|
|
15
|
+
const mine = bookings.useMyBookings(chosen ? { personId: chosen.personId } : {});
|
|
12
16
|
const [message, setMessage] = useState(null);
|
|
13
17
|
const done = (text) => {
|
|
14
18
|
setMessage(text);
|
|
15
19
|
timetable.refetch?.();
|
|
16
20
|
mine.refetch?.();
|
|
17
21
|
};
|
|
18
|
-
return (_jsxs(Screen, { title: "Timetable", children: [
|
|
22
|
+
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: () => {
|
|
23
|
+
setPersonId(person.self ? null : person.personId);
|
|
24
|
+
setMessage(null);
|
|
25
|
+
} }, person.personId)))] })) : null, message ? _jsx(Text, { accessibilityRole: "alert", children: message }) : null, timetable.isPending ? (_jsx(Text, { 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, { klass: klass, booking: bookingFor(klass.id, mine.data?.bookings), forPerson: chosen ? { id: chosen.personId, name: chosen.name } : null, bookings: bookings, onDone: done }, klass.id))) })) : null] }));
|
|
19
26
|
}
|
|
20
|
-
function ClassItem({ klass, booking, bookings, onDone, }) {
|
|
27
|
+
function ClassItem({ klass, booking, forPerson, bookings, onDone, }) {
|
|
21
28
|
const book = bookings.useBook();
|
|
22
29
|
const cancel = bookings.useCancel();
|
|
23
30
|
const [preview, setPreview] = useState(null);
|
|
@@ -41,9 +48,14 @@ function ClassItem({ klass, booking, bookings, onDone, }) {
|
|
|
41
48
|
else
|
|
42
49
|
setPreview({ state: asked.state, message: asked.message });
|
|
43
50
|
} })) : (_jsx(Button, { label: "Book", busy: book.isPending, onPress: async () => {
|
|
44
|
-
const result = await book.mutateAsync({
|
|
51
|
+
const result = await book.mutateAsync({
|
|
52
|
+
classId: klass.id,
|
|
53
|
+
...(forPerson ? { forPersonId: forPerson.id } : {}),
|
|
54
|
+
});
|
|
45
55
|
onDone(result.result === "booked"
|
|
46
|
-
? `Booked: ${name}, ${classTime(klass)}.`
|
|
47
|
-
:
|
|
56
|
+
? `Booked${forPerson ? ` for ${forPerson.name}` : ""}: ${name}, ${classTime(klass)}.`
|
|
57
|
+
: result.result === "waiting"
|
|
58
|
+
? `${name}: ${result.message}`
|
|
59
|
+
: refusalMessage(result, klass.timeZone));
|
|
48
60
|
} }))] }));
|
|
49
61
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { BookingsHooks } from "@composable-os/pack-bookings/client";
|
|
2
|
-
type Hooks = Pick<BookingsHooks, "useTimetable" | "useMyBookings" | "useBook" | "useCancel">;
|
|
3
|
-
export declare function Timetable({ bookings, from, to, }: {
|
|
2
|
+
type Hooks = Pick<BookingsHooks, "useTimetable" | "useMyBookings" | "useBook" | "useCancel" | "useFamily" | "useBuy">;
|
|
3
|
+
export declare function Timetable({ bookings, from, to, payReturnUrl, }: {
|
|
4
4
|
bookings: Hooks;
|
|
5
5
|
/** The first moment shown (ISO 8601); the host's default is now. */
|
|
6
6
|
from?: string;
|
|
7
7
|
to?: string;
|
|
8
|
+
/** Where the payment provider sends a member back after paying for a class (a drop-in). */
|
|
9
|
+
payReturnUrl?: string;
|
|
8
10
|
}): import("react").JSX.Element;
|
|
9
11
|
export {};
|
|
@@ -2,9 +2,14 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { bookingFor, classTime, placesLabel, refusalMessage, } from "@composable-os/pack-bookings/client";
|
|
3
3
|
import { useState } from "react";
|
|
4
4
|
import { Button } from "../ui-button/button.js";
|
|
5
|
-
export function Timetable({ bookings, from, to, }) {
|
|
5
|
+
export function Timetable({ bookings, from, to, payReturnUrl, }) {
|
|
6
6
|
const timetable = bookings.useTimetable({ ...(from ? { from } : {}), ...(to ? { to } : {}) });
|
|
7
|
-
const
|
|
7
|
+
const family = bookings.useFamily();
|
|
8
|
+
const people = family.data?.people ?? [];
|
|
9
|
+
// Whose bookings are shown and made: the member's own unless they pick a child.
|
|
10
|
+
const [personId, setPersonId] = useState(null);
|
|
11
|
+
const chosen = people.find((p) => p.personId === personId && !p.self);
|
|
12
|
+
const mine = bookings.useMyBookings(chosen ? { personId: chosen.personId } : {});
|
|
8
13
|
const [message, setMessage] = useState(null);
|
|
9
14
|
if (timetable.isPending)
|
|
10
15
|
return _jsx("p", { "aria-busy": "true", children: "Loading the timetable\u2026" });
|
|
@@ -15,14 +20,20 @@ export function Timetable({ bookings, from, to, }) {
|
|
|
15
20
|
timetable.refetch?.();
|
|
16
21
|
mine.refetch?.();
|
|
17
22
|
};
|
|
18
|
-
return (_jsxs("section", { className: "grid gap-4", "aria-label": "Timetable", children: [
|
|
23
|
+
return (_jsxs("section", { className: "grid gap-4", "aria-label": "Timetable", children: [people.length > 1 ? (_jsxs("label", { className: "grid gap-1 text-sm", children: ["Booking for", _jsx("select", { className: "rounded-md border p-2", value: chosen?.personId ?? "", onChange: (event) => {
|
|
24
|
+
setPersonId(event.target.value || null);
|
|
25
|
+
setMessage(null);
|
|
26
|
+
}, children: people.map((person) => (_jsx("option", { value: person.self ? "" : person.personId, children: person.self ? "Me" : person.name }, person.personId))) })] })) : null, message ? _jsx("p", { role: "status", children: message }) : null, 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) => (_jsx(ClassRow, { klass: klass, booking: bookingFor(klass.id, mine.data?.bookings), forPerson: chosen ? { id: chosen.personId, name: chosen.name } : null, bookings: bookings, payReturnUrl: payReturnUrl, onDone: (text) => {
|
|
19
27
|
setMessage(text);
|
|
20
28
|
refresh();
|
|
21
29
|
} }, klass.id))) })] }));
|
|
22
30
|
}
|
|
23
|
-
function ClassRow({ klass, booking, bookings, onDone, }) {
|
|
31
|
+
function ClassRow({ klass, booking, forPerson, bookings, onDone, payReturnUrl, }) {
|
|
24
32
|
const book = bookings.useBook();
|
|
25
33
|
const cancel = bookings.useCancel();
|
|
34
|
+
const buy = bookings.useBuy();
|
|
35
|
+
// The host said nothing they hold can pay for it: they may pay for this one class.
|
|
36
|
+
const [canPay, setCanPay] = useState(false);
|
|
26
37
|
const [preview, setPreview] = useState(null);
|
|
27
38
|
const name = klass.title ?? "Class";
|
|
28
39
|
return (_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: name }), _jsx("span", { children: classTime(klass) }), _jsx("span", { className: "text-muted-foreground text-sm", children: [klass.coach?.name, klass.room?.name, placesLabel(klass.places)]
|
|
@@ -43,10 +54,30 @@ function ClassRow({ klass, booking, bookings, onDone, }) {
|
|
|
43
54
|
onDone(refusalMessage(asked, klass.timeZone));
|
|
44
55
|
else
|
|
45
56
|
setPreview({ state: asked.state, message: asked.message });
|
|
46
|
-
}, children: ["Cancel ", name] }))) : (_jsxs(Button, { disabled:
|
|
47
|
-
const
|
|
57
|
+
}, children: ["Cancel ", name] }))) : canPay && payReturnUrl ? (_jsxs(Button, { disabled: buy.start.isPending || buy.checkout.isPending, onClick: async () => {
|
|
58
|
+
const held = await buy.start.mutateAsync({
|
|
59
|
+
classId: klass.id,
|
|
60
|
+
...(forPerson ? { forPersonId: forPerson.id } : {}),
|
|
61
|
+
});
|
|
62
|
+
if (held.result === "refused") {
|
|
63
|
+
onDone(refusalMessage(held, klass.timeZone));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const page = await buy.checkout.mutateAsync({
|
|
67
|
+
id: held.orderId,
|
|
68
|
+
returnUrl: payReturnUrl,
|
|
69
|
+
});
|
|
70
|
+
window.location.assign(page.url);
|
|
71
|
+
}, children: ["Pay for ", name] })) : (_jsxs(Button, { disabled: book.isPending, onClick: async () => {
|
|
72
|
+
const done = await book.mutateAsync({
|
|
73
|
+
classId: klass.id,
|
|
74
|
+
...(forPerson ? { forPersonId: forPerson.id } : {}),
|
|
75
|
+
});
|
|
76
|
+
setCanPay(done.result === "refused" && done.reason === "no_use");
|
|
48
77
|
onDone(done.result === "booked"
|
|
49
|
-
? `Booked: ${name}, ${classTime(klass)}.`
|
|
50
|
-
:
|
|
78
|
+
? `Booked${forPerson ? ` for ${forPerson.name}` : ""}: ${name}, ${classTime(klass)}.`
|
|
79
|
+
: done.result === "waiting"
|
|
80
|
+
? `${name}: ${done.message}`
|
|
81
|
+
: refusalMessage(done, klass.timeZone));
|
|
51
82
|
}, children: ["Book ", name] }))] }));
|
|
52
83
|
}
|