@composable-os/pack-bookings 0.0.0-stage → 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/LICENSE +109 -0
- 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.d.ts +10 -0
- package/dist/blocks/bookings-desk/desk.js +62 -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 +6 -0
- package/dist/blocks/bookings-native-timetable/timetable-screen.js +61 -0
- package/dist/blocks/bookings-timetable/timetable.d.ts +11 -0
- package/dist/blocks/bookings-timetable/timetable.js +83 -0
- package/dist/client/index.d.ts +2039 -0
- package/dist/client/index.js +209 -0
- package/dist/index.d.ts +1745 -0
- package/dist/index.js +974 -0
- package/dist/tools.d.ts +691 -0
- package/dist/tools.js +1623 -0
- package/package.json +36 -4
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
2
|
+
|
|
3
|
+
> This licence covers the repository except the directories listed in NOTICE. In particular, the
|
|
4
|
+
> assistant packages `packages/agent-*` (agent-core, agent-a2ui, agent-voice, agent-plugins) are
|
|
5
|
+
> licensed under the MIT License; see the LICENSE file in each of those directories (ADR 0350).
|
|
6
|
+
|
|
7
|
+
## Abbreviation
|
|
8
|
+
|
|
9
|
+
FSL-1.1-ALv2
|
|
10
|
+
|
|
11
|
+
## Notice
|
|
12
|
+
|
|
13
|
+
Copyright 2026 Tim O'Connell
|
|
14
|
+
|
|
15
|
+
## Terms and Conditions
|
|
16
|
+
|
|
17
|
+
### Licensor ("We")
|
|
18
|
+
|
|
19
|
+
The party offering the Software under these Terms and Conditions.
|
|
20
|
+
|
|
21
|
+
### The Software
|
|
22
|
+
|
|
23
|
+
The "Software" is each version of the software that we make available under
|
|
24
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
25
|
+
Conditions with the Software.
|
|
26
|
+
|
|
27
|
+
### License Grant
|
|
28
|
+
|
|
29
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
30
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
31
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
32
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
33
|
+
|
|
34
|
+
### Permitted Purpose
|
|
35
|
+
|
|
36
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
37
|
+
means making the Software available to others in a commercial product or
|
|
38
|
+
service that:
|
|
39
|
+
|
|
40
|
+
1. substitutes for the Software;
|
|
41
|
+
|
|
42
|
+
2. substitutes for any other product or service we offer using the Software
|
|
43
|
+
that exists as of the date we make the Software available; or
|
|
44
|
+
|
|
45
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
46
|
+
|
|
47
|
+
Permitted Purposes specifically include using the Software:
|
|
48
|
+
|
|
49
|
+
1. for your internal use and access;
|
|
50
|
+
|
|
51
|
+
2. for non-commercial education;
|
|
52
|
+
|
|
53
|
+
3. for non-commercial research; and
|
|
54
|
+
|
|
55
|
+
4. in connection with professional services that you provide to a licensee
|
|
56
|
+
using the Software in accordance with these Terms and Conditions.
|
|
57
|
+
|
|
58
|
+
### Patents
|
|
59
|
+
|
|
60
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
61
|
+
patents, the license grant above includes a license under our patents. If you
|
|
62
|
+
make a claim against any party that the Software infringes or contributes to
|
|
63
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
64
|
+
immediately.
|
|
65
|
+
|
|
66
|
+
### Redistribution
|
|
67
|
+
|
|
68
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
69
|
+
the Software.
|
|
70
|
+
|
|
71
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
72
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
73
|
+
remove any copyright notices provided in or with the Software.
|
|
74
|
+
|
|
75
|
+
### Disclaimer
|
|
76
|
+
|
|
77
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
78
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
79
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
80
|
+
|
|
81
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
82
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
83
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
84
|
+
|
|
85
|
+
### Trademarks
|
|
86
|
+
|
|
87
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
88
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
89
|
+
trademarks, trade names, service marks or product names.
|
|
90
|
+
|
|
91
|
+
## Grant of Future License
|
|
92
|
+
|
|
93
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
94
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
95
|
+
the date we make the Software available. On or after that date, you may use the
|
|
96
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
97
|
+
will apply:
|
|
98
|
+
|
|
99
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
100
|
+
this file except in compliance with the License.
|
|
101
|
+
|
|
102
|
+
You may obtain a copy of the License at
|
|
103
|
+
|
|
104
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
105
|
+
|
|
106
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
107
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
108
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
109
|
+
specific language governing permissions and limitations under the License.
|
|
@@ -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,10 @@
|
|
|
1
|
+
import type { BookingsHooks } from "@composable-os/pack-bookings/client";
|
|
2
|
+
type Hooks = Pick<BookingsHooks, "useDay" | "useBookFor" | "useFindPeople">;
|
|
3
|
+
export declare function Desk({ bookings, date, timeZone, }: {
|
|
4
|
+
bookings: Hooks;
|
|
5
|
+
/** The local date shown, YYYY-MM-DD. */
|
|
6
|
+
date: string;
|
|
7
|
+
/** The gym's zone, e.g. Australia/Sydney. */
|
|
8
|
+
timeZone: string;
|
|
9
|
+
}): import("react").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } 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
|
+
import { Input } from "../ui-input/input.js";
|
|
6
|
+
import { Label } from "../ui-label/label.js";
|
|
7
|
+
export function Desk({ bookings, date, timeZone, }) {
|
|
8
|
+
const day = bookings.useDay({ date, timeZone });
|
|
9
|
+
const bookFor = bookings.useBookFor();
|
|
10
|
+
const [classId, setClassId] = useState("");
|
|
11
|
+
const [query, setQuery] = useState("");
|
|
12
|
+
const [personId, setPersonId] = useState(null);
|
|
13
|
+
const [givenName, setGivenName] = useState("");
|
|
14
|
+
const [familyName, setFamilyName] = useState("");
|
|
15
|
+
const [paidAtDesk, setPaidAtDesk] = useState(true);
|
|
16
|
+
const [message, setMessage] = useState(null);
|
|
17
|
+
const [matches, setMatches] = useState([]);
|
|
18
|
+
const found = bookings.useFindPeople({ query });
|
|
19
|
+
if (day.isPending)
|
|
20
|
+
return _jsx("p", { "aria-busy": "true", children: "Loading the day\u2026" });
|
|
21
|
+
if (day.error || !day.data)
|
|
22
|
+
return _jsx("p", { role: "alert", children: "We could not load the day." });
|
|
23
|
+
// Only a scheduled class can be booked; the host refuses the others anyway.
|
|
24
|
+
const open = day.data.classes.filter((klass) => klass.state === "scheduled");
|
|
25
|
+
const submit = async (confirmNew = false, chosen = personId) => {
|
|
26
|
+
setMessage(null);
|
|
27
|
+
try {
|
|
28
|
+
const done = await bookFor.mutateAsync({
|
|
29
|
+
classId,
|
|
30
|
+
...(chosen
|
|
31
|
+
? { personId: chosen }
|
|
32
|
+
: { newPerson: { givenName, ...(familyName ? { familyName } : {}) }, confirmNew }),
|
|
33
|
+
paidAtDesk,
|
|
34
|
+
});
|
|
35
|
+
if (done.result === "booked") {
|
|
36
|
+
setMessage("Booked in.");
|
|
37
|
+
setMatches([]);
|
|
38
|
+
setGivenName("");
|
|
39
|
+
setFamilyName("");
|
|
40
|
+
setPersonId(null);
|
|
41
|
+
setQuery("");
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (done.result === "waiting") {
|
|
45
|
+
setMessage(done.message);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
setMatches(done.people ?? []);
|
|
49
|
+
setMessage(done.message);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
setMessage("That did not work. Try again, or check the class and the person.");
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
return (_jsxs("section", { className: "grid gap-4", "aria-label": "Front desk", children: [_jsx("ul", { className: "grid gap-2", children: day.data.classes.map((klass) => (_jsxs("li", { className: "flex justify-between gap-4 rounded-md border p-2", children: [_jsxs("span", { children: [klass.title ?? "Class", " \u00B7 ", classTime(klass), klass.staffOnly ? " · booked by staff" : ""] }), _jsxs("span", { children: [klass.booked, " booked", klass.state === "scheduled" ? "" : ` · ${klass.state}`] })] }, klass.id))) }), _jsxs("form", { className: "grid gap-3", "aria-label": "Book someone in", onSubmit: async (event) => {
|
|
56
|
+
event.preventDefault();
|
|
57
|
+
await submit();
|
|
58
|
+
}, children: [_jsx(Label, { htmlFor: "desk-class", children: "Class" }), _jsxs("select", { id: "desk-class", value: classId, onChange: (event) => setClassId(event.target.value), required: true, children: [_jsx("option", { value: "", children: "Choose a class" }), open.map((klass) => (_jsxs("option", { value: klass.id, children: [klass.title ?? "Class", " \u00B7 ", classTime(klass)] }, klass.id)))] }), _jsx(Label, { htmlFor: "desk-find", children: "Find someone on file" }), _jsx(Input, { id: "desk-find", value: query, onChange: (event) => {
|
|
59
|
+
setQuery(event.target.value);
|
|
60
|
+
setPersonId(null);
|
|
61
|
+
} }), found.data?.people.length ? (_jsx("ul", { className: "grid gap-1", "aria-label": "People on file", children: found.data.people.map((person) => (_jsx("li", { children: _jsxs("label", { className: "flex items-center gap-2", children: [_jsx("input", { type: "radio", name: "desk-person", checked: personId === person.id, onChange: () => setPersonId(person.id) }), person.name ?? "No name", person.email ? ` · ${person.email}` : ""] }) }, person.id))) })) : null, personId ? null : (_jsxs(_Fragment, { children: [_jsx(Label, { htmlFor: "desk-given", children: "Given name (a walk-in)" }), _jsx(Input, { id: "desk-given", value: givenName, onChange: (event) => setGivenName(event.target.value), required: true }), _jsx(Label, { htmlFor: "desk-family", children: "Family name" }), _jsx(Input, { id: "desk-family", value: familyName, onChange: (event) => setFamilyName(event.target.value) })] })), _jsxs("label", { className: "flex items-center gap-2", children: [_jsx("input", { type: "checkbox", checked: paidAtDesk, onChange: (event) => setPaidAtDesk(event.target.checked) }), "Paid at the desk (spends no membership or pass)"] }), _jsx(Button, { type: "submit", disabled: bookFor.isPending || !classId, children: personId ? "Book them in" : "Book walk-in" }), message ? _jsx("p", { role: "status", children: message }) : null, matches.length ? (_jsxs("section", { className: "grid gap-2", "aria-label": "Already on file", children: [matches.map((person) => (_jsxs(Button, { variant: "outline", type: "button", onClick: () => submit(false, person.id), children: ["Book ", person.name] }, person.id))), _jsx(Button, { variant: "ghost", type: "button", onClick: () => submit(true, null), children: "Someone new: book anyway" })] })) : null] })] }));
|
|
62
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { BookingsHooks } from "@composable-os/pack-bookings/client";
|
|
2
|
+
type Hooks = Pick<BookingsHooks, "useTimetable" | "useMyBookings" | "useBook" | "useCancel" | "useFamily">;
|
|
3
|
+
export declare function TimetableScreen({ bookings }: {
|
|
4
|
+
bookings: Hooks;
|
|
5
|
+
}): import("react").JSX.Element;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { bookingFor, classTime, placesLabel, refusalMessage, } from "@composable-os/pack-bookings/client";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Text, 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
|
+
export function TimetableScreen({ bookings }) {
|
|
10
|
+
const timetable = bookings.useTimetable({});
|
|
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 } : {});
|
|
16
|
+
const [message, setMessage] = useState(null);
|
|
17
|
+
const done = (text) => {
|
|
18
|
+
setMessage(text);
|
|
19
|
+
timetable.refetch?.();
|
|
20
|
+
mine.refetch?.();
|
|
21
|
+
};
|
|
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] }));
|
|
26
|
+
}
|
|
27
|
+
function ClassItem({ klass, booking, forPerson, bookings, onDone, }) {
|
|
28
|
+
const book = bookings.useBook();
|
|
29
|
+
const cancel = bookings.useCancel();
|
|
30
|
+
const [preview, setPreview] = useState(null);
|
|
31
|
+
const name = klass.title ?? "Class";
|
|
32
|
+
return (_jsxs(View, { children: [_jsx(Row, { title: name, detail: [classTime(klass), klass.coach?.name, placesLabel(klass.places)]
|
|
33
|
+
.filter(Boolean)
|
|
34
|
+
.join(" · ") }), booking && preview ? (_jsxs(View, { children: [_jsx(Text, { children: preview.message }), _jsx(Button, { label: "Confirm cancel", busy: cancel.isPending, onPress: async () => {
|
|
35
|
+
const result = await cancel.mutateAsync({
|
|
36
|
+
bookingId: booking.id,
|
|
37
|
+
confirm: true,
|
|
38
|
+
expect: preview.state,
|
|
39
|
+
});
|
|
40
|
+
setPreview(null);
|
|
41
|
+
onDone(result.result === "refused"
|
|
42
|
+
? refusalMessage(result, klass.timeZone)
|
|
43
|
+
: `${name}: ${result.message}`);
|
|
44
|
+
} }), _jsx(Button, { label: "Keep it", quiet: true, onPress: () => setPreview(null) })] })) : booking ? (_jsx(Button, { label: "Cancel", quiet: true, busy: cancel.isPending, onPress: async () => {
|
|
45
|
+
const asked = await cancel.mutateAsync({ bookingId: booking.id });
|
|
46
|
+
if (asked.result === "refused")
|
|
47
|
+
onDone(refusalMessage(asked, klass.timeZone));
|
|
48
|
+
else
|
|
49
|
+
setPreview({ state: asked.state, message: asked.message });
|
|
50
|
+
} })) : (_jsx(Button, { label: "Book", busy: book.isPending, onPress: async () => {
|
|
51
|
+
const result = await book.mutateAsync({
|
|
52
|
+
classId: klass.id,
|
|
53
|
+
...(forPerson ? { forPersonId: forPerson.id } : {}),
|
|
54
|
+
});
|
|
55
|
+
onDone(result.result === "booked"
|
|
56
|
+
? `Booked${forPerson ? ` for ${forPerson.name}` : ""}: ${name}, ${classTime(klass)}.`
|
|
57
|
+
: result.result === "waiting"
|
|
58
|
+
? `${name}: ${result.message}`
|
|
59
|
+
: refusalMessage(result, klass.timeZone));
|
|
60
|
+
} }))] }));
|
|
61
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { BookingsHooks } from "@composable-os/pack-bookings/client";
|
|
2
|
+
type Hooks = Pick<BookingsHooks, "useTimetable" | "useMyBookings" | "useBook" | "useCancel" | "useFamily" | "useBuy">;
|
|
3
|
+
export declare function Timetable({ bookings, from, to, payReturnUrl, }: {
|
|
4
|
+
bookings: Hooks;
|
|
5
|
+
/** The first moment shown (ISO 8601); the host's default is now. */
|
|
6
|
+
from?: string;
|
|
7
|
+
to?: string;
|
|
8
|
+
/** Where the payment provider sends a member back after paying for a class (a drop-in). */
|
|
9
|
+
payReturnUrl?: string;
|
|
10
|
+
}): import("react").JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { bookingFor, classTime, placesLabel, refusalMessage, } from "@composable-os/pack-bookings/client";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Button } from "../ui-button/button.js";
|
|
5
|
+
export function Timetable({ bookings, from, to, payReturnUrl, }) {
|
|
6
|
+
const timetable = bookings.useTimetable({ ...(from ? { from } : {}), ...(to ? { to } : {}) });
|
|
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 } : {});
|
|
13
|
+
const [message, setMessage] = useState(null);
|
|
14
|
+
if (timetable.isPending)
|
|
15
|
+
return _jsx("p", { "aria-busy": "true", children: "Loading the timetable\u2026" });
|
|
16
|
+
if (timetable.error || !timetable.data) {
|
|
17
|
+
return _jsx("p", { role: "alert", children: "We could not load the timetable. Try again soon." });
|
|
18
|
+
}
|
|
19
|
+
const refresh = () => {
|
|
20
|
+
timetable.refetch?.();
|
|
21
|
+
mine.refetch?.();
|
|
22
|
+
};
|
|
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) => {
|
|
27
|
+
setMessage(text);
|
|
28
|
+
refresh();
|
|
29
|
+
} }, klass.id))) })] }));
|
|
30
|
+
}
|
|
31
|
+
function ClassRow({ klass, booking, forPerson, bookings, onDone, payReturnUrl, }) {
|
|
32
|
+
const book = bookings.useBook();
|
|
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);
|
|
37
|
+
const [preview, setPreview] = useState(null);
|
|
38
|
+
const name = klass.title ?? "Class";
|
|
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)]
|
|
40
|
+
.filter(Boolean)
|
|
41
|
+
.join(" · ") })] }), booking ? (preview ? (_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("span", { children: preview.message }), _jsx(Button, { variant: "destructive", disabled: cancel.isPending, onClick: async () => {
|
|
42
|
+
const done = await cancel.mutateAsync({
|
|
43
|
+
bookingId: booking.id,
|
|
44
|
+
confirm: true,
|
|
45
|
+
expect: preview.state,
|
|
46
|
+
});
|
|
47
|
+
setPreview(null);
|
|
48
|
+
onDone(done.result === "refused"
|
|
49
|
+
? refusalMessage(done, klass.timeZone)
|
|
50
|
+
: `${name}: ${done.message}`);
|
|
51
|
+
}, children: "Confirm cancel" }), _jsx(Button, { variant: "outline", onClick: () => setPreview(null), children: "Keep it" })] })) : (_jsxs(Button, { variant: "outline", disabled: cancel.isPending, onClick: async () => {
|
|
52
|
+
const asked = await cancel.mutateAsync({ bookingId: booking.id });
|
|
53
|
+
if (asked.result === "refused")
|
|
54
|
+
onDone(refusalMessage(asked, klass.timeZone));
|
|
55
|
+
else
|
|
56
|
+
setPreview({ state: asked.state, message: asked.message });
|
|
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");
|
|
77
|
+
onDone(done.result === "booked"
|
|
78
|
+
? `Booked${forPerson ? ` for ${forPerson.name}` : ""}: ${name}, ${classTime(klass)}.`
|
|
79
|
+
: done.result === "waiting"
|
|
80
|
+
? `${name}: ${done.message}`
|
|
81
|
+
: refusalMessage(done, klass.timeZone));
|
|
82
|
+
}, children: ["Book ", name] }))] }));
|
|
83
|
+
}
|