@composable-os/pack-rostering 0.0.0-stage → 0.1.0-beta.12

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.
Files changed (51) hide show
  1. package/LICENSE +109 -0
  2. package/dist/blocks/rostering-away/away-list.d.ts +8 -0
  3. package/dist/blocks/rostering-away/away-list.js +101 -0
  4. package/dist/blocks/rostering-checklist/checklist.d.ts +9 -0
  5. package/dist/blocks/rostering-checklist/checklist.js +132 -0
  6. package/dist/blocks/rostering-checklist/my-shifts-with-checklist.d.ts +11 -0
  7. package/dist/blocks/rostering-checklist/my-shifts-with-checklist.js +6 -0
  8. package/dist/blocks/rostering-checklists/checklists.d.ts +11 -0
  9. package/dist/blocks/rostering-checklists/checklists.js +76 -0
  10. package/dist/blocks/rostering-my-availability/my-availability.d.ts +7 -0
  11. package/dist/blocks/rostering-my-availability/my-availability.js +143 -0
  12. package/dist/blocks/rostering-my-calendar/my-calendar.d.ts +6 -0
  13. package/dist/blocks/rostering-my-calendar/my-calendar.js +92 -0
  14. package/dist/blocks/rostering-my-shifts/my-hours.d.ts +6 -0
  15. package/dist/blocks/rostering-my-shifts/my-hours.js +63 -0
  16. package/dist/blocks/rostering-my-shifts/my-shifts.d.ts +17 -0
  17. package/dist/blocks/rostering-my-shifts/my-shifts.js +53 -0
  18. package/dist/blocks/rostering-native-checklist/checklist-screen.d.ts +8 -0
  19. package/dist/blocks/rostering-native-checklist/checklist-screen.js +110 -0
  20. package/dist/blocks/rostering-native-my-availability/my-availability-screen.d.ts +7 -0
  21. package/dist/blocks/rostering-native-my-availability/my-availability-screen.js +110 -0
  22. package/dist/blocks/rostering-native-my-calendar/my-calendar-screen.d.ts +10 -0
  23. package/dist/blocks/rostering-native-my-calendar/my-calendar-screen.js +72 -0
  24. package/dist/blocks/rostering-native-my-shifts/my-hours-screen.d.ts +6 -0
  25. package/dist/blocks/rostering-native-my-shifts/my-hours-screen.js +60 -0
  26. package/dist/blocks/rostering-native-my-shifts/my-shifts-screen.d.ts +12 -0
  27. package/dist/blocks/rostering-native-my-shifts/my-shifts-screen.js +56 -0
  28. package/dist/blocks/rostering-native-offers/offers-screen.d.ts +7 -0
  29. package/dist/blocks/rostering-native-offers/offers-screen.js +56 -0
  30. package/dist/blocks/rostering-native-roster/roster-screen.d.ts +7 -0
  31. package/dist/blocks/rostering-native-roster/roster-screen.js +31 -0
  32. package/dist/blocks/rostering-offers/offers.d.ts +7 -0
  33. package/dist/blocks/rostering-offers/offers.js +52 -0
  34. package/dist/blocks/rostering-patterns/patterns.d.ts +7 -0
  35. package/dist/blocks/rostering-patterns/patterns.js +58 -0
  36. package/dist/blocks/rostering-pay/pay.d.ts +7 -0
  37. package/dist/blocks/rostering-pay/pay.js +160 -0
  38. package/dist/blocks/rostering-qualifications/qualifications.d.ts +6 -0
  39. package/dist/blocks/rostering-qualifications/qualifications.js +48 -0
  40. package/dist/blocks/rostering-week/assign.d.ts +12 -0
  41. package/dist/blocks/rostering-week/assign.js +99 -0
  42. package/dist/blocks/rostering-week/week.d.ts +13 -0
  43. package/dist/blocks/rostering-week/week.js +82 -0
  44. package/dist/client/index.d.ts +3113 -0
  45. package/dist/client/index.js +654 -0
  46. package/dist/index.d.ts +1594 -0
  47. package/dist/index.js +541 -0
  48. package/dist/tools.d.ts +1094 -0
  49. package/dist/tools.js +1047 -0
  50. package/package.json +36 -4
  51. 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,8 @@
1
+ import { type RosteringHooks } from "@composable-os/pack-rostering/client";
2
+ type Hooks = Pick<RosteringHooks, "useMe" | "useAwayList" | "useAwayFor" | "useBack" | "usePeople">;
3
+ export declare function TimeOff({ rostering, from, locale, }: {
4
+ rostering: Hooks;
5
+ from?: string;
6
+ locale?: string;
7
+ }): import("react").JSX.Element;
8
+ export {};
@@ -0,0 +1,101 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // Everyone's time off (stage 45 step 7), for someone who rosters: by week, who said they cannot
3
+ // work, with their notes, and adding or ending someone's time off for them. The host lets only
4
+ // someone who rosters read anyone else's, and only as a person at the screen (never an assistant),
5
+ // so this is shown only when the host says the reader rosters (`me.rosters`), and other staff
6
+ // never see that anyone is away.
7
+ //
8
+ // Notes are read on this screen only: kept in the app's cache no longer than they are shown,
9
+ // hidden when the page is left, and what was sent is forgotten once the call is over.
10
+ import { addDays, awayKind, awayWhen, dayLabel, forgetAfter, rosterRefusal, weekOf, } from "@composable-os/pack-rostering/client";
11
+ import { useEffect, useId, useRef, useState } from "react";
12
+ import { Button } from "../ui-button/button.js";
13
+ /** Hides what is shown when the page is left; reads it again when it comes back. */
14
+ function useForgetOnLeave(forget, cameBack) {
15
+ const latest = useRef({ forget, cameBack });
16
+ latest.current = { forget, cameBack };
17
+ useEffect(() => {
18
+ const hide = () => latest.current.forget();
19
+ const show = (event) => {
20
+ if (!event.persisted)
21
+ return;
22
+ latest.current.forget();
23
+ latest.current.cameBack();
24
+ };
25
+ window.addEventListener("pagehide", hide);
26
+ window.addEventListener("pageshow", show);
27
+ return () => {
28
+ window.removeEventListener("pagehide", hide);
29
+ window.removeEventListener("pageshow", show);
30
+ };
31
+ }, []);
32
+ }
33
+ export function TimeOff({ rostering, from, locale = "en-AU", }) {
34
+ const me = rostering.useMe();
35
+ const rosters = me.data?.rosters === true;
36
+ const [start, setStart] = useState(from ? weekOf(from) : null);
37
+ const first = start ?? (me.data ? weekOf(me.data.today) : null);
38
+ const list = rostering.useAwayList({ from: first ?? "", to: first ? addDays(first, 6) : "" }, rosters && first !== null);
39
+ const people = rostering.usePeople(rosters);
40
+ const awayFor = rostering.useAwayFor();
41
+ const back = rostering.useBack();
42
+ const [hidden, setHidden] = useState(false);
43
+ const [account, setAccount] = useState("");
44
+ const [startsAt, setStartsAt] = useState("");
45
+ const [endsAt, setEndsAt] = useState("");
46
+ const [note, setNote] = useState("");
47
+ const [refusal, setRefusal] = useState(null);
48
+ const [said, setSaid] = useState(null);
49
+ const id = useId();
50
+ useForgetOnLeave(() => {
51
+ setHidden(true);
52
+ setNote("");
53
+ }, () => void Promise.resolve(list.refetch?.()).then(() => setHidden(false)));
54
+ if (me.isPending)
55
+ return _jsx("p", { "aria-busy": "true", children: "Loading\u2026" });
56
+ if (me.error || !me.data)
57
+ return _jsx("p", { role: "alert", children: rosterRefusal(me.error).message });
58
+ if (!rosters) {
59
+ return (_jsx("p", { role: "status", "data-refusal": "rostering", children: "Other people's time off is seen only by whoever rosters. Yours is on My availability." }));
60
+ }
61
+ const today = me.data.today;
62
+ async function add(event) {
63
+ event.preventDefault();
64
+ setRefusal(null);
65
+ setSaid(null);
66
+ const input = {
67
+ account,
68
+ kind: "leave",
69
+ startsAt,
70
+ endsAt,
71
+ ...(note.trim() ? { note: note.trim() } : {}),
72
+ };
73
+ try {
74
+ const made = await forgetAfter(awayFor, input);
75
+ setNote("");
76
+ setSaid(made.count
77
+ ? `Saved. They are on ${made.count} shift${made.count === 1 ? "" : "s"} then, which stay theirs with a warning.`
78
+ : "Saved.");
79
+ }
80
+ catch (error) {
81
+ setRefusal(rosterRefusal(error));
82
+ }
83
+ await list.refetch?.();
84
+ }
85
+ async function end(itemId) {
86
+ setRefusal(null);
87
+ try {
88
+ await back.mutateAsync({ id: itemId });
89
+ setSaid("Ended.");
90
+ }
91
+ catch (error) {
92
+ setRefusal(rosterRefusal(error));
93
+ }
94
+ await list.refetch?.();
95
+ }
96
+ const items = hidden ? [] : (list.data?.items ?? []);
97
+ const names = [...new Set(items.map((i) => i.name))].sort();
98
+ return (_jsxs("section", { className: "grid gap-4", "aria-labelledby": `${id}-h`, children: [_jsxs("header", { className: "flex flex-wrap items-center justify-between gap-2", children: [_jsxs("h2", { id: `${id}-h`, className: "text-lg font-medium", children: ["Time off", first ? `: week of ${dayLabel(first, locale, true)}` : ""] }), _jsxs("nav", { "aria-label": "Weeks", className: "flex flex-wrap gap-2", children: [_jsx(Button, { type: "button", variant: "outline", "aria-label": "Previous week", onClick: () => first && setStart(addDays(first, -7)), children: "\u2039 Previous" }), _jsx(Button, { type: "button", variant: "outline", onClick: () => setStart(weekOf(today)), children: "This week" }), _jsx(Button, { type: "button", variant: "outline", "aria-label": "Next week", onClick: () => first && setStart(addDays(first, 7)), children: "Next \u203A" })] })] }), said ? (_jsx("p", { role: "status", className: "text-sm", children: said })) : null, refusal ? (_jsx("p", { role: "alert", className: "text-sm", "data-refusal": refusal.kind, children: refusal.message })) : null, list.isPending || hidden ? _jsx("p", { "aria-busy": "true", children: "Loading time off\u2026" }) : null, list.error ? _jsx("p", { role: "alert", children: rosterRefusal(list.error).message }) : null, list.data && !hidden && !items.length ? _jsx("p", { children: "Nobody said they are away this week." }) : null, _jsx("ul", { className: "grid gap-3", children: names.map((name) => (_jsxs("li", { className: "grid gap-1 rounded-md border p-2", children: [_jsx("h3", { className: "font-medium", children: name }), _jsx("ul", { className: "grid gap-1 text-sm", children: items
99
+ .filter((i) => i.name === name)
100
+ .map((item) => (_jsxs("li", { className: "flex flex-wrap items-center justify-between gap-2", children: [_jsxs("span", { children: [awayKind(item.kind), " \u00B7 ", awayWhen(item, locale), item.note ? (_jsx("span", { className: "block text-muted-foreground", children: item.note })) : null] }), _jsx(Button, { type: "button", size: "sm", variant: "outline", disabled: back.isPending, "aria-label": `End ${name}'s ${awayKind(item.kind).toLowerCase()}`, onClick: () => end(item.id), children: "End" })] }, item.id))) })] }, name))) }), _jsxs("form", { className: "grid gap-2 rounded-md border p-3", onSubmit: add, "aria-label": "Add leave for someone", children: [_jsx("h3", { className: "text-sm font-medium", children: "Add leave for someone" }), _jsx("label", { htmlFor: `${id}-who`, className: "text-sm", children: "Who" }), _jsxs("select", { id: `${id}-who`, className: "rounded-md border border-input px-2 py-1 text-sm", value: account, onChange: (e) => setAccount(e.target.value), required: true, children: [_jsx("option", { value: "", children: "Choose\u2026" }), (people.data?.people ?? []).map((p) => (_jsx("option", { value: p.account, children: p.name }, p.account)))] }), _jsx("label", { htmlFor: `${id}-from`, className: "text-sm", children: "From" }), _jsx("input", { id: `${id}-from`, type: "datetime-local", className: "rounded-md border border-input px-2 py-1 text-sm", value: startsAt, onChange: (e) => setStartsAt(e.target.value), required: true }), _jsx("label", { htmlFor: `${id}-until`, className: "text-sm", children: "Until" }), _jsx("input", { id: `${id}-until`, type: "datetime-local", className: "rounded-md border border-input px-2 py-1 text-sm", value: endsAt, onChange: (e) => setEndsAt(e.target.value), required: true }), _jsx("label", { htmlFor: `${id}-note`, className: "text-sm", children: "Note (optional)" }), _jsx("input", { id: `${id}-note`, className: "rounded-md border border-input px-2 py-1 text-sm", value: note, maxLength: 500, autoComplete: "off", onChange: (e) => setNote(e.target.value) }), _jsx(Button, { type: "submit", disabled: awayFor.isPending || !account, children: "Add leave" })] })] }));
101
+ }
@@ -0,0 +1,9 @@
1
+ import { type RosteringHooks, type RosterShift } from "@composable-os/pack-rostering/client";
2
+ export type ChecklistHooks = Pick<RosteringHooks, "useChecklist" | "useTick" | "useChecklistDone">;
3
+ export declare function ShiftChecklist({ rostering, shift, locale, zone, }: {
4
+ rostering: ChecklistHooks;
5
+ shift: RosterShift;
6
+ locale?: string;
7
+ /** The roster's zone, for the times (the shift's own zone first). */
8
+ zone?: string;
9
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,132 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ // A shift's checklist (stage 45 step 4b, ADR 0650), for the `shiftExtra` slot under a shift (my
3
+ // shifts; a rosterer's week). A duty may carry a checklist: its shift's person ticks each step off,
4
+ // done (with a note where the step asks for one) or not done (with why), and marks it done, which
5
+ // is final. Whoever rosters may tick it for the person, saying why: it is kept, and shown, as
6
+ // ticked by them for that person.
7
+ //
8
+ // The host decides everything here: whose it is to tick (`canTick`, `onBehalf`), when (from the
9
+ // shift's start until 2 hours after its end), whether a step needs a note, whether every required
10
+ // step is ticked. This shows the host's answer and its refusals, each in its own state.
11
+ //
12
+ // What someone writes on a step, why it was not done and why it was ticked for them are private:
13
+ // kept only in this screen's state, sent with `forgetAfter` (never in a URL, storage or a query's
14
+ // key), cleared when the page is left, and read again when the browser brings it back. The
15
+ // checklist itself is fetched only when it is opened, and kept no longer than it is shown.
16
+ import { checklistStateLabel, forgetAfter, refusalNext, rosterRefusal, shiftTime, tickLabel, } from "@composable-os/pack-rostering/client";
17
+ import { useEffect, useId, useRef, useState } from "react";
18
+ import { Button } from "../ui-button/button.js";
19
+ const EMPTY_DRAFT = { note: "", why: "", notDone: false };
20
+ /** Forgets what was typed when the page is left, or brought back from the back-forward cache. */
21
+ function useForgetOnLeave(forget, cameBack) {
22
+ const latest = useRef({ forget, cameBack });
23
+ latest.current = { forget, cameBack };
24
+ useEffect(() => {
25
+ const hide = () => latest.current.forget();
26
+ const show = (event) => {
27
+ if (!event.persisted)
28
+ return;
29
+ latest.current.forget();
30
+ latest.current.cameBack();
31
+ };
32
+ window.addEventListener("pagehide", hide);
33
+ window.addEventListener("pageshow", show);
34
+ return () => {
35
+ window.removeEventListener("pagehide", hide);
36
+ window.removeEventListener("pageshow", show);
37
+ };
38
+ }, []);
39
+ }
40
+ export function ShiftChecklist({ rostering, shift, locale = "en-AU", zone, }) {
41
+ const [open, setOpen] = useState(false);
42
+ const answer = rostering.useChecklist(open ? { object: shift.object, id: shift.id } : null);
43
+ const tick = rostering.useTick();
44
+ const done = rostering.useChecklistDone();
45
+ const [drafts, setDrafts] = useState({});
46
+ const [forWhy, setForWhy] = useState("");
47
+ const [refusal, setRefusal] = useState(null);
48
+ const [said, setSaid] = useState(null);
49
+ const [hidden, setHidden] = useState(false);
50
+ const id = useId();
51
+ useForgetOnLeave(() => {
52
+ setDrafts({});
53
+ setForWhy("");
54
+ setHidden(true);
55
+ }, () => void Promise.resolve(answer.refetch?.()).then(() => setHidden(false)));
56
+ if (!shift.checklist)
57
+ return null;
58
+ const busy = tick.isPending || done.isPending;
59
+ const draftOf = (position) => drafts[position] ?? EMPTY_DRAFT;
60
+ const setDraft = (position, patch) => setDrafts((d) => ({ ...d, [position]: { ...(d[position] ?? EMPTY_DRAFT), ...patch } }));
61
+ const data = hidden ? undefined : answer.data;
62
+ const run = data?.run ?? null;
63
+ const editable = Boolean(data?.canTick) && (run === null || run.state === "open");
64
+ // Someone else's tick is changed only by whoever rosters (the host refuses it otherwise).
65
+ const mayChange = (step) => !step.tick || step.tick.by === data?.you || data?.youRoster === true;
66
+ const onBehalf = Boolean(data?.onBehalf);
67
+ const tz = shift.zone ?? zone ?? "UTC";
68
+ async function act(step, what, words) {
69
+ setRefusal(null);
70
+ setSaid(null);
71
+ try {
72
+ await what();
73
+ setSaid(words);
74
+ if (step !== null)
75
+ setDrafts((d) => ({ ...d, [step]: EMPTY_DRAFT }));
76
+ }
77
+ catch (error) {
78
+ setRefusal({ step, refusal: rosterRefusal(error) });
79
+ }
80
+ await answer.refetch?.();
81
+ }
82
+ function tickStep(step, state) {
83
+ const d = draftOf(step.position);
84
+ const input = {
85
+ object: shift.object,
86
+ id: shift.id,
87
+ step: step.position,
88
+ state,
89
+ ...(state === "done" && d.note.trim() ? { note: d.note.trim() } : {}),
90
+ ...(state === "not_done" && d.why.trim() ? { why: d.why.trim() } : {}),
91
+ ...(onBehalf && forWhy.trim() ? { forWhy: forWhy.trim() } : {}),
92
+ };
93
+ return act(step.position, () => forgetAfter(tick, input), state === "clear" ? "Tick cleared." : "Ticked.");
94
+ }
95
+ const steps = run?.steps ??
96
+ (data?.preview ?? []).map((s, position) => ({
97
+ ...s,
98
+ position,
99
+ tick: null,
100
+ history: [],
101
+ missed: false,
102
+ }));
103
+ const state = run ? run.state : (shift.checklist.state ?? null);
104
+ return (_jsxs("section", { className: "grid gap-2 rounded-md border p-2 text-sm", "aria-labelledby": `${id}-name`, "data-checklist-for": shift.id, children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [_jsxs("p", { id: `${id}-name`, className: "font-medium", children: ["Checklist: ", shift.checklist.name, state ? (_jsx("span", { className: "ml-2 rounded border px-1 text-xs", "data-checklist-state": state, children: checklistStateLabel(state) })) : null] }), _jsx(Button, { type: "button", variant: "outline", "aria-expanded": open, "aria-controls": `${id}-body`, "aria-label": `${open ? "Close" : "Open"} the checklist ${shift.checklist.name} of ${shift.title}`, onClick: () => {
105
+ setOpen((o) => !o);
106
+ setRefusal(null);
107
+ setSaid(null);
108
+ }, children: open ? "Close checklist" : "Open checklist" })] }), open ? (_jsxs("div", { id: `${id}-body`, className: "grid gap-2", children: [answer.isPending || hidden ? _jsx("p", { "aria-busy": "true", children: "Loading the checklist\u2026" }) : null, answer.error ? (_jsx("p", { role: "alert", "data-refusal": rosterRefusal(answer.error).kind, children: rosterRefusal(answer.error).message })) : null, data ? (_jsxs(_Fragment, { children: [data.opens && data.tickUntil ? (_jsx("p", { className: "text-muted-foreground", children: editable
109
+ ? `Tick it off until ${shiftTime({ startsAt: data.tickUntil, endsAt: null }, tz, { withDate: true, locale })}.`
110
+ : run && run.state !== "open"
111
+ ? `This checklist is ${checklistStateLabel(run.state).toLowerCase()}: it does not change.`
112
+ : `It can be ticked from ${shiftTime({ startsAt: data.opens, endsAt: null }, tz, { withDate: true, locale })} until ${shiftTime({ startsAt: data.tickUntil, endsAt: null }, tz, { withDate: true, locale })}.` })) : null, editable && onBehalf ? (_jsxs("div", { className: "grid gap-1 rounded-md border p-2", children: [_jsxs("p", { children: ["You are ticking this for ", data.forName ?? "the person on the shift", "."] }), _jsxs("label", { className: "grid gap-1", htmlFor: `${id}-for`, children: [_jsx("span", { children: "Why you are ticking it for them" }), _jsx("input", { id: `${id}-for`, className: "rounded-md border px-2 py-1", value: forWhy, maxLength: 500, autoComplete: "off", onChange: (e) => setForWhy(e.target.value) })] })] })) : null, _jsx("ol", { className: "grid gap-2", "aria-label": `Steps of ${shift.checklist.name}`, children: steps.map((step) => {
113
+ const d = draftOf(step.position);
114
+ return (_jsxs("li", { className: "grid gap-1 rounded-md border p-2", "data-step": step.position, "data-ticked": step.tick ? (step.tick.done ? "done" : "not_done") : undefined, "data-missed": step.missed ? "true" : undefined, children: [_jsxs("p", { children: [_jsx("span", { className: "font-medium", children: step.text }), _jsxs("span", { className: "ml-2 text-xs text-muted-foreground", children: [step.required ? "Required" : "Optional", step.asksNote ? " · asks for a note" : ""] })] }), step.tick ? (_jsxs("p", { className: "text-xs", children: [tickLabel(step.tick), step.tick.why ? ` · Why: ${step.tick.why}` : "", step.tick.onBehalfWhy
115
+ ? ` · For them because: ${step.tick.onBehalfWhy}`
116
+ : ""] })) : null, step.tick?.note ? _jsxs("p", { className: "text-xs", children: ["Note: ", step.tick.note] }) : null, step.tick?.withheld ? (_jsx("p", { className: "text-xs text-muted-foreground", children: "What they wrote is theirs and whoever rosters' to read." })) : null, step.history.length ? (_jsxs("details", { className: "text-xs", "data-history": step.position, children: [_jsxs("summary", { children: ["Earlier ticks (", step.history.length, ")"] }), _jsx("ul", { className: "grid gap-1", children: step.history.map((h) => (_jsxs("li", { children: [tickLabel(h), h.why ? ` · Why: ${h.why}` : "", h.note ? ` · Note: ${h.note}` : ""] }, h.id))) })] })) : null, step.missed ? _jsx("p", { className: "text-xs font-semibold", children: "Missed" }) : null, editable && mayChange(step) ? (_jsxs("div", { className: "grid gap-1", children: [_jsxs("label", { className: "grid gap-1", htmlFor: `${id}-note-${step.position}`, children: [_jsx("span", { className: "text-xs", children: step.asksNote ? "Note (needed to tick it done)" : "Note (optional)" }), _jsx("input", { id: `${id}-note-${step.position}`, className: "rounded-md border px-2 py-1", value: d.note, maxLength: 1000, autoComplete: "off", "aria-label": `Note on ${step.text}`, onChange: (e) => setDraft(step.position, { note: e.target.value }) })] }), d.notDone ? (_jsxs("label", { className: "grid gap-1", htmlFor: `${id}-why-${step.position}`, children: [_jsx("span", { className: "text-xs", children: "Why it was not done" }), _jsx("input", { id: `${id}-why-${step.position}`, className: "rounded-md border px-2 py-1", value: d.why, maxLength: 500, autoComplete: "off", "aria-label": `Why ${step.text} was not done`, onChange: (e) => setDraft(step.position, { why: e.target.value }) })] })) : null, _jsxs("div", { className: "flex flex-wrap gap-2", children: [_jsx(Button, { type: "button", disabled: busy, "aria-busy": busy, "aria-label": `Tick ${step.text} done`, onClick: () => tickStep(step, "done"), children: "Done" }), _jsx(Button, { type: "button", variant: "outline", disabled: busy, "aria-label": d.notDone
117
+ ? `Save ${step.text} as not done`
118
+ : `Mark ${step.text} not done`, onClick: () => d.notDone
119
+ ? tickStep(step, "not_done")
120
+ : setDraft(step.position, { notDone: true }), children: d.notDone ? "Save not done" : "Not done" }), step.tick ? (_jsx(Button, { type: "button", variant: "outline", disabled: busy, "aria-label": `Clear the tick of ${step.text}`, onClick: () => tickStep(step, "clear"), children: "Clear" })) : null] })] })) : null, refusal?.step === step.position ? (_jsx(Refusal, { refusal: refusal.refusal })) : null] }, step.position));
121
+ }) }), editable ? (_jsx(Button, { type: "button", disabled: busy, "aria-busy": busy, "aria-label": `Mark the checklist ${shift.checklist.name} done`, onClick: () => act(null, () => forgetAfter(done, {
122
+ object: shift.object,
123
+ id: shift.id,
124
+ ...(onBehalf && forWhy.trim() ? { forWhy: forWhy.trim() } : {}),
125
+ }), "Done. It does not change now."), children: "Mark done" })) : null, run?.closedByName && run.state === "done" ? (_jsxs("p", { className: "text-xs", children: ["Marked done by ", run.closedByName, run.account && run.closedBy !== run.account && run.name
126
+ ? ` for ${run.name}`
127
+ : "", run.closedWhy ? ` · Why: ${run.closedWhy}` : ""] })) : null, run?.corrections.length ? (_jsxs("section", { "aria-label": "Corrections", className: "grid gap-1", children: [_jsx("h4", { className: "text-xs font-medium", children: "Corrections" }), _jsx("ul", { className: "grid gap-1 text-xs", children: run.corrections.map((c) => (_jsxs("li", { children: [c.text, " (", c.byName, ")"] }, c.id))) })] })) : null] })) : null, said ? (_jsx("p", { role: "status", className: "text-xs", children: said })) : null, refusal && refusal.step === null ? _jsx(Refusal, { refusal: refusal.refusal }) : null] })) : null] }));
128
+ }
129
+ function Refusal({ refusal }) {
130
+ const next = refusalNext(refusal.kind, false);
131
+ return (_jsxs("div", { role: "alert", className: "text-xs", "data-refusal": refusal.kind, children: [_jsx("p", { children: refusal.message }), next ? _jsx("p", { children: next }) : null] }));
132
+ }
@@ -0,0 +1,11 @@
1
+ import type { RosteringHooks } from "@composable-os/pack-rostering/client";
2
+ import type { MyHoursHooks } from "../rostering-my-shifts/my-hours.tsx";
3
+ import { type ChecklistHooks } from "./checklist.tsx";
4
+ type Hooks = Pick<RosteringHooks, "useMe" | "useMine" | "useOffers" | "useOffer" | "useWithdraw"> & ChecklistHooks & MyHoursHooks;
5
+ export declare function MyShiftsWithChecklist({ rostering, from, days, locale, }: {
6
+ rostering: Hooks;
7
+ from?: string;
8
+ days?: number;
9
+ locale?: string;
10
+ }): import("react").JSX.Element;
11
+ export {};
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { MyShifts } from "../rostering-my-shifts/my-shifts.js";
3
+ import { ShiftChecklist } from "./checklist.js";
4
+ export function MyShiftsWithChecklist({ rostering, from, days, locale = "en-AU", }) {
5
+ return (_jsx(MyShifts, { rostering: rostering, ...(from ? { from } : {}), ...(days ? { days } : {}), locale: locale, shiftExtra: (shift) => _jsx(ShiftChecklist, { rostering: rostering, shift: shift, locale: locale }) }));
6
+ }
@@ -0,0 +1,11 @@
1
+ import { type RosteringHooks } from "@composable-os/pack-rostering/client";
2
+ type Hooks = Pick<RosteringHooks, "useMe" | "useChecklistRuns" | "useChecklistCorrect">;
3
+ export declare function ChecklistRuns({ rostering, from, to, locale, }: {
4
+ rostering: Hooks;
5
+ /** The first date (local, YYYY-MM-DD); a week before today in the business's zone by default. */
6
+ from?: string;
7
+ /** The last date; today by default. */
8
+ to?: string;
9
+ locale?: string;
10
+ }): import("react").JSX.Element;
11
+ export {};
@@ -0,0 +1,76 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // How checklists went (stage 45 step 4b, ADR 0650), for whoever rosters: every checklist run in a
3
+ // range of dates, by checklist and then by date, each with its shift, its person, whether it is
4
+ // open, done, missed or cancelled, how many steps were ticked, how many were ticked for the person
5
+ // by someone else, and the steps nobody ticked when it was missed. A closed run takes a correction:
6
+ // a note kept beside it, never a change to its ticks.
7
+ //
8
+ // The host decides who sees this: the screen asks `me` first and shows nothing but a line unless
9
+ // the host says the reader rosters, and the host refuses anyone else anyway. The runs are kept no
10
+ // longer than they are shown; a correction is sent with `forgetAfter` and kept only on screen.
11
+ import { addDays, checklistStateLabel, dateIn, dayLabel, forgetAfter, rosterRefusal, shiftTime, } from "@composable-os/pack-rostering/client";
12
+ import { useId, useState } from "react";
13
+ import { Button } from "../ui-button/button.js";
14
+ export function ChecklistRuns({ rostering, from, to, locale = "en-AU", }) {
15
+ const me = rostering.useMe();
16
+ const today = me.data?.today ?? null;
17
+ const [range, setRange] = useState(from && to ? { from, to } : null);
18
+ const [template, setTemplate] = useState("");
19
+ const current = range ?? (today ? { from: from ?? addDays(today, -6), to: to ?? today } : null);
20
+ const rosters = me.data?.rosters === true;
21
+ const runs = rostering.useChecklistRuns(rosters && current ? { ...current, ...(template ? { template } : {}) } : null);
22
+ const correct = rostering.useChecklistCorrect();
23
+ const [writing, setWriting] = useState(null);
24
+ const [text, setText] = useState("");
25
+ const [refusal, setRefusal] = useState(null);
26
+ const [said, setSaid] = useState(null);
27
+ const id = useId();
28
+ if (me.isPending)
29
+ return _jsx("p", { "aria-busy": "true", children: "Loading\u2026" });
30
+ if (me.error || !me.data)
31
+ return _jsx("p", { role: "alert", children: rosterRefusal(me.error).message });
32
+ if (!rosters) {
33
+ return _jsx("p", { children: "How checklists went is shown to whoever rosters." });
34
+ }
35
+ const zone = runs.data?.zone ?? me.data.zone;
36
+ const list = runs.data?.runs ?? [];
37
+ const templates = new Map();
38
+ for (const r of list)
39
+ templates.set(r.template.id, r.template.name);
40
+ const byTemplate = new Map();
41
+ for (const r of list) {
42
+ const dates = byTemplate.get(r.template.id) ?? new Map();
43
+ const date = dateIn(r.opens, zone);
44
+ dates.set(date, [...(dates.get(date) ?? []), r]);
45
+ byTemplate.set(r.template.id, dates);
46
+ }
47
+ async function submit(event, run) {
48
+ event.preventDefault();
49
+ setRefusal(null);
50
+ setSaid(null);
51
+ try {
52
+ await forgetAfter(correct, { run, text: text.trim() });
53
+ setText("");
54
+ setWriting(null);
55
+ setSaid("Correction added beside it.");
56
+ }
57
+ catch (error) {
58
+ setRefusal(rosterRefusal(error));
59
+ }
60
+ await runs.refetch?.();
61
+ }
62
+ return (_jsxs("section", { className: "grid gap-4", "aria-labelledby": `${id}-h`, children: [_jsx("h2", { id: `${id}-h`, className: "text-lg font-medium", children: "How checklists went" }), _jsxs("form", { className: "flex flex-wrap items-end gap-2 text-sm", onSubmit: (e) => {
63
+ e.preventDefault();
64
+ const data = new FormData(e.currentTarget);
65
+ const f = String(data.get("from") ?? "");
66
+ const t = String(data.get("to") ?? "");
67
+ if (f && t)
68
+ setRange({ from: f, to: t });
69
+ }, children: [_jsxs("label", { className: "grid gap-1", htmlFor: `${id}-from`, children: [_jsx("span", { children: "From" }), _jsx("input", { id: `${id}-from`, name: "from", type: "date", className: "rounded-md border px-2 py-1", defaultValue: current?.from })] }), _jsxs("label", { className: "grid gap-1", htmlFor: `${id}-to`, children: [_jsx("span", { children: "To" }), _jsx("input", { id: `${id}-to`, name: "to", type: "date", className: "rounded-md border px-2 py-1", defaultValue: current?.to })] }), _jsxs("label", { className: "grid gap-1", htmlFor: `${id}-tpl`, children: [_jsx("span", { children: "Checklist" }), _jsxs("select", { id: `${id}-tpl`, className: "rounded-md border px-2 py-1", value: template, onChange: (e) => setTemplate(e.target.value), children: [_jsx("option", { value: "", children: "Every checklist" }), [...templates].map(([tid, name]) => (_jsx("option", { value: tid, children: name }, tid)))] })] }), _jsx(Button, { type: "submit", variant: "outline", children: "Show" })] }), _jsxs("p", { className: "text-sm text-muted-foreground", children: ["Times are in ", zone, "."] }), runs.isPending ? _jsx("p", { "aria-busy": "true", children: "Loading the checklists\u2026" }) : null, runs.error ? (_jsx("p", { role: "alert", "data-refusal": rosterRefusal(runs.error).kind, children: rosterRefusal(runs.error).message })) : null, runs.data?.truncated ? (_jsx("p", { role: "status", children: "More runs than one screen shows: the first ones are shown." })) : null, said ? (_jsx("p", { role: "status", className: "text-sm", children: said })) : null, refusal ? (_jsx("p", { role: "alert", className: "text-sm", "data-refusal": refusal.kind, children: refusal.message })) : null, runs.data && !list.length ? _jsx("p", { children: "No checklists in these dates." }) : null, [...byTemplate].map(([tid, dates]) => (_jsxs("section", { className: "grid gap-2", "aria-label": templates.get(tid), children: [_jsx("h3", { className: "font-medium", children: templates.get(tid) }), [...dates].map(([date, items]) => (_jsxs("div", { className: "grid gap-1", children: [_jsx("h4", { className: "text-sm font-medium", children: dayLabel(date, locale, true) }), _jsx("ul", { className: "grid gap-2", children: items.map((r) => (_jsxs("li", { className: "grid gap-1 rounded-md border p-2 text-sm", "data-run": r.id, "data-state": r.state, "data-record": r.record, children: [_jsxs("p", { children: [_jsx("span", { className: "font-medium", children: r.title }), ",", " ", shiftTime({ startsAt: r.opens, endsAt: r.closes }, zone, { locale }), " \u00B7", " ", r.name ?? "Nobody on it", " \u00B7", " ", _jsx("span", { "data-checklist-state": r.state, children: checklistStateLabel(r.state) })] }), _jsxs("p", { className: "text-xs", children: [r.ticked, " of ", r.steps, " ticked", r.onBehalf ? ` · ${r.onBehalf} ticked for them by someone else` : "", r.corrections ? ` · ${r.corrections} correction(s)` : ""] }), r.missed.length ? (_jsxs("p", { className: "text-xs", children: ["Not done: ", r.missed.join("; ")] })) : null, r.state !== "open" ? (writing === r.id ? (_jsxs("form", { className: "grid gap-1", onSubmit: (e) => submit(e, r.id), children: [_jsxs("label", { className: "grid gap-1", htmlFor: `${id}-c-${r.id}`, children: [_jsx("span", { className: "text-xs", children: "Correction" }), _jsx("input", { id: `${id}-c-${r.id}`, className: "rounded-md border px-2 py-1", value: text, maxLength: 1000, autoComplete: "off", onChange: (e) => setText(e.target.value) })] }), _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { type: "submit", disabled: correct.isPending || !text.trim(), "aria-busy": correct.isPending, children: "Add correction" }), _jsx(Button, { type: "button", variant: "outline", onClick: () => {
70
+ setWriting(null);
71
+ setText("");
72
+ }, children: "Cancel" })] })] })) : (_jsx(Button, { type: "button", variant: "outline", "aria-label": `Add a correction to the checklist of ${r.title}`, onClick: () => {
73
+ setWriting(r.id);
74
+ setText("");
75
+ }, children: "Add a correction" }))) : null] }, r.id))) })] }, date)))] }, tid)))] }));
76
+ }
@@ -0,0 +1,7 @@
1
+ import { type RosteringHooks } from "@composable-os/pack-rostering/client";
2
+ type Hooks = Pick<RosteringHooks, "useMe" | "useMyAway" | "useAway" | "useBack" | "useOffer">;
3
+ export declare function MyAvailability({ rostering, locale, }: {
4
+ rostering: Hooks;
5
+ locale?: string;
6
+ }): import("react").JSX.Element;
7
+ export {};