@composable-os/pack-bookings 0.0.0-stage → 0.1.0-beta.10

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 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,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,58 @@
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
+ setMatches(done.people ?? []);
45
+ setMessage(done.message);
46
+ }
47
+ catch {
48
+ setMessage("That did not work. Try again, or check the class and the person.");
49
+ }
50
+ };
51
+ 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) => {
52
+ event.preventDefault();
53
+ await submit();
54
+ }, 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) => {
55
+ setQuery(event.target.value);
56
+ setPersonId(null);
57
+ } }), 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] })] }));
58
+ }
@@ -0,0 +1,6 @@
1
+ import type { BookingsHooks } from "@composable-os/pack-bookings/client";
2
+ type Hooks = Pick<BookingsHooks, "useTimetable" | "useMyBookings" | "useBook" | "useCancel">;
3
+ export declare function TimetableScreen({ bookings }: {
4
+ bookings: Hooks;
5
+ }): import("react").JSX.Element;
6
+ export {};
@@ -0,0 +1,49 @@
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 mine = bookings.useMyBookings({});
12
+ const [message, setMessage] = useState(null);
13
+ const done = (text) => {
14
+ setMessage(text);
15
+ timetable.refetch?.();
16
+ mine.refetch?.();
17
+ };
18
+ return (_jsxs(Screen, { title: "Timetable", children: [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), bookings: bookings, onDone: done }, klass.id))) })) : null] }));
19
+ }
20
+ function ClassItem({ klass, booking, bookings, onDone, }) {
21
+ const book = bookings.useBook();
22
+ const cancel = bookings.useCancel();
23
+ const [preview, setPreview] = useState(null);
24
+ const name = klass.title ?? "Class";
25
+ return (_jsxs(View, { children: [_jsx(Row, { title: name, detail: [classTime(klass), klass.coach?.name, placesLabel(klass.places)]
26
+ .filter(Boolean)
27
+ .join(" · ") }), booking && preview ? (_jsxs(View, { children: [_jsx(Text, { children: preview.message }), _jsx(Button, { label: "Confirm cancel", busy: cancel.isPending, onPress: async () => {
28
+ const result = await cancel.mutateAsync({
29
+ bookingId: booking.id,
30
+ confirm: true,
31
+ expect: preview.state,
32
+ });
33
+ setPreview(null);
34
+ onDone(result.result === "refused"
35
+ ? refusalMessage(result, klass.timeZone)
36
+ : `${name}: ${result.message}`);
37
+ } }), _jsx(Button, { label: "Keep it", quiet: true, onPress: () => setPreview(null) })] })) : booking ? (_jsx(Button, { label: "Cancel", quiet: true, busy: cancel.isPending, onPress: async () => {
38
+ const asked = await cancel.mutateAsync({ bookingId: booking.id });
39
+ if (asked.result === "refused")
40
+ onDone(refusalMessage(asked, klass.timeZone));
41
+ else
42
+ setPreview({ state: asked.state, message: asked.message });
43
+ } })) : (_jsx(Button, { label: "Book", busy: book.isPending, onPress: async () => {
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
+ } }))] }));
49
+ }
@@ -0,0 +1,9 @@
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, }: {
4
+ bookings: Hooks;
5
+ /** The first moment shown (ISO 8601); the host's default is now. */
6
+ from?: string;
7
+ to?: string;
8
+ }): import("react").JSX.Element;
9
+ export {};
@@ -0,0 +1,52 @@
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, }) {
6
+ const timetable = bookings.useTimetable({ ...(from ? { from } : {}), ...(to ? { to } : {}) });
7
+ const mine = bookings.useMyBookings({});
8
+ const [message, setMessage] = useState(null);
9
+ if (timetable.isPending)
10
+ return _jsx("p", { "aria-busy": "true", children: "Loading the timetable\u2026" });
11
+ if (timetable.error || !timetable.data) {
12
+ return _jsx("p", { role: "alert", children: "We could not load the timetable. Try again soon." });
13
+ }
14
+ const refresh = () => {
15
+ timetable.refetch?.();
16
+ mine.refetch?.();
17
+ };
18
+ return (_jsxs("section", { className: "grid gap-4", "aria-label": "Timetable", children: [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), bookings: bookings, onDone: (text) => {
19
+ setMessage(text);
20
+ refresh();
21
+ } }, klass.id))) })] }));
22
+ }
23
+ function ClassRow({ klass, booking, bookings, onDone, }) {
24
+ const book = bookings.useBook();
25
+ const cancel = bookings.useCancel();
26
+ const [preview, setPreview] = useState(null);
27
+ const name = klass.title ?? "Class";
28
+ 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)]
29
+ .filter(Boolean)
30
+ .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 () => {
31
+ const done = await cancel.mutateAsync({
32
+ bookingId: booking.id,
33
+ confirm: true,
34
+ expect: preview.state,
35
+ });
36
+ setPreview(null);
37
+ onDone(done.result === "refused"
38
+ ? refusalMessage(done, klass.timeZone)
39
+ : `${name}: ${done.message}`);
40
+ }, children: "Confirm cancel" }), _jsx(Button, { variant: "outline", onClick: () => setPreview(null), children: "Keep it" })] })) : (_jsxs(Button, { variant: "outline", disabled: cancel.isPending, onClick: async () => {
41
+ const asked = await cancel.mutateAsync({ bookingId: booking.id });
42
+ if (asked.result === "refused")
43
+ onDone(refusalMessage(asked, klass.timeZone));
44
+ else
45
+ setPreview({ state: asked.state, message: asked.message });
46
+ }, children: ["Cancel ", name] }))) : (_jsxs(Button, { disabled: book.isPending, onClick: async () => {
47
+ const done = await book.mutateAsync({ classId: klass.id });
48
+ onDone(done.result === "booked"
49
+ ? `Booked: ${name}, ${classTime(klass)}.`
50
+ : refusalMessage(done, klass.timeZone));
51
+ }, children: ["Book ", name] }))] }));
52
+ }