@composable-os/pack-rostering 0.1.0-beta.17 → 0.1.0-beta.19

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.
@@ -8,28 +8,12 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
8
8
  // Notes are read on this screen only: kept in the app's cache no longer than they are shown,
9
9
  // hidden when the page is left, and what was sent is forgotten once the call is over.
10
10
  import { addDays, awayKind, awayWhen, dayLabel, forgetAfter, rosterRefusal, weekOf, } from "@composable-os/pack-rostering/client";
11
- import { useEffect, useId, useRef, useState } from "react";
11
+ import { useId, useState } from "react";
12
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
- }
13
+ import { Field, FieldError, FieldLabel } from "../ui-field/field.js";
14
+ import { useForgetOnLeave } from "../ui-hooks/use-forget-on-leave.js";
15
+ import { Input } from "../ui-input/input.js";
16
+ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "../ui-select/select.js";
33
17
  export function TimeOff({ rostering, from, locale = "en-AU", }) {
34
18
  const me = rostering.useMe();
35
19
  const rosters = me.data?.rosters === true;
@@ -54,7 +38,7 @@ export function TimeOff({ rostering, from, locale = "en-AU", }) {
54
38
  if (me.isPending)
55
39
  return _jsx("p", { "aria-busy": "true", children: "Loading\u2026" });
56
40
  if (me.error || !me.data)
57
- return _jsx("p", { role: "alert", children: rosterRefusal(me.error).message });
41
+ return _jsx(FieldError, { children: rosterRefusal(me.error).message });
58
42
  if (!rosters) {
59
43
  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
44
  }
@@ -95,7 +79,7 @@ export function TimeOff({ rostering, from, locale = "en-AU", }) {
95
79
  }
96
80
  const items = hidden ? [] : (list.data?.items ?? []);
97
81
  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
82
+ 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(FieldError, { "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(FieldError, { 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
83
  .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" })] })] }));
84
+ .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" }), _jsxs(Field, { className: "gap-2", children: [_jsx(FieldLabel, { htmlFor: `${id}-who`, children: "Who" }), _jsxs(Select, { value: account, onValueChange: setAccount, required: true, children: [_jsx(SelectTrigger, { id: `${id}-who`, children: _jsx(SelectValue, { placeholder: "Choose\u2026" }) }), _jsx(SelectContent, { children: (people.data?.people ?? []).map((p) => (_jsx(SelectItem, { value: p.account, children: p.name }, p.account))) })] })] }), _jsxs(Field, { className: "gap-2", children: [_jsx(FieldLabel, { htmlFor: `${id}-from`, children: "From" }), _jsx(Input, { id: `${id}-from`, type: "datetime-local", value: startsAt, onChange: (e) => setStartsAt(e.target.value), required: true })] }), _jsxs(Field, { className: "gap-2", children: [_jsx(FieldLabel, { htmlFor: `${id}-until`, children: "Until" }), _jsx(Input, { id: `${id}-until`, type: "datetime-local", value: endsAt, onChange: (e) => setEndsAt(e.target.value), required: true })] }), _jsxs(Field, { className: "gap-2", children: [_jsx(FieldLabel, { htmlFor: `${id}-note`, children: "Note (optional)" }), _jsx(Input, { id: `${id}-note`, value: note, maxLength: 500, autoComplete: "off", onChange: (e) => setNote(e.target.value) })] }), _jsx(Button, { type: "submit", disabled: awayFor.isPending || !account, children: "Add leave" })] })] }));
101
85
  }
@@ -14,29 +14,12 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
14
14
  // key), cleared when the page is left, and read again when the browser brings it back. The
15
15
  // checklist itself is fetched only when it is opened, and kept no longer than it is shown.
16
16
  import { checklistStateLabel, forgetAfter, refusalNext, rosterRefusal, shiftTime, tickLabel, } from "@composable-os/pack-rostering/client";
17
- import { useEffect, useId, useRef, useState } from "react";
17
+ import { useId, useState } from "react";
18
18
  import { Button } from "../ui-button/button.js";
19
+ import { Field, FieldError, FieldLabel } from "../ui-field/field.js";
20
+ import { useForgetOnLeave } from "../ui-hooks/use-forget-on-leave.js";
21
+ import { Input } from "../ui-input/input.js";
19
22
  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
23
  export function ShiftChecklist({ rostering, shift, locale = "en-AU", zone, }) {
41
24
  const [open, setOpen] = useState(false);
42
25
  const answer = rostering.useChecklist(open ? { object: shift.object, id: shift.id } : null);
@@ -105,15 +88,15 @@ export function ShiftChecklist({ rostering, shift, locale = "en-AU", zone, }) {
105
88
  setOpen((o) => !o);
106
89
  setRefusal(null);
107
90
  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
91
+ }, 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(FieldError, { "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
92
  ? `Tick it off until ${shiftTime({ startsAt: data.tickUntil, endsAt: null }, tz, { withDate: true, locale })}.`
110
93
  : run && run.state !== "open"
111
94
  ? `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) => {
95
+ : `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(Field, { className: "gap-1", children: [_jsx(FieldLabel, { htmlFor: `${id}-for`, children: "Why you are ticking it for them" }), _jsx(Input, { id: `${id}-for`, 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
96
  const d = draftOf(step.position);
114
97
  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
98
  ? ` · 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
99
+ : ""] })) : 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(FieldLabel, { 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}`, 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(FieldLabel, { 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}`, 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
100
  ? `Save ${step.text} as not done`
118
101
  : `Mark ${step.text} not done`, onClick: () => d.notDone
119
102
  ? tickStep(step, "not_done")
@@ -128,5 +111,5 @@ export function ShiftChecklist({ rostering, shift, locale = "en-AU", zone, }) {
128
111
  }
129
112
  function Refusal({ refusal }) {
130
113
  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] }));
114
+ return (_jsxs(FieldError, { className: "text-xs", "data-refusal": refusal.kind, children: [_jsx("p", { children: refusal.message }), next ? _jsx("p", { children: next }) : null] }));
132
115
  }
@@ -11,6 +11,10 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
11
  import { addDays, checklistStateLabel, dateIn, dayLabel, forgetAfter, rosterRefusal, shiftTime, } from "@composable-os/pack-rostering/client";
12
12
  import { useId, useState } from "react";
13
13
  import { Button } from "../ui-button/button.js";
14
+ import { EmptyState } from "../ui-empty-state/empty-state.js";
15
+ import { Field, FieldError, FieldLabel } from "../ui-field/field.js";
16
+ import { Input } from "../ui-input/input.js";
17
+ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "../ui-select/select.js";
14
18
  export function ChecklistRuns({ rostering, from, to, locale = "en-AU", }) {
15
19
  const me = rostering.useMe();
16
20
  const today = me.data?.today ?? null;
@@ -28,7 +32,7 @@ export function ChecklistRuns({ rostering, from, to, locale = "en-AU", }) {
28
32
  if (me.isPending)
29
33
  return _jsx("p", { "aria-busy": "true", children: "Loading\u2026" });
30
34
  if (me.error || !me.data)
31
- return _jsx("p", { role: "alert", children: rosterRefusal(me.error).message });
35
+ return _jsx(FieldError, { children: rosterRefusal(me.error).message });
32
36
  if (!rosters) {
33
37
  return _jsx("p", { children: "How checklists went is shown to whoever rosters." });
34
38
  }
@@ -66,7 +70,7 @@ export function ChecklistRuns({ rostering, from, to, locale = "en-AU", }) {
66
70
  const t = String(data.get("to") ?? "");
67
71
  if (f && t)
68
72
  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: () => {
73
+ }, children: [_jsxs(Field, { className: "gap-1", children: [_jsx(FieldLabel, { htmlFor: `${id}-from`, children: "From" }), _jsx(Input, { id: `${id}-from`, name: "from", type: "date", defaultValue: current?.from })] }), _jsxs(Field, { className: "gap-1", children: [_jsx(FieldLabel, { htmlFor: `${id}-to`, children: "To" }), _jsx(Input, { id: `${id}-to`, name: "to", type: "date", defaultValue: current?.to })] }), _jsxs(Field, { className: "gap-1", children: [_jsx(FieldLabel, { htmlFor: `${id}-tpl`, children: "Checklist" }), _jsxs(Select, { value: template, onValueChange: setTemplate, none: "Every checklist", children: [_jsx(SelectTrigger, { id: `${id}-tpl`, children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: [...templates].map(([tid, name]) => (_jsx(SelectItem, { 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(FieldError, { "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(FieldError, { "data-refusal": refusal.kind, children: refusal.message }) : null, runs.data && !list.length ? _jsx(EmptyState, { title: "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(FieldLabel, { className: "grid gap-1", htmlFor: `${id}-c-${r.id}`, children: [_jsx("span", { className: "text-xs", children: "Correction" }), _jsx(Input, { id: `${id}-c-${r.id}`, 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
74
  setWriting(null);
71
75
  setText("");
72
76
  }, children: "Cancel" })] })] })) : (_jsx(Button, { type: "button", variant: "outline", "aria-label": `Add a correction to the checklist of ${r.title}`, onClick: () => {
@@ -9,8 +9,13 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
9
9
  // off (the note) is forgotten once the call is over and when I leave the page; it is read back only
10
10
  // on this screen, and kept in the app's cache no longer than it is shown.
11
11
  import { awayKind, awayWhen, forgetAfter, rosterRefusal, shiftTime, WEEKDAYS, } from "@composable-os/pack-rostering/client";
12
- import { useEffect, useId, useRef, useState } from "react";
12
+ import { useId, useState } from "react";
13
13
  import { Button } from "../ui-button/button.js";
14
+ import { Field, FieldError, FieldLabel, FieldLegend, FieldSet } from "../ui-field/field.js";
15
+ import { useForgetOnLeave } from "../ui-hooks/use-forget-on-leave.js";
16
+ import { Input } from "../ui-input/input.js";
17
+ import { RadioGroup, RadioGroupItem } from "../ui-radio-group/radio-group.js";
18
+ import { ToggleGroup, ToggleGroupItem } from "../ui-toggle-group/toggle-group.js";
14
19
  const EMPTY = {
15
20
  kind: "leave",
16
21
  startDate: "",
@@ -22,26 +27,6 @@ const EMPTY = {
22
27
  untilDate: "",
23
28
  note: "",
24
29
  };
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
30
  /** What the form asks the host for (the host checks it, and says what is wrong). */
46
31
  function inputOf(form) {
47
32
  const note = form.note.trim() ? { note: form.note.trim() } : {};
@@ -85,7 +70,7 @@ export function MyAvailability({ rostering, locale = "en-AU", }) {
85
70
  if (me.isPending)
86
71
  return _jsx("p", { "aria-busy": "true", children: "Loading your availability\u2026" });
87
72
  if (me.error || !me.data)
88
- return _jsx("p", { role: "alert", children: rosterRefusal(me.error).message });
73
+ return _jsx(FieldError, { children: rosterRefusal(me.error).message });
89
74
  const zone = me.data.zone;
90
75
  const set = (patch) => setForm((f) => ({ ...f, ...patch }));
91
76
  async function submit(event) {
@@ -128,16 +113,14 @@ export function MyAvailability({ rostering, locale = "en-AU", }) {
128
113
  }
129
114
  }
130
115
  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] })] }));
116
+ 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(FieldError, { "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: "gap-1", children: [_jsx(FieldLegend, { variant: "label", className: "mb-1", children: "What kind" }), _jsx(RadioGroup, { className: "gap-1", value: form.kind, onValueChange: (kind) => set({ kind: kind }), children: ["leave", "other", "regular"].map((kind) => (_jsxs(Field, { orientation: "horizontal", className: "min-h-11", children: [_jsx(RadioGroupItem, { id: f(`kind-${kind}`), value: kind }), _jsx(FieldLabel, { htmlFor: f(`kind-${kind}`), className: "font-normal", children: kind === "leave"
117
+ ? "Leave"
118
+ : kind === "other"
119
+ ? "Another one-off time"
120
+ : "Every week" })] }, kind))) })] }), form.kind === "regular" ? (_jsxs(_Fragment, { children: [_jsxs(FieldSet, { className: "gap-1", children: [_jsx(FieldLegend, { variant: "label", className: "mb-1", children: "Days" }), _jsx(ToggleGroup, { type: "multiple", variant: "outline", spacing: 1, className: "flex-wrap", "aria-label": "Days", value: form.weekdays.map(String), onValueChange: (days) => set({
121
+ weekdays: WEEKDAYS.map(([value]) => value).filter((d) => days.includes(String(d))),
122
+ }), children: WEEKDAYS.map(([value, label]) => (_jsx(ToggleGroupItem, { value: String(value), children: 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(FieldError, { 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
123
  }
141
124
  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) })] }));
125
+ return (_jsxs(Field, { className: "gap-1", children: [_jsx(FieldLabel, { htmlFor: id, children: label }), _jsx(Input, { id: id, type: type, value: value, maxLength: maxLength, autoComplete: "off", onChange: (e) => onChange(e.target.value) })] }));
143
126
  }
@@ -9,27 +9,12 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
9
9
  // Everything is the host's: whether a feed exists, the address, who may make one (the person
10
10
  // themselves), and each refusal, including a retried request whose answer the host never keeps
11
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";
12
+ import { forgetAfter, formatDay, rosterRefusal, } from "@composable-os/pack-rostering/client";
13
+ import { useEffect, useId, useState } from "react";
14
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
- }
15
+ import { Field, FieldError, FieldLabel } from "../ui-field/field.js";
16
+ import { useForgetOnLeave } from "../ui-hooks/use-forget-on-leave.js";
17
+ import { Input } from "../ui-input/input.js";
33
18
  export function MyCalendar({ rostering }) {
34
19
  const feed = rostering.useFeed();
35
20
  const rotate = rostering.useFeedRotate();
@@ -84,8 +69,8 @@ export function MyCalendar({ rostering }) {
84
69
  }
85
70
  }
86
71
  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()}` : ""}.`
72
+ 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(FieldError, { children: rosterRefusal(feed.error).message }) : null, refusal ? _jsx(FieldError, { "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: [_jsxs(Field, { className: "gap-2", children: [_jsx(FieldLabel, { htmlFor: `${id}-a`, className: "font-medium", children: "Your calendar address (shown this once)" }), _jsx(Input, { id: `${id}-a`, readOnly: true, value: address.https, className: "w-full 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
73
+ ? `You have a calendar address${state.createdAt ? `, made ${formatDay(state.createdAt)}` : ""}.`
89
74
  : "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
75
  ? "Make a new address? The one you have stops working, in every calendar that uses it."
91
76
  : "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] }));
@@ -10,28 +10,13 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
10
10
  // app's cache no longer than they are shown (`gcTime: 0`), are hidden when the page is left (and
11
11
  // read again when the browser brings it back), and are never put in an address or stored. It
12
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
- }
13
+ import { basisLabel, dayLabel, formatClockValue, payPeriodState, refusalNext, rosterRefusal, } from "@composable-os/pack-rostering/client";
14
+ import { useId, useState } from "react";
15
+ import { Button } from "../ui-button/button.js";
16
+ import { FieldError } from "../ui-field/field.js";
17
+ import { useForgetOnLeave } from "../ui-hooks/use-forget-on-leave.js";
18
+ import { ItemButton } from "../ui-item/item.js";
19
+ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "../ui-table/table.js";
35
20
  export function MyHours({ rostering, locale = "en-AU", }) {
36
21
  const [hidden, setHidden] = useState(false);
37
22
  const periods = rostering.useMyPayPeriods(!hidden);
@@ -42,22 +27,22 @@ export function MyHours({ rostering, locale = "en-AU", }) {
42
27
  setChosen(null);
43
28
  }, () => setHidden(false));
44
29
  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] }));
30
+ 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(ItemButton, { className: "block p-2", "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
31
  }
47
32
  function PeriodsRefusal({ error, onRetry }) {
48
33
  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"
34
+ return (_jsxs(FieldError, { className: "grid gap-1", "data-refusal": refusal.kind, children: [_jsx("p", { children: refusal.kind === "human_only"
50
35
  ? "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] }));
36
+ : refusal.message }), refusal.kind === "network" || refusal.kind === "other" ? (_jsx("p", { children: _jsx(Button, { variant: "link", size: "inline", className: "underline", onClick: onRetry, children: "Try again" }) })) : null] }));
52
37
  }
53
38
  function PeriodHours({ rostering, period, locale, }) {
54
39
  const mine = rostering.useMyPay({ start: period.start });
55
40
  const id = useId();
56
41
  const data = mine.data;
57
42
  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
43
+ 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(FieldError, { "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, { variant: "link", size: "inline", 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
44
  ? "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
45
+ : `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(TableHeader, { children: _jsxs(TableRow, { className: "text-left", children: [_jsx(TableHead, { scope: "col", className: "p-1", children: "Kind of work" }), _jsx(TableHead, { scope: "col", className: "p-1", children: "Shifts" }), _jsx(TableHead, { scope: "col", className: "p-1", children: "Hours" }), _jsx(TableHead, { scope: "col", className: "p-1", children: "Not worked" })] }) }), _jsx(TableBody, { children: data.totals.map((t) => (_jsxs(TableRow, { className: "border-t", children: [_jsx(TableHead, { scope: "row", className: "p-1 text-left font-normal", children: t.kindName }), _jsx(TableCell, { className: "p-1", children: t.shifts }), _jsx(TableCell, { className: "p-1", children: t.hours }), _jsx(TableCell, { 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), " ", formatClockValue(l.localStart.slice(11, 16)), "\u2013", formatClockValue(l.localEnd.slice(11, 16)), l.place ? ` · ${l.place}` : "", " · ", l.notWorked
61
46
  ? "Marked not worked: counts for nothing. Ask whoever rosters why."
62
47
  : `${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
48
  }
@@ -12,6 +12,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
12
  import { addDays, dateIn, dayLabel, refusalNext, rosterRefusal, shiftName, shiftTime, } from "@composable-os/pack-rostering/client";
13
13
  import { useId, useState } from "react";
14
14
  import { Button } from "../ui-button/button.js";
15
+ import { FieldError } from "../ui-field/field.js";
15
16
  import { MyHours } from "./my-hours.js";
16
17
  export function MyShifts({ rostering, from, days = 28, locale = "en-AU", calendar, shiftExtra, }) {
17
18
  const me = rostering.useMe();
@@ -26,7 +27,7 @@ export function MyShifts({ rostering, from, days = 28, locale = "en-AU", calenda
26
27
  if (me.isPending)
27
28
  return _jsx("p", { "aria-busy": "true", children: "Loading your shifts\u2026" });
28
29
  if (me.error || !me.data)
29
- return _jsx("p", { role: "alert", children: rosterRefusal(me.error).message });
30
+ return _jsx(FieldError, { children: rosterRefusal(me.error).message });
30
31
  const zone = mine.data?.zone ?? me.data.zone;
31
32
  const busy = offer.isPending || withdraw.isPending;
32
33
  async function act(id, what, done) {
@@ -47,7 +48,7 @@ export function MyShifts({ rostering, from, days = 28, locale = "en-AU", calenda
47
48
  const date = dateIn(s.startsAt, zone);
48
49
  byDate.set(date, [...(byDate.get(date) ?? []), s]);
49
50
  }
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
+ 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(FieldError, { 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(FieldError, { "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
52
  ? ` · closes ${shiftTime({ startsAt: o.closesAt, endsAt: null }, zone, { withDate: true, locale })}`
52
53
  : ""] }, o.id))) })] })) : null, _jsx(MyHours, { rostering: rostering, locale: locale })] }));
53
54
  }
@@ -9,7 +9,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
9
9
  // marked not worked, only that it was. The figures are fetched only when I pick a period, kept no
10
10
  // longer than they are shown (`gcTime: 0`), hidden when the app goes to the background (read
11
11
  // again when it comes back), and never stored.
12
- import { basisLabel, dayLabel, payPeriodState, refusalNext, rosterRefusal, } from "@composable-os/pack-rostering/client";
12
+ import { basisLabel, dayLabel, formatClockValue, payPeriodState, refusalNext, rosterRefusal, } from "@composable-os/pack-rostering/client";
13
13
  import { useEffect, useState } from "react";
14
14
  import { AppState, View } from "react-native";
15
15
  import { Button } from "../native-base/button.js";
@@ -45,7 +45,7 @@ function PeriodHours({ rostering, period, locale, }) {
45
45
  return (_jsxs(View, { children: [_jsxs(Text, { accessibilityRole: "header", children: [dayLabel(period.start, locale, true), " to ", dayLabel(period.end, locale, true)] }), mine.isPending ? (_jsx(Text, { tone: "muted", accessibilityRole: "progressbar", children: "Loading your hours\u2026" })) : null, refusal ? (_jsxs(View, { children: [_jsxs(Text, { accessibilityRole: "alert", children: [refusal.message, refusalNext(refusal.kind, false) ? ` ${refusalNext(refusal.kind, false)}` : ""] }), refusal.kind === "network" || refusal.kind === "other" ? (_jsx(Button, { label: "Try again", quiet: true, onPress: () => mine.refetch?.() })) : null] })) : null, data && !data.counted ? (_jsx(Text, { 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(View, { children: [_jsx(Text, { children: data.period.preview
46
46
  ? "A preview from the roster as it stands: it can change until the period is locked."
47
47
  : "Locked: these are the figures payroll was given." }), _jsxs(Text, { children: ["Counted: ", basisLabel(data.basis)] }), _jsx(List, { empty: "You have no counted shifts in this period.", children: data.totals.map((t) => (_jsx(Row, { title: t.kindName, detail: `${t.shifts} shifts · ${t.hours} hours${t.notWorked ? ` · ${t.notWorked} not worked` : ""}` }, `${t.basis}:${t.kind?.id ?? t.kindName}`))) }), _jsxs(Text, { children: ["All my hours: ", data.hours] }), data.lines.length ? (_jsx(List, { children: data.lines.map((l) => (_jsx(Row, { title: `${dayLabel(l.localDate, locale)} · ${l.title}`, detail: [
48
- `${l.localStart.slice(11, 16)}–${l.localEnd.slice(11, 16)}`,
48
+ `${formatClockValue(l.localStart.slice(11, 16))}–${formatClockValue(l.localEnd.slice(11, 16))}`,
49
49
  l.place,
50
50
  l.notWorked
51
51
  ? "Marked not worked: counts for nothing. Ask whoever rosters why."
@@ -11,7 +11,10 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
11
  // for each has its own state, and the list is refreshed.
12
12
  import { refusalNext, rosterRefusal, shiftTime, } from "@composable-os/pack-rostering/client";
13
13
  import { useId, useState } from "react";
14
+ import { Alert, AlertDescription } from "../ui-alert/alert.js";
14
15
  import { Button } from "../ui-button/button.js";
16
+ import { EmptyState } from "../ui-empty-state/empty-state.js";
17
+ import { FieldError } from "../ui-field/field.js";
15
18
  export function OffersToMe({ rostering, locale = "en-AU" }) {
16
19
  const me = rostering.useMe();
17
20
  const offers = rostering.useOffers();
@@ -23,7 +26,7 @@ export function OffersToMe({ rostering, locale = "en-AU" }) {
23
26
  if (me.isPending || offers.isPending)
24
27
  return _jsx("p", { "aria-busy": "true", children: "Loading offers\u2026" });
25
28
  if (me.error || !me.data)
26
- return _jsx("p", { role: "alert", children: rosterRefusal(me.error).message });
29
+ return _jsx(FieldError, { children: rosterRefusal(me.error).message });
27
30
  const zone = me.data.zone;
28
31
  async function takeIt(o, confirmUnavailable) {
29
32
  setRefusal(null);
@@ -48,5 +51,5 @@ export function OffersToMe({ rostering, locale = "en-AU" }) {
48
51
  await offers.refetch?.();
49
52
  }
50
53
  const open = offers.data?.open ?? [];
51
- return (_jsxs("section", { className: "grid gap-3", "aria-labelledby": headingId, children: [_jsx("h2", { id: headingId, className: "text-lg font-medium", children: "Offered to me" }), taken ? (_jsx("p", { role: "status", className: "text-sm", children: taken })) : null, refusal && !open.some((o) => o.id === refusal.id) ? (_jsxs("div", { role: "alert", className: "rounded-md border p-2 text-sm", "data-refusal": refusal.refusal.kind, children: [_jsx("p", { children: refusal.refusal.message }), refusalNext(refusal.refusal.kind, me.data.rosters) ? (_jsx("p", { children: refusalNext(refusal.refusal.kind, me.data.rosters) })) : null] })) : null, offers.error ? _jsx("p", { role: "alert", children: rosterRefusal(offers.error).message }) : null, offers.data && !open.length ? _jsx("p", { children: "No shifts are offered to you right now." }) : null, _jsx("ul", { className: "grid gap-2", children: open.map((o) => (_jsxs("li", { className: "grid gap-2 rounded-md border p-3", "data-offer": o.id, "aria-label": `${o.shift.title}, ${shiftTime(o.shift, zone, { withDate: true, locale })}, offered by ${o.fromName ?? "whoever rosters"}`, children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [_jsxs("div", { children: [_jsx("p", { className: "font-medium", children: o.shift.title }), _jsx("p", { className: "text-sm text-muted-foreground", children: shiftTime(o.shift, zone, { withDate: true, locale }) }), _jsxs("p", { className: "text-sm", children: ["Offered by ", o.fromName ?? "whoever rosters", o.to ? " to you" : "", o.unavailable ? " · You said you are away then" : ""] })] }), confirming === o.id ? null : (_jsx(Button, { type: "button", disabled: take.isPending, "aria-label": `Take ${o.shift.title}`, onClick: () => takeIt(o, false), children: "Take it" }))] }), confirming === o.id ? (_jsxs("div", { role: "alertdialog", "aria-label": "You said you are away then", className: "grid gap-2 rounded-md border p-2", children: [_jsx("p", { className: "text-sm", children: "You said you are not available then. Take it anyway?" }), _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { type: "button", disabled: take.isPending, onClick: () => takeIt(o, true), children: "Take it anyway" }), _jsx(Button, { type: "button", variant: "outline", onClick: () => setConfirming(null), children: "Leave it" })] })] })) : null, refusal?.id === o.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] }, o.id))) })] }));
54
+ return (_jsxs("section", { className: "grid gap-3", "aria-labelledby": headingId, children: [_jsx("h2", { id: headingId, className: "text-lg font-medium", children: "Offered to me" }), taken ? (_jsx("p", { role: "status", className: "text-sm", children: taken })) : null, refusal && !open.some((o) => o.id === refusal.id) ? (_jsx(Alert, { variant: "destructive", "data-refusal": refusal.refusal.kind, children: _jsxs(AlertDescription, { children: [_jsx("p", { children: refusal.refusal.message }), refusalNext(refusal.refusal.kind, me.data.rosters) ? (_jsx("p", { children: refusalNext(refusal.refusal.kind, me.data.rosters) })) : null] }) })) : null, offers.error ? _jsx(FieldError, { children: rosterRefusal(offers.error).message }) : null, offers.data && !open.length ? (_jsx(EmptyState, { title: "No shifts are offered to you right now." })) : null, _jsx("ul", { className: "grid gap-2", children: open.map((o) => (_jsxs("li", { className: "grid gap-2 rounded-md border p-3", "data-offer": o.id, "aria-label": `${o.shift.title}, ${shiftTime(o.shift, zone, { withDate: true, locale })}, offered by ${o.fromName ?? "whoever rosters"}`, children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [_jsxs("div", { children: [_jsx("p", { className: "font-medium", children: o.shift.title }), _jsx("p", { className: "text-sm text-muted-foreground", children: shiftTime(o.shift, zone, { withDate: true, locale }) }), _jsxs("p", { className: "text-sm", children: ["Offered by ", o.fromName ?? "whoever rosters", o.to ? " to you" : "", o.unavailable ? " · You said you are away then" : ""] })] }), confirming === o.id ? null : (_jsx(Button, { type: "button", disabled: take.isPending, "aria-label": `Take ${o.shift.title}`, onClick: () => takeIt(o, false), children: "Take it" }))] }), confirming === o.id ? (_jsxs("div", { role: "alertdialog", "aria-label": "You said you are away then", className: "grid gap-2 rounded-md border p-2", children: [_jsx("p", { className: "text-sm", children: "You said you are not available then. Take it anyway?" }), _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { type: "button", disabled: take.isPending, onClick: () => takeIt(o, true), children: "Take it anyway" }), _jsx(Button, { type: "button", variant: "outline", onClick: () => setConfirming(null), children: "Leave it" })] })] })) : null, refusal?.id === o.id ? (_jsxs(FieldError, { "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] }, o.id))) })] }));
52
55
  }