@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.
- package/LICENSE +109 -0
- package/dist/blocks/rostering-away/away-list.d.ts +8 -0
- package/dist/blocks/rostering-away/away-list.js +101 -0
- package/dist/blocks/rostering-checklist/checklist.d.ts +9 -0
- package/dist/blocks/rostering-checklist/checklist.js +132 -0
- package/dist/blocks/rostering-checklist/my-shifts-with-checklist.d.ts +11 -0
- package/dist/blocks/rostering-checklist/my-shifts-with-checklist.js +6 -0
- package/dist/blocks/rostering-checklists/checklists.d.ts +11 -0
- package/dist/blocks/rostering-checklists/checklists.js +76 -0
- package/dist/blocks/rostering-my-availability/my-availability.d.ts +7 -0
- package/dist/blocks/rostering-my-availability/my-availability.js +143 -0
- package/dist/blocks/rostering-my-calendar/my-calendar.d.ts +6 -0
- package/dist/blocks/rostering-my-calendar/my-calendar.js +92 -0
- package/dist/blocks/rostering-my-shifts/my-hours.d.ts +6 -0
- package/dist/blocks/rostering-my-shifts/my-hours.js +63 -0
- package/dist/blocks/rostering-my-shifts/my-shifts.d.ts +17 -0
- package/dist/blocks/rostering-my-shifts/my-shifts.js +53 -0
- package/dist/blocks/rostering-native-checklist/checklist-screen.d.ts +8 -0
- package/dist/blocks/rostering-native-checklist/checklist-screen.js +110 -0
- package/dist/blocks/rostering-native-my-availability/my-availability-screen.d.ts +7 -0
- package/dist/blocks/rostering-native-my-availability/my-availability-screen.js +110 -0
- package/dist/blocks/rostering-native-my-calendar/my-calendar-screen.d.ts +10 -0
- package/dist/blocks/rostering-native-my-calendar/my-calendar-screen.js +72 -0
- package/dist/blocks/rostering-native-my-shifts/my-hours-screen.d.ts +6 -0
- package/dist/blocks/rostering-native-my-shifts/my-hours-screen.js +60 -0
- package/dist/blocks/rostering-native-my-shifts/my-shifts-screen.d.ts +12 -0
- package/dist/blocks/rostering-native-my-shifts/my-shifts-screen.js +56 -0
- package/dist/blocks/rostering-native-offers/offers-screen.d.ts +7 -0
- package/dist/blocks/rostering-native-offers/offers-screen.js +56 -0
- package/dist/blocks/rostering-native-roster/roster-screen.d.ts +7 -0
- package/dist/blocks/rostering-native-roster/roster-screen.js +31 -0
- package/dist/blocks/rostering-offers/offers.d.ts +7 -0
- package/dist/blocks/rostering-offers/offers.js +52 -0
- package/dist/blocks/rostering-patterns/patterns.d.ts +7 -0
- package/dist/blocks/rostering-patterns/patterns.js +58 -0
- package/dist/blocks/rostering-pay/pay.d.ts +7 -0
- package/dist/blocks/rostering-pay/pay.js +160 -0
- package/dist/blocks/rostering-qualifications/qualifications.d.ts +6 -0
- package/dist/blocks/rostering-qualifications/qualifications.js +48 -0
- package/dist/blocks/rostering-week/assign.d.ts +12 -0
- package/dist/blocks/rostering-week/assign.js +99 -0
- package/dist/blocks/rostering-week/week.d.ts +13 -0
- package/dist/blocks/rostering-week/week.js +82 -0
- package/dist/client/index.d.ts +3113 -0
- package/dist/client/index.js +654 -0
- package/dist/index.d.ts +1594 -0
- package/dist/index.js +541 -0
- package/dist/tools.d.ts +1094 -0
- package/dist/tools.js +1047 -0
- package/package.json +36 -4
- package/README.md +0 -3
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
// My availability (stage 45 step 7), for every rostered person: the times I said I cannot work
|
|
3
|
+
// (leave and other one-off times, and regular time off such as every Wednesday afternoon), to add
|
|
4
|
+
// and to end. Nobody approves it. Only I and whoever rosters ever see it: other staff see nothing,
|
|
5
|
+
// not even that I am away.
|
|
6
|
+
//
|
|
7
|
+
// When I add time off over shifts I am already on, they stay mine (the host lists them in its
|
|
8
|
+
// answer, and tells whoever rosters), and this offers them in one step. What I write about my time
|
|
9
|
+
// off (the note) is forgotten once the call is over and when I leave the page; it is read back only
|
|
10
|
+
// on this screen, and kept in the app's cache no longer than it is shown.
|
|
11
|
+
import { awayKind, awayWhen, forgetAfter, rosterRefusal, shiftTime, WEEKDAYS, } from "@composable-os/pack-rostering/client";
|
|
12
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
13
|
+
import { Button } from "../ui-button/button.js";
|
|
14
|
+
const EMPTY = {
|
|
15
|
+
kind: "leave",
|
|
16
|
+
startDate: "",
|
|
17
|
+
startTime: "00:00",
|
|
18
|
+
endDate: "",
|
|
19
|
+
endTime: "23:59",
|
|
20
|
+
weekdays: [],
|
|
21
|
+
fromDate: "",
|
|
22
|
+
untilDate: "",
|
|
23
|
+
note: "",
|
|
24
|
+
};
|
|
25
|
+
/** Forgets what was typed when the page is left, or brought back from the back-forward cache. */
|
|
26
|
+
function useForgetOnLeave(forget, cameBack) {
|
|
27
|
+
const latest = useRef({ forget, cameBack });
|
|
28
|
+
latest.current = { forget, cameBack };
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const hide = () => latest.current.forget();
|
|
31
|
+
const show = (event) => {
|
|
32
|
+
if (!event.persisted)
|
|
33
|
+
return;
|
|
34
|
+
latest.current.forget();
|
|
35
|
+
latest.current.cameBack();
|
|
36
|
+
};
|
|
37
|
+
window.addEventListener("pagehide", hide);
|
|
38
|
+
window.addEventListener("pageshow", show);
|
|
39
|
+
return () => {
|
|
40
|
+
window.removeEventListener("pagehide", hide);
|
|
41
|
+
window.removeEventListener("pageshow", show);
|
|
42
|
+
};
|
|
43
|
+
}, []);
|
|
44
|
+
}
|
|
45
|
+
/** What the form asks the host for (the host checks it, and says what is wrong). */
|
|
46
|
+
function inputOf(form) {
|
|
47
|
+
const note = form.note.trim() ? { note: form.note.trim() } : {};
|
|
48
|
+
if (form.kind === "regular") {
|
|
49
|
+
return {
|
|
50
|
+
kind: "regular",
|
|
51
|
+
weekdays: form.weekdays,
|
|
52
|
+
startTime: form.startTime,
|
|
53
|
+
endTime: form.endTime,
|
|
54
|
+
fromDate: form.fromDate,
|
|
55
|
+
...(form.untilDate ? { untilDate: form.untilDate } : {}),
|
|
56
|
+
...note,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
kind: form.kind,
|
|
61
|
+
startsAt: `${form.startDate}T${form.startTime}`,
|
|
62
|
+
endsAt: `${form.endDate}T${form.endTime}`,
|
|
63
|
+
...note,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export function MyAvailability({ rostering, locale = "en-AU", }) {
|
|
67
|
+
const me = rostering.useMe();
|
|
68
|
+
const list = rostering.useMyAway({});
|
|
69
|
+
const away = rostering.useAway();
|
|
70
|
+
const back = rostering.useBack();
|
|
71
|
+
const offer = rostering.useOffer();
|
|
72
|
+
const [form, setForm] = useState(EMPTY);
|
|
73
|
+
const [answer, setAnswer] = useState(null);
|
|
74
|
+
const [offered, setOffered] = useState([]);
|
|
75
|
+
const [refusal, setRefusal] = useState(null);
|
|
76
|
+
const [said, setSaid] = useState(null);
|
|
77
|
+
// Hidden when the page is left, and until it is read again when it comes back.
|
|
78
|
+
const [hidden, setHidden] = useState(false);
|
|
79
|
+
const id = useId();
|
|
80
|
+
useForgetOnLeave(() => {
|
|
81
|
+
setForm(EMPTY);
|
|
82
|
+
setAnswer(null);
|
|
83
|
+
setHidden(true);
|
|
84
|
+
}, () => void Promise.resolve(list.refetch?.()).then(() => setHidden(false)));
|
|
85
|
+
if (me.isPending)
|
|
86
|
+
return _jsx("p", { "aria-busy": "true", children: "Loading your availability\u2026" });
|
|
87
|
+
if (me.error || !me.data)
|
|
88
|
+
return _jsx("p", { role: "alert", children: rosterRefusal(me.error).message });
|
|
89
|
+
const zone = me.data.zone;
|
|
90
|
+
const set = (patch) => setForm((f) => ({ ...f, ...patch }));
|
|
91
|
+
async function submit(event) {
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
setRefusal(null);
|
|
94
|
+
setSaid(null);
|
|
95
|
+
setAnswer(null);
|
|
96
|
+
setOffered([]);
|
|
97
|
+
try {
|
|
98
|
+
const made = await forgetAfter(away, inputOf(form));
|
|
99
|
+
setAnswer(made);
|
|
100
|
+
setForm(EMPTY);
|
|
101
|
+
setSaid("Saved. Only you and whoever rosters can see it.");
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
setRefusal(rosterRefusal(error));
|
|
105
|
+
}
|
|
106
|
+
await list.refetch?.();
|
|
107
|
+
}
|
|
108
|
+
async function remove(itemId) {
|
|
109
|
+
setRefusal(null);
|
|
110
|
+
setSaid(null);
|
|
111
|
+
try {
|
|
112
|
+
await back.mutateAsync({ id: itemId });
|
|
113
|
+
setSaid("Removed.");
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
setRefusal(rosterRefusal(error));
|
|
117
|
+
}
|
|
118
|
+
await list.refetch?.();
|
|
119
|
+
}
|
|
120
|
+
async function offerShift(object, shiftId) {
|
|
121
|
+
setRefusal(null);
|
|
122
|
+
try {
|
|
123
|
+
await offer.mutateAsync({ object, id: shiftId });
|
|
124
|
+
setOffered((o) => [...o, shiftId]);
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
setRefusal(rosterRefusal(error));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const f = (name) => `${id}-${name}`;
|
|
131
|
+
return (_jsxs("section", { className: "grid gap-4", "aria-labelledby": f("h"), children: [_jsx("h2", { id: f("h"), className: "text-lg font-medium", children: "My availability" }), _jsxs("p", { className: "text-sm text-muted-foreground", children: ["Times are in ", zone, ". Only you and whoever rosters see this."] }), 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, answer?.count ? (_jsxs("section", { className: "grid gap-2 rounded-md border p-3", "aria-label": "Your shifts then", children: [_jsxs("p", { className: "text-sm", children: ["You are on ", answer.count, " shift", answer.count === 1 ? "" : "s", " then. They stay yours until someone takes them: offer them now?"] }), _jsx("ul", { className: "grid gap-1", children: answer.shifts.map((s) => (_jsxs("li", { className: "flex flex-wrap items-center justify-between gap-2 text-sm", children: [_jsxs("span", { children: [s.title, ", ", shiftTime(s, zone, { withDate: true, locale })] }), offered.includes(s.id) ? (_jsx("span", { children: "Offered" })) : (_jsx(Button, { type: "button", size: "sm", variant: "outline", disabled: offer.isPending, "aria-label": `Offer ${s.title}`, onClick: () => offerShift(s.object, s.id), children: "Offer" }))] }, s.id))) })] })) : null, _jsxs("form", { className: "grid gap-3 rounded-md border p-3", onSubmit: submit, "aria-label": "Add time off", children: [_jsxs("fieldset", { className: "grid gap-1", children: [_jsx("legend", { className: "text-sm font-medium", children: "What kind" }), ["leave", "other", "regular"].map((kind) => (_jsxs("label", { className: "flex items-center gap-2 text-sm", children: [_jsx("input", { type: "radio", name: f("kind"), checked: form.kind === kind, onChange: () => set({ kind }) }), kind === "leave"
|
|
132
|
+
? "Leave"
|
|
133
|
+
: kind === "other"
|
|
134
|
+
? "Another one-off time"
|
|
135
|
+
: "Every week"] }, kind)))] }), form.kind === "regular" ? (_jsxs(_Fragment, { children: [_jsxs("fieldset", { className: "flex flex-wrap gap-3", children: [_jsx("legend", { className: "text-sm font-medium", children: "Days" }), WEEKDAYS.map(([value, label]) => (_jsxs("label", { className: "flex items-center gap-1 text-sm", children: [_jsx("input", { type: "checkbox", checked: form.weekdays.includes(value), onChange: (e) => set({
|
|
136
|
+
weekdays: e.target.checked
|
|
137
|
+
? [...form.weekdays, value]
|
|
138
|
+
: form.weekdays.filter((d) => d !== value),
|
|
139
|
+
}) }), label] }, value)))] }), _jsxs("div", { className: "grid gap-2 sm:grid-cols-2", children: [_jsx(TextField, { id: f("st"), label: "From (time)", type: "time", value: form.startTime, onChange: (v) => set({ startTime: v }) }), _jsx(TextField, { id: f("et"), label: "Until (time)", type: "time", value: form.endTime, onChange: (v) => set({ endTime: v }) }), _jsx(TextField, { id: f("fd"), label: "Starting on", type: "date", value: form.fromDate, onChange: (v) => set({ fromDate: v }) }), _jsx(TextField, { id: f("ud"), label: "Ending on (optional)", type: "date", value: form.untilDate, onChange: (v) => set({ untilDate: v }) })] })] })) : (_jsxs("div", { className: "grid gap-2 sm:grid-cols-2", children: [_jsx(TextField, { id: f("sd"), label: "From (date)", type: "date", value: form.startDate, onChange: (v) => set({ startDate: v }) }), _jsx(TextField, { id: f("st1"), label: "From (time)", type: "time", value: form.startTime, onChange: (v) => set({ startTime: v }) }), _jsx(TextField, { id: f("ed"), label: "Until (date)", type: "date", value: form.endDate, onChange: (v) => set({ endDate: v }) }), _jsx(TextField, { id: f("et1"), label: "Until (time)", type: "time", value: form.endTime, onChange: (v) => set({ endTime: v }) })] })), _jsx(TextField, { id: f("note"), label: "Note (optional, seen by you and whoever rosters)", value: form.note, maxLength: 500, onChange: (v) => set({ note: v }) }), _jsx(Button, { type: "submit", disabled: away.isPending, children: "Add time off" })] }), _jsxs("section", { className: "grid gap-2", "aria-label": "My time off", children: [_jsx("h3", { className: "text-sm font-medium", children: "My time off" }), list.isPending || hidden ? _jsx("p", { "aria-busy": "true", children: "Loading\u2026" }) : null, list.error ? _jsx("p", { role: "alert", children: rosterRefusal(list.error).message }) : null, list.data && !hidden && !list.data.items.length ? (_jsx("p", { className: "text-sm", children: "None from today on." })) : null, !hidden ? (_jsx("ul", { className: "grid gap-2", children: (list.data?.items ?? []).map((item) => (_jsxs("li", { className: "flex flex-wrap items-center justify-between gap-2 rounded-md border p-2 text-sm", children: [_jsxs("span", { children: [_jsx("strong", { 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 ${awayKind(item.kind).toLowerCase()}: ${awayWhen(item, locale)}`, onClick: () => remove(item.id), children: "End" })] }, item.id))) })) : null] })] }));
|
|
140
|
+
}
|
|
141
|
+
function TextField({ id, label, value, onChange, type = "text", maxLength, }) {
|
|
142
|
+
return (_jsxs("div", { className: "grid gap-1", children: [_jsx("label", { htmlFor: id, className: "text-sm", children: label }), _jsx("input", { id: id, type: type, value: value, maxLength: maxLength, autoComplete: "off", className: "rounded-md border border-input px-2 py-1 text-sm", onChange: (e) => onChange(e.target.value) })] }));
|
|
143
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type RosteringHooks } from "@composable-os/pack-rostering/client";
|
|
2
|
+
type Hooks = Pick<RosteringHooks, "useFeed" | "useFeedRotate" | "useFeedRevoke">;
|
|
3
|
+
export declare function MyCalendar({ rostering }: {
|
|
4
|
+
rostering: Hooks;
|
|
5
|
+
}): import("react").JSX.Element;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
// My calendar (stage 45 step 7, over step 5's feed, ADR 0628), for every rostered person: whether
|
|
3
|
+
// I have a private calendar address for my own shifts, making one (or a new one, which stops the
|
|
4
|
+
// old), and switching it off. The address is shown once, as the host gives it: copied, or opened
|
|
5
|
+
// in a calendar app ("Add to calendar", a webcal link), on the host the screen's client talks to; it is never stored here, never put in a
|
|
6
|
+
// URL of this app, and cleared when the page is left or brought back from the back-forward cache.
|
|
7
|
+
// The host keeps only its hash, so a lost address is never shown again: the person makes a new one.
|
|
8
|
+
//
|
|
9
|
+
// Everything is the host's: whether a feed exists, the address, who may make one (the person
|
|
10
|
+
// themselves), and each refusal, including a retried request whose answer the host never keeps
|
|
11
|
+
// (`address_lost`: a new address was made but cannot be shown; make another).
|
|
12
|
+
import { forgetAfter, rosterRefusal, } from "@composable-os/pack-rostering/client";
|
|
13
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
14
|
+
import { Button } from "../ui-button/button.js";
|
|
15
|
+
/** Clears what is shown when the page is left, and when it comes back from the back-forward cache. */
|
|
16
|
+
function useForgetOnLeave(forget) {
|
|
17
|
+
const latest = useRef(forget);
|
|
18
|
+
latest.current = forget;
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const hide = () => latest.current();
|
|
21
|
+
const show = (event) => {
|
|
22
|
+
if (event.persisted)
|
|
23
|
+
latest.current();
|
|
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 MyCalendar({ rostering }) {
|
|
34
|
+
const feed = rostering.useFeed();
|
|
35
|
+
const rotate = rostering.useFeedRotate();
|
|
36
|
+
const revoke = rostering.useFeedRevoke();
|
|
37
|
+
const [address, setAddress] = useState(null);
|
|
38
|
+
const [confirm, setConfirm] = useState(null);
|
|
39
|
+
const [refusal, setRefusal] = useState(null);
|
|
40
|
+
const [said, setSaid] = useState(null);
|
|
41
|
+
const id = useId();
|
|
42
|
+
useForgetOnLeave(() => {
|
|
43
|
+
setAddress(null);
|
|
44
|
+
setSaid(null);
|
|
45
|
+
});
|
|
46
|
+
// Gone from the screen, gone: nothing of it outlives the block.
|
|
47
|
+
useEffect(() => () => setAddress(null), []);
|
|
48
|
+
async function make() {
|
|
49
|
+
setConfirm(null);
|
|
50
|
+
setRefusal(null);
|
|
51
|
+
setSaid(null);
|
|
52
|
+
setAddress(null);
|
|
53
|
+
try {
|
|
54
|
+
const made = await forgetAfter(rotate, {});
|
|
55
|
+
setAddress({ https: made.https, webcal: made.webcal });
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
setRefusal(rosterRefusal(error));
|
|
59
|
+
}
|
|
60
|
+
await feed.refetch?.();
|
|
61
|
+
}
|
|
62
|
+
async function off() {
|
|
63
|
+
setConfirm(null);
|
|
64
|
+
setRefusal(null);
|
|
65
|
+
setAddress(null);
|
|
66
|
+
try {
|
|
67
|
+
await revoke.mutateAsync({});
|
|
68
|
+
setSaid("Switched off: the address no longer works. Your calendar keeps what it last fetched.");
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
setRefusal(rosterRefusal(error));
|
|
72
|
+
}
|
|
73
|
+
await feed.refetch?.();
|
|
74
|
+
}
|
|
75
|
+
async function copy() {
|
|
76
|
+
if (!address)
|
|
77
|
+
return;
|
|
78
|
+
try {
|
|
79
|
+
await navigator.clipboard.writeText(address.https);
|
|
80
|
+
setSaid("Copied. Paste it where your calendar app adds a calendar by address.");
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
setSaid("Select the address and copy it.");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const state = feed.data;
|
|
87
|
+
return (_jsxs("section", { className: "grid gap-3", "aria-labelledby": `${id}-h`, children: [_jsx("h2", { id: `${id}-h`, className: "text-lg font-medium", children: "My calendar" }), _jsx("p", { className: "text-sm text-muted-foreground", children: "A private address your phone's calendar subscribes to: your own shifts, kept up to date. Anyone with the address sees your shifts, so do not share it. Calendar apps fetch it on their own schedule, often hours apart: this app is always the latest." }), feed.isPending ? _jsx("p", { "aria-busy": "true", children: "Loading\u2026" }) : null, feed.error ? _jsx("p", { role: "alert", children: rosterRefusal(feed.error).message }) : null, refusal ? (_jsx("p", { role: "alert", className: "text-sm", "data-refusal": refusal.kind, children: refusal.message })) : null, said ? (_jsx("p", { role: "status", className: "text-sm", children: said })) : null, address ? (_jsxs("div", { className: "grid gap-2 rounded-md border p-3", "data-testid": "feed-address", children: [_jsx("label", { htmlFor: `${id}-a`, className: "text-sm font-medium", children: "Your calendar address (shown this once)" }), _jsx("input", { id: `${id}-a`, readOnly: true, value: address.https, className: "w-full rounded-md border border-input px-2 py-1 font-mono text-xs", autoComplete: "off", onFocus: (e) => e.currentTarget.select() }), _jsxs("div", { className: "flex flex-wrap gap-2", children: [_jsx(Button, { type: "button", onClick: copy, children: "Copy the address" }), _jsx(Button, { asChild: true, variant: "outline", children: _jsx("a", { href: address.webcal, rel: "noreferrer noopener", children: "Add to calendar" }) }), _jsx(Button, { type: "button", variant: "outline", onClick: () => setAddress(null), children: "Done" })] }), _jsx("p", { className: "text-xs text-muted-foreground", children: "It is not kept here. Lost it? Make a new address: the old one stops working." })] })) : null, state && !address ? (_jsx("p", { className: "text-sm", "data-feed": state.active ? "on" : "off", children: state.active
|
|
88
|
+
? `You have a calendar address${state.createdAt ? `, made ${new Date(state.createdAt).toLocaleDateString()}` : ""}.`
|
|
89
|
+
: "You have no calendar address." })) : null, state ? (confirm ? (_jsxs("div", { role: "alertdialog", "aria-label": confirm === "replace" ? "Make a new address" : "Switch it off", className: "grid gap-2 rounded-md border p-2", children: [_jsx("p", { className: "text-sm", children: confirm === "replace"
|
|
90
|
+
? "Make a new address? The one you have stops working, in every calendar that uses it."
|
|
91
|
+
: "Switch it off? The address stops working; your calendar keeps what it last fetched." }), _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { type: "button", disabled: rotate.isPending || revoke.isPending, onClick: confirm === "replace" ? make : off, children: confirm === "replace" ? "Make a new address" : "Switch it off" }), _jsx(Button, { type: "button", variant: "outline", onClick: () => setConfirm(null), children: "Keep it" })] })] })) : (_jsx("div", { className: "flex flex-wrap gap-2", children: state.active ? (_jsxs(_Fragment, { children: [_jsx(Button, { type: "button", variant: "outline", onClick: () => setConfirm("replace"), children: "Make a new address\u2026" }), _jsx(Button, { type: "button", variant: "outline", onClick: () => setConfirm("off"), children: "Switch it off\u2026" })] })) : (_jsx(Button, { type: "button", disabled: rotate.isPending, onClick: make, children: "Make my calendar address" })) }))) : null] }));
|
|
92
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type RosteringHooks } from "@composable-os/pack-rostering/client";
|
|
2
|
+
export type MyHoursHooks = Pick<RosteringHooks, "useMyPayPeriods" | "useMyPay">;
|
|
3
|
+
export declare function MyHours({ rostering, locale, }: {
|
|
4
|
+
rostering: MyHoursHooks;
|
|
5
|
+
locale?: string;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
// My hours (stage 45, the owner's decision of 2026-11-24), a part of My shifts: my own hours and
|
|
3
|
+
// shifts for a pay period, as payroll is given them. Hours and counts only: no money anywhere.
|
|
4
|
+
//
|
|
5
|
+
// Everything is the host's answer: which periods there are (the current one and twelve before
|
|
6
|
+
// it), whether I am counted for pay and how, my totals per kind of work and each of my shifts with
|
|
7
|
+
// its minutes (a locked period's locked figures, or a preview of an open one), and each refusal.
|
|
8
|
+
// Nothing about anyone else, and not why a shift was marked not worked (whoever rosters keeps
|
|
9
|
+
// that), only that it was. The figures are fetched only when I pick a period, are kept in the
|
|
10
|
+
// app's cache no longer than they are shown (`gcTime: 0`), are hidden when the page is left (and
|
|
11
|
+
// read again when the browser brings it back), and are never put in an address or stored. It
|
|
12
|
+
// announces nothing on its own (no live region): it sits under My shifts, whose own messages do.
|
|
13
|
+
import { basisLabel, dayLabel, payPeriodState, refusalNext, rosterRefusal, } from "@composable-os/pack-rostering/client";
|
|
14
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
15
|
+
/** Hides what is shown when the page is left; shows it again only once read again. */
|
|
16
|
+
function useForgetOnLeave(forget, cameBack) {
|
|
17
|
+
const latest = useRef({ forget, cameBack });
|
|
18
|
+
latest.current = { forget, cameBack };
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const hide = () => latest.current.forget();
|
|
21
|
+
const show = (event) => {
|
|
22
|
+
if (!event.persisted)
|
|
23
|
+
return;
|
|
24
|
+
latest.current.forget();
|
|
25
|
+
latest.current.cameBack();
|
|
26
|
+
};
|
|
27
|
+
window.addEventListener("pagehide", hide);
|
|
28
|
+
window.addEventListener("pageshow", show);
|
|
29
|
+
return () => {
|
|
30
|
+
window.removeEventListener("pagehide", hide);
|
|
31
|
+
window.removeEventListener("pageshow", show);
|
|
32
|
+
};
|
|
33
|
+
}, []);
|
|
34
|
+
}
|
|
35
|
+
export function MyHours({ rostering, locale = "en-AU", }) {
|
|
36
|
+
const [hidden, setHidden] = useState(false);
|
|
37
|
+
const periods = rostering.useMyPayPeriods(!hidden);
|
|
38
|
+
const [chosen, setChosen] = useState(null);
|
|
39
|
+
const headingId = useId();
|
|
40
|
+
useForgetOnLeave(() => {
|
|
41
|
+
setHidden(true);
|
|
42
|
+
setChosen(null);
|
|
43
|
+
}, () => setHidden(false));
|
|
44
|
+
const period = periods.data?.periods.find((p) => p.start === chosen) ?? null;
|
|
45
|
+
return (_jsxs("section", { className: "grid gap-3", "aria-labelledby": headingId, children: [_jsx("h3", { id: headingId, className: "text-base font-medium", children: "My hours" }), _jsx("p", { className: "text-sm text-muted-foreground", children: "Your own hours and shifts for each pay period, as payroll is given them. Only you see this here." }), hidden || periods.isPending ? _jsx("p", { "aria-busy": "true", children: "Loading the pay periods\u2026" }) : null, !hidden && periods.error ? (_jsx(PeriodsRefusal, { error: periods.error, onRetry: () => periods.refetch?.() })) : null, !hidden && periods.data && !periods.data.set ? (_jsx("p", { "data-refusal": "pay_period_unset", children: "Pay periods are not set up yet, so there are no hours to show." })) : null, !hidden && periods.data?.set ? (_jsx("ul", { className: "grid gap-2 sm:grid-cols-2", "aria-label": "Pay periods", children: periods.data.periods.map((p) => (_jsx("li", { children: _jsxs("button", { type: "button", className: "block w-full rounded-md border p-2 text-left text-sm", "aria-pressed": chosen === p.start, "data-start": p.start, "aria-label": `${dayLabel(p.start, locale)} to ${dayLabel(p.end, locale)}, ${payPeriodState(p)}`, onClick: () => setChosen(chosen === p.start ? null : p.start), children: [_jsxs("span", { className: "block font-medium", children: [dayLabel(p.start, locale), " \u2013 ", dayLabel(p.end, locale)] }), _jsx("span", { className: "block text-xs", children: payPeriodState(p) })] }) }, p.start))) })) : null, !hidden && period ? (_jsx(PeriodHours, { rostering: rostering, period: period, locale: locale }, period.start)) : null] }));
|
|
46
|
+
}
|
|
47
|
+
function PeriodsRefusal({ error, onRetry }) {
|
|
48
|
+
const refusal = rosterRefusal(error);
|
|
49
|
+
return (_jsxs("div", { role: "alert", className: "grid gap-1 text-sm", "data-refusal": refusal.kind, children: [_jsx("p", { children: refusal.kind === "human_only"
|
|
50
|
+
? "Your hours are shown to you only, at the screen."
|
|
51
|
+
: refusal.message }), refusal.kind === "network" || refusal.kind === "other" ? (_jsx("p", { children: _jsx("button", { type: "button", className: "underline", onClick: onRetry, children: "Try again" }) })) : null] }));
|
|
52
|
+
}
|
|
53
|
+
function PeriodHours({ rostering, period, locale, }) {
|
|
54
|
+
const mine = rostering.useMyPay({ start: period.start });
|
|
55
|
+
const id = useId();
|
|
56
|
+
const data = mine.data;
|
|
57
|
+
const refusal = mine.error ? rosterRefusal(mine.error) : null;
|
|
58
|
+
return (_jsxs("section", { className: "grid gap-3 rounded-md border p-3", "aria-labelledby": `${id}-h`, "aria-busy": mine.isPending, children: [_jsxs("h4", { id: `${id}-h`, className: "font-medium", children: [dayLabel(period.start, locale, true), " to ", dayLabel(period.end, locale, true)] }), mine.isPending ? _jsx("p", { "aria-busy": "true", children: "Loading your hours\u2026" }) : null, refusal ? (_jsxs("div", { role: "alert", className: "text-sm", "data-refusal": refusal.kind, children: [_jsx("p", { children: refusal.message }), refusalNext(refusal.kind, false) ? _jsx("p", { children: refusalNext(refusal.kind, false) }) : null, refusal.kind === "network" || refusal.kind === "other" ? (_jsx("p", { children: _jsx("button", { type: "button", className: "underline", onClick: () => mine.refetch?.(), children: "Try again" }) })) : null] })) : null, data && !data.counted ? (_jsx("p", { "data-state": "not-counted", children: "You are not counted for pay in this period, so there are no hours to show. If you think you should be, ask whoever handles pay." })) : null, data?.counted ? (_jsxs(_Fragment, { children: [_jsx("p", { className: "text-sm", "data-state": data.period.preview ? "preview" : "locked", children: data.period.preview
|
|
59
|
+
? "A preview from the roster as it stands: it can change until the period is locked."
|
|
60
|
+
: `Locked: these are the figures payroll was given${data.period.version && data.period.version > 1 ? ` (version ${data.period.version})` : ""}.` }), _jsxs("p", { className: "text-sm", children: ["Counted: ", basisLabel(data.basis)] }), data.totals.length ? (_jsx("div", { className: "max-w-full overflow-x-auto", children: _jsxs("table", { className: "text-sm", "aria-label": "My hours and shifts", children: [_jsx("thead", { children: _jsxs("tr", { className: "text-left", children: [_jsx("th", { scope: "col", className: "p-1", children: "Kind of work" }), _jsx("th", { scope: "col", className: "p-1", children: "Shifts" }), _jsx("th", { scope: "col", className: "p-1", children: "Hours" }), _jsx("th", { scope: "col", className: "p-1", children: "Not worked" })] }) }), _jsx("tbody", { children: data.totals.map((t) => (_jsxs("tr", { className: "border-t", children: [_jsx("th", { scope: "row", className: "p-1 text-left font-normal", children: t.kindName }), _jsx("td", { className: "p-1", children: t.shifts }), _jsx("td", { className: "p-1", children: t.hours }), _jsx("td", { className: "p-1", children: t.notWorked })] }, `${t.basis}:${t.kind?.id ?? t.kindName}`))) })] }) })) : (_jsx("p", { className: "text-sm", children: "You have no counted shifts in this period." })), _jsxs("p", { className: "text-sm font-medium", children: ["All my hours: ", data.hours] }), data.lines.length ? (_jsxs("details", { children: [_jsx("summary", { className: "cursor-pointer text-sm", children: "Each of my shifts" }), _jsx("ul", { className: "grid gap-1 text-sm", children: data.lines.map((l) => (_jsxs("li", { className: "border-t pt-1", "data-not-worked": l.notWorked ? "true" : undefined, children: [_jsx("span", { className: "font-medium", children: l.title }), ", ", dayLabel(l.localDate, locale), " ", l.localStart.slice(11, 16), "\u2013", l.localEnd.slice(11, 16), l.place ? ` · ${l.place}` : "", " · ", l.notWorked
|
|
61
|
+
? "Marked not worked: counts for nothing. Ask whoever rosters why."
|
|
62
|
+
: `${l.countedMinutes} minutes${l.beforeMinutes || l.afterMinutes ? ` (with ${l.beforeMinutes + l.afterMinutes} minutes of set-up and pack-down)` : ""}`, l.clockChange ? _jsx("span", { className: "block text-xs", children: l.clockChange }) : null, l.flagged ? (_jsx("span", { className: "block text-xs", children: "Its list was taken by someone else: whoever handles pay checks it." })) : null] }, `${l.object}:${l.id}`))) })] })) : null] })) : null] }));
|
|
63
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type RosteringHooks, type RosterShift } from "@composable-os/pack-rostering/client";
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
import { type MyHoursHooks } from "./my-hours.tsx";
|
|
4
|
+
type Hooks = Pick<RosteringHooks, "useMe" | "useMine" | "useOffers" | "useOffer" | "useWithdraw"> & MyHoursHooks;
|
|
5
|
+
export declare function MyShifts({ rostering, from, days, locale, calendar, shiftExtra, }: {
|
|
6
|
+
rostering: Hooks;
|
|
7
|
+
/** The first date; today in the business's zone by default. */
|
|
8
|
+
from?: string;
|
|
9
|
+
/** How many days ahead (at most 62). */
|
|
10
|
+
days?: number;
|
|
11
|
+
locale?: string;
|
|
12
|
+
/** My calendar's address and its buttons (the calendar feed block, once step 5 is built). */
|
|
13
|
+
calendar?: ReactNode;
|
|
14
|
+
/** Something to show under a shift (its checklist: rostering-checklist's ShiftChecklist). */
|
|
15
|
+
shiftExtra?: (shift: RosterShift) => ReactNode;
|
|
16
|
+
}): import("react").JSX.Element;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// My shifts (stage 45 step 7), for every rostered person: my shifts over the next weeks, day by
|
|
3
|
+
// day, each with its time in the business's zone, its place, and a button to offer it to everyone
|
|
4
|
+
// who could take it, or to withdraw my open offer. An offered shift stays mine (in my list and my
|
|
5
|
+
// pay) until someone takes it; the host says so, and refuses an offer it would not let through
|
|
6
|
+
// (nobody else qualified, past the cut-off, already offered), each with its own state here.
|
|
7
|
+
//
|
|
8
|
+
// Room is left for what later steps add: a duty shift's checklist under the shift (`shiftExtra`,
|
|
9
|
+
// step 4b) and my calendar's address above the list (`calendar`, step 5). Under the list, My hours
|
|
10
|
+
// (my-hours.tsx, the owner's decision of 2026-11-24): my own hours for a pay period, fetched only
|
|
11
|
+
// when I pick one.
|
|
12
|
+
import { addDays, dateIn, dayLabel, refusalNext, rosterRefusal, shiftName, shiftTime, } from "@composable-os/pack-rostering/client";
|
|
13
|
+
import { useId, useState } from "react";
|
|
14
|
+
import { Button } from "../ui-button/button.js";
|
|
15
|
+
import { MyHours } from "./my-hours.js";
|
|
16
|
+
export function MyShifts({ rostering, from, days = 28, locale = "en-AU", calendar, shiftExtra, }) {
|
|
17
|
+
const me = rostering.useMe();
|
|
18
|
+
const first = from ?? me.data?.today ?? null;
|
|
19
|
+
const mine = rostering.useMine({ from: first ?? "", to: first ? addDays(first, Math.min(days, 62) - 1) : "" }, first !== null);
|
|
20
|
+
const offers = rostering.useOffers();
|
|
21
|
+
const offer = rostering.useOffer();
|
|
22
|
+
const withdraw = rostering.useWithdraw();
|
|
23
|
+
const [refusal, setRefusal] = useState(null);
|
|
24
|
+
const [said, setSaid] = useState(null);
|
|
25
|
+
const headingId = useId();
|
|
26
|
+
if (me.isPending)
|
|
27
|
+
return _jsx("p", { "aria-busy": "true", children: "Loading your shifts\u2026" });
|
|
28
|
+
if (me.error || !me.data)
|
|
29
|
+
return _jsx("p", { role: "alert", children: rosterRefusal(me.error).message });
|
|
30
|
+
const zone = mine.data?.zone ?? me.data.zone;
|
|
31
|
+
const busy = offer.isPending || withdraw.isPending;
|
|
32
|
+
async function act(id, what, done) {
|
|
33
|
+
setRefusal(null);
|
|
34
|
+
setSaid(null);
|
|
35
|
+
try {
|
|
36
|
+
await what();
|
|
37
|
+
setSaid(done);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
setRefusal({ id, refusal: rosterRefusal(error) });
|
|
41
|
+
}
|
|
42
|
+
await Promise.all([mine.refetch?.(), offers.refetch?.()]);
|
|
43
|
+
}
|
|
44
|
+
const shifts = mine.data?.shifts ?? [];
|
|
45
|
+
const byDate = new Map();
|
|
46
|
+
for (const s of shifts) {
|
|
47
|
+
const date = dateIn(s.startsAt, zone);
|
|
48
|
+
byDate.set(date, [...(byDate.get(date) ?? []), s]);
|
|
49
|
+
}
|
|
50
|
+
return (_jsxs("section", { className: "grid gap-4", "aria-labelledby": headingId, children: [_jsx("h2", { id: headingId, className: "text-lg font-medium", children: "My shifts" }), calendar, _jsxs("p", { className: "text-sm text-muted-foreground", children: ["Times are in ", zone, ". Offers close ", me.data.cutoffMinutes, " minutes before a shift starts."] }), said ? (_jsx("p", { role: "status", className: "text-sm", children: said })) : null, mine.isPending ? _jsx("p", { "aria-busy": "true", children: "Loading your shifts\u2026" }) : null, mine.error ? _jsx("p", { role: "alert", children: rosterRefusal(mine.error).message }) : null, mine.data?.truncated ? (_jsx("p", { role: "status", className: "text-sm", children: "You have more shifts than one screen shows: the first ones are shown." })) : null, mine.data && !shifts.length ? _jsxs("p", { children: ["You have no shifts in the next ", days, " days."] }) : null, _jsx("ol", { className: "grid gap-3", "aria-label": "Days", children: [...byDate.entries()].map(([date, list]) => (_jsxs("li", { className: "grid gap-2", children: [_jsx("h3", { className: "text-sm font-medium", children: dayLabel(date, locale, true) }), _jsx("ul", { className: "grid gap-2", children: list.map((shift) => (_jsxs("li", { className: "grid gap-1 rounded-md border p-3", "aria-label": shiftName(shift, zone, locale), "data-shift": shift.id, children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [_jsxs("div", { children: [_jsx("p", { className: "font-medium", children: shift.title }), _jsxs("p", { className: "text-sm text-muted-foreground", children: [shiftTime(shift, zone, { locale }), shift.place ? ` · ${shift.place}` : ""] }), shift.offer ? (_jsx("p", { className: "text-sm", children: "Offered: still yours until someone takes it." })) : null] }), shift.offer ? (_jsx(Button, { type: "button", variant: "outline", disabled: busy, "aria-label": `Withdraw the offer of ${shift.title}`, onClick: () => act(shift.id, () => withdraw.mutateAsync({ offer: shift.offer?.id ?? "" }), "Offer withdrawn: the shift is still yours."), children: "Withdraw offer" })) : (_jsx(Button, { type: "button", variant: "outline", disabled: busy, "aria-label": `Offer ${shift.title} for someone else to take`, onClick: () => act(shift.id, () => offer.mutateAsync({ object: shift.object, id: shift.id }), "Offered to everyone who could take it. It stays yours until someone does."), children: "Offer" }))] }), refusal?.id === shift.id ? (_jsxs("div", { role: "alert", className: "text-sm", "data-refusal": refusal.refusal.kind, children: [_jsx("p", { children: refusal.refusal.message }), refusalNext(refusal.refusal.kind, me.data?.rosters ?? false) ? (_jsx("p", { children: refusalNext(refusal.refusal.kind, me.data?.rosters ?? false) })) : null] })) : null, shiftExtra?.(shift)] }, shift.id))) })] }, date))) }), offers.data?.mine.length ? (_jsxs("section", { className: "grid gap-2", "aria-label": "My open offers", children: [_jsx("h3", { className: "text-sm font-medium", children: "My open offers" }), _jsx("ul", { className: "grid gap-1 text-sm", children: offers.data.mine.map((o) => (_jsxs("li", { children: [o.shift.title, ", ", shiftTime(o.shift, zone, { withDate: true, locale }), o.to ? " (to one person)" : "", o.closesAt
|
|
51
|
+
? ` · closes ${shiftTime({ startsAt: o.closesAt, endsAt: null }, zone, { withDate: true, locale })}`
|
|
52
|
+
: ""] }, o.id))) })] })) : null, _jsx(MyHours, { rostering: rostering, locale: locale })] }));
|
|
53
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
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 ShiftChecklistNative({ rostering, shift, locale, zone, }: {
|
|
4
|
+
rostering: ChecklistHooks;
|
|
5
|
+
shift: RosterShift;
|
|
6
|
+
locale?: string;
|
|
7
|
+
zone?: string;
|
|
8
|
+
}): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// A shift's checklist in the app (stage 45 step 4b, ADR 0650), for the native my-shifts'
|
|
3
|
+
// `shiftExtra` slot: the same as the web's, over the native base. The shift's person ticks each
|
|
4
|
+
// step off (done, with a note where the step asks for one; not done, with why) and marks it done,
|
|
5
|
+
// which is final; whoever rosters may tick it for them, saying why, kept as ticked by them for that
|
|
6
|
+
// person. The host decides whose it is, when it may be ticked and whether it is complete: this
|
|
7
|
+
// shows its answer and its refusals.
|
|
8
|
+
//
|
|
9
|
+
// What someone writes on a step is private: kept only in this screen's state, sent with
|
|
10
|
+
// `forgetAfter`, and cleared when the app goes to the background (so the app switcher's snapshot
|
|
11
|
+
// never shows it). The checklist is fetched only when opened, and kept no longer than it is shown.
|
|
12
|
+
import { checklistStateLabel, forgetAfter, refusalNext, rosterRefusal, shiftTime, tickLabel, } from "@composable-os/pack-rostering/client";
|
|
13
|
+
import { useEffect, useState } from "react";
|
|
14
|
+
import { AppState, View } from "react-native";
|
|
15
|
+
import { Button } from "../native-base/button.js";
|
|
16
|
+
import { Field } from "../native-base/field.js";
|
|
17
|
+
import { Text } from "../native-base/text.js";
|
|
18
|
+
const EMPTY = { note: "", why: "", notDone: false };
|
|
19
|
+
export function ShiftChecklistNative({ rostering, shift, locale = "en-AU", zone, }) {
|
|
20
|
+
const [open, setOpen] = useState(false);
|
|
21
|
+
const answer = rostering.useChecklist(open ? { object: shift.object, id: shift.id } : null);
|
|
22
|
+
const tick = rostering.useTick();
|
|
23
|
+
const done = rostering.useChecklistDone();
|
|
24
|
+
const [drafts, setDrafts] = useState({});
|
|
25
|
+
const [forWhy, setForWhy] = useState("");
|
|
26
|
+
const [refusal, setRefusal] = useState(null);
|
|
27
|
+
const [said, setSaid] = useState(null);
|
|
28
|
+
const [hidden, setHidden] = useState(false);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const listener = AppState.addEventListener("change", (state) => {
|
|
31
|
+
if (state !== "active") {
|
|
32
|
+
setDrafts({});
|
|
33
|
+
setForWhy("");
|
|
34
|
+
setHidden(true);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
void Promise.resolve(answer.refetch?.()).then(() => setHidden(false));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return () => listener.remove();
|
|
41
|
+
}, [answer.refetch]);
|
|
42
|
+
if (!shift.checklist)
|
|
43
|
+
return null;
|
|
44
|
+
const busy = tick.isPending || done.isPending;
|
|
45
|
+
const data = hidden ? undefined : answer.data;
|
|
46
|
+
const run = data?.run ?? null;
|
|
47
|
+
const editable = Boolean(data?.canTick) && (run === null || run.state === "open");
|
|
48
|
+
// Someone else's tick is changed only by whoever rosters (the host refuses it otherwise).
|
|
49
|
+
const mayChange = (step) => !step.tick || step.tick.by === data?.you || data?.youRoster === true;
|
|
50
|
+
const onBehalf = Boolean(data?.onBehalf);
|
|
51
|
+
const tz = shift.zone ?? zone ?? "UTC";
|
|
52
|
+
const draftOf = (p) => drafts[p] ?? EMPTY;
|
|
53
|
+
const setDraft = (p, patch) => setDrafts((d) => ({ ...d, [p]: { ...(d[p] ?? EMPTY), ...patch } }));
|
|
54
|
+
async function act(step, what, words) {
|
|
55
|
+
setRefusal(null);
|
|
56
|
+
setSaid(null);
|
|
57
|
+
try {
|
|
58
|
+
await what();
|
|
59
|
+
setSaid(words);
|
|
60
|
+
if (step !== null)
|
|
61
|
+
setDrafts((d) => ({ ...d, [step]: EMPTY }));
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
setRefusal({ step, refusal: rosterRefusal(error) });
|
|
65
|
+
}
|
|
66
|
+
await answer.refetch?.();
|
|
67
|
+
}
|
|
68
|
+
const tickStep = (position, state) => {
|
|
69
|
+
const d = draftOf(position);
|
|
70
|
+
return act(position, () => forgetAfter(tick, {
|
|
71
|
+
object: shift.object,
|
|
72
|
+
id: shift.id,
|
|
73
|
+
step: position,
|
|
74
|
+
state,
|
|
75
|
+
...(state === "done" && d.note.trim() ? { note: d.note.trim() } : {}),
|
|
76
|
+
...(state === "not_done" && d.why.trim() ? { why: d.why.trim() } : {}),
|
|
77
|
+
...(onBehalf && forWhy.trim() ? { forWhy: forWhy.trim() } : {}),
|
|
78
|
+
}), state === "clear" ? "Tick cleared." : "Ticked.");
|
|
79
|
+
};
|
|
80
|
+
const steps = run?.steps ??
|
|
81
|
+
(data?.preview ?? []).map((s, position) => ({
|
|
82
|
+
...s,
|
|
83
|
+
position,
|
|
84
|
+
tick: null,
|
|
85
|
+
history: [],
|
|
86
|
+
missed: false,
|
|
87
|
+
}));
|
|
88
|
+
const state = run ? run.state : (shift.checklist.state ?? null);
|
|
89
|
+
const alert = (r) => {
|
|
90
|
+
const next = refusalNext(r.kind, false);
|
|
91
|
+
return (_jsxs(Text, { accessibilityRole: "alert", children: [r.message, next ? ` ${next}` : ""] }));
|
|
92
|
+
};
|
|
93
|
+
return (_jsxs(View, { children: [_jsxs(Text, { accessibilityRole: "header", children: ["Checklist: ", shift.checklist.name, state ? ` · ${checklistStateLabel(state)}` : ""] }), _jsx(Button, { label: open ? "Close checklist" : `Open the checklist of ${shift.title}`, quiet: true, onPress: () => {
|
|
94
|
+
setOpen((o) => !o);
|
|
95
|
+
setRefusal(null);
|
|
96
|
+
setSaid(null);
|
|
97
|
+
} }), open ? (_jsxs(View, { children: [answer.isPending || hidden ? (_jsx(Text, { tone: "muted", accessibilityRole: "progressbar", children: "Loading the checklist\u2026" })) : null, answer.error ? alert(rosterRefusal(answer.error)) : null, data?.tickUntil && editable ? (_jsxs(Text, { children: ["Tick it off until", " ", shiftTime({ startsAt: data.tickUntil, endsAt: null }, tz, {
|
|
98
|
+
withDate: true,
|
|
99
|
+
locale,
|
|
100
|
+
}), "."] })) : null, run && run.state !== "open" ? (_jsxs(Text, { children: ["This checklist is ", checklistStateLabel(run.state).toLowerCase(), ": it does not change."] })) : null, editable && onBehalf ? (_jsxs(View, { children: [_jsxs(Text, { children: ["You are ticking this for ", data?.forName ?? "the person on the shift", "."] }), _jsx(Field, { label: "Why you are ticking it for them", value: forWhy, maxLength: 500, onChangeText: setForWhy })] })) : null, steps.map((step) => {
|
|
101
|
+
const d = draftOf(step.position);
|
|
102
|
+
return (_jsxs(View, { accessible: false, children: [_jsxs(Text, { children: [step.text, " (", step.required ? "required" : "optional", step.asksNote ? ", asks for a note" : "", ")"] }), step.tick ? _jsx(Text, { children: tickLabel(step.tick) }) : null, step.tick?.why ? _jsxs(Text, { children: ["Why: ", step.tick.why] }) : null, step.tick?.note ? _jsxs(Text, { children: ["Note: ", step.tick.note] }) : null, step.history.map((h) => (_jsxs(Text, { children: ["Earlier: ", tickLabel(h), h.why ? ` · Why: ${h.why}` : "", h.note ? ` · Note: ${h.note}` : ""] }, h.id))), step.missed ? _jsx(Text, { children: "Missed" }) : null, editable && mayChange(step) ? (_jsxs(View, { children: [_jsx(Field, { label: step.asksNote ? `Note on ${step.text} (needed)` : `Note on ${step.text}`, value: d.note, maxLength: 1000, onChangeText: (note) => setDraft(step.position, { note }) }), d.notDone ? (_jsx(Field, { label: `Why ${step.text} was not done`, value: d.why, maxLength: 500, onChangeText: (why) => setDraft(step.position, { why }) })) : null, _jsx(Button, { label: `Tick ${step.text} done`, busy: busy, onPress: () => tickStep(step.position, "done") }), _jsx(Button, { label: d.notDone ? `Save ${step.text} as not done` : `${step.text}: not done`, quiet: true, busy: busy, onPress: () => d.notDone
|
|
103
|
+
? tickStep(step.position, "not_done")
|
|
104
|
+
: setDraft(step.position, { notDone: true }) }), step.tick ? (_jsx(Button, { label: `Clear the tick of ${step.text}`, quiet: true, busy: busy, onPress: () => tickStep(step.position, "clear") })) : null] })) : null, refusal?.step === step.position ? alert(refusal.refusal) : null] }, step.position));
|
|
105
|
+
}), editable ? (_jsx(Button, { label: "Mark the checklist done", busy: busy, onPress: () => act(null, () => forgetAfter(done, {
|
|
106
|
+
object: shift.object,
|
|
107
|
+
id: shift.id,
|
|
108
|
+
...(onBehalf && forWhy.trim() ? { forWhy: forWhy.trim() } : {}),
|
|
109
|
+
}), "Done. It does not change now.") })) : null, run?.corrections.map((c) => (_jsxs(Text, { children: ["Correction: ", c.text, " (", c.byName, ")"] }, c.id))), said ? _jsx(Text, { accessibilityRole: "alert", children: said }) : null, refusal && refusal.step === null ? alert(refusal.refusal) : null] })) : null] }));
|
|
110
|
+
}
|
|
@@ -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 MyAvailabilityScreen({ rostering, locale, }: {
|
|
4
|
+
rostering: Hooks;
|
|
5
|
+
locale?: string;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
7
|
+
export {};
|