@composable-os/pack-rostering 0.1.0-beta.18 → 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.
- package/dist/blocks/rostering-away/away-list.js +8 -24
- package/dist/blocks/rostering-checklist/checklist.js +8 -25
- package/dist/blocks/rostering-checklists/checklists.js +6 -2
- package/dist/blocks/rostering-my-availability/my-availability.js +15 -32
- package/dist/blocks/rostering-my-calendar/my-calendar.js +7 -22
- package/dist/blocks/rostering-my-shifts/my-hours.js +12 -27
- package/dist/blocks/rostering-my-shifts/my-shifts.js +3 -2
- package/dist/blocks/rostering-native-my-shifts/my-hours-screen.js +2 -2
- package/dist/blocks/rostering-offers/offers.js +5 -2
- package/dist/blocks/rostering-patterns/patterns.js +9 -5
- package/dist/blocks/rostering-pay/pay.js +14 -28
- package/dist/blocks/rostering-qualifications/qualifications.js +6 -3
- package/dist/blocks/rostering-week/assign.js +6 -21
- package/dist/blocks/rostering-week/week.js +17 -4
- package/dist/client/index.d.ts +7 -12
- package/dist/client/index.js +16 -44
- package/dist/index.d.ts +38 -24
- package/dist/index.js +23 -14
- package/package.json +3 -3
|
@@ -6,9 +6,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
6
6
|
//
|
|
7
7
|
// Shown only when the host says the reader rosters (`me.rosters`): nobody else's screen asks for
|
|
8
8
|
// the patterns. Everything shown is the host's answer.
|
|
9
|
-
import { dayLabel, patternWhen, refusalNext, rosterRefusal, WEEKDAYS, } from "@composable-os/pack-rostering/client";
|
|
9
|
+
import { dayLabel, formatClockValue, patternWhen, refusalNext, rosterRefusal, WEEKDAYS, } from "@composable-os/pack-rostering/client";
|
|
10
10
|
import { useId, useState } from "react";
|
|
11
11
|
import { Button } from "../ui-button/button.js";
|
|
12
|
+
import { Field, FieldError, FieldLabel } from "../ui-field/field.js";
|
|
13
|
+
import { Input } from "../ui-input/input.js";
|
|
14
|
+
import { ItemButton } from "../ui-item/item.js";
|
|
15
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "../ui-select/select.js";
|
|
12
16
|
export function Patterns({ rostering, locale = "en-AU" }) {
|
|
13
17
|
const me = rostering.useMe();
|
|
14
18
|
const rosters = me.data?.rosters === true;
|
|
@@ -19,14 +23,14 @@ export function Patterns({ rostering, locale = "en-AU" }) {
|
|
|
19
23
|
if (me.isPending)
|
|
20
24
|
return _jsx("p", { "aria-busy": "true", children: "Loading\u2026" });
|
|
21
25
|
if (me.error || !me.data)
|
|
22
|
-
return _jsx(
|
|
26
|
+
return _jsx(FieldError, { children: rosterRefusal(me.error).message });
|
|
23
27
|
if (!rosters) {
|
|
24
28
|
return (_jsx("p", { role: "status", "data-refusal": "rostering", children: "The regular week is for whoever rosters. Your own shifts are on My shifts." }));
|
|
25
29
|
}
|
|
26
30
|
const all = patterns.data?.patterns ?? [];
|
|
27
|
-
return (_jsxs("section", { className: "grid gap-4", "aria-labelledby": headingId, children: [_jsx("h2", { id: headingId, className: "text-lg font-medium", children: "Regular week" }), patterns.isPending ? _jsx("p", { "aria-busy": "true", children: "Loading the regular week\u2026" }) : null, patterns.error ? _jsx(
|
|
31
|
+
return (_jsxs("section", { className: "grid gap-4", "aria-labelledby": headingId, children: [_jsx("h2", { id: headingId, className: "text-lg font-medium", children: "Regular week" }), patterns.isPending ? _jsx("p", { "aria-busy": "true", children: "Loading the regular week\u2026" }) : null, patterns.error ? _jsx(FieldError, { children: rosterRefusal(patterns.error).message }) : null, patterns.data?.truncated ? (_jsx("p", { role: "status", className: "text-sm", children: "There are more patterns than one screen shows." })) : null, _jsx("ol", { className: "grid gap-3 md:grid-cols-7", "aria-label": "Days of the week", children: WEEKDAYS.map(([day, label]) => {
|
|
28
32
|
const on = all.filter((p) => p.weekdays.includes(day));
|
|
29
|
-
return (_jsxs("li", { className: "min-w-0 rounded-md border p-2", children: [_jsx("h3", { className: "text-sm font-medium", children: label }), on.length ? (_jsx("ul", { className: "mt-2 grid gap-2", children: on.map((p) => (_jsx("li", { children: _jsxs(
|
|
33
|
+
return (_jsxs("li", { className: "min-w-0 rounded-md border p-2", children: [_jsx("h3", { className: "text-sm font-medium", children: label }), on.length ? (_jsx("ul", { className: "mt-2 grid gap-2", children: on.map((p) => (_jsx("li", { children: _jsxs(ItemButton, { className: "block p-2", "aria-label": `${p.title}, ${label} ${formatClockValue(p.time ?? "")}, ${p.name ?? "nobody"}. Change who works it`, "aria-pressed": editing?.id === p.id, onClick: () => setEditing(p), children: [_jsx("span", { className: "block text-xs text-muted-foreground", children: formatClockValue(p.time ?? "") }), _jsx("span", { className: "block font-medium", children: p.title }), _jsx("span", { className: "block text-xs", children: p.name ?? (p.noAccount ? "A coach with no account" : "Nobody") })] }) }, `${p.object}:${p.id}`))) })) : (_jsx("p", { className: "mt-2 text-xs text-muted-foreground", children: "Nothing" }))] }, day));
|
|
30
34
|
}) }), editing ? (_jsx(ChangePattern, { rostering: rostering, pattern: editing, people: people.data?.people ?? [], today: me.data.today, locale: locale, onClose: () => setEditing(null), onChanged: () => patterns.refetch?.() })) : null] }));
|
|
31
35
|
}
|
|
32
36
|
function ChangePattern({ rostering, pattern, people, today, locale, onClose, onChanged, }) {
|
|
@@ -54,5 +58,5 @@ function ChangePattern({ rostering, pattern, people, today, locale, onClose, onC
|
|
|
54
58
|
setRefusal(rosterRefusal(error));
|
|
55
59
|
}
|
|
56
60
|
}
|
|
57
|
-
return (_jsxs("form", { className: "grid gap-3 rounded-md border p-3", onSubmit: submit, "aria-label": `Change who works ${pattern.title}`, children: [_jsxs("div", { className: "flex items-start justify-between gap-2", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: pattern.title }), _jsxs("p", { className: "text-sm text-muted-foreground", children: [pattern.objectLabel, " \u00B7 ", patternWhen(pattern), " \u00B7 ", pattern.zone] })] }), _jsx(Button, { type: "button", variant: "outline", onClick: onClose, children: "Close" })] }), _jsxs(
|
|
61
|
+
return (_jsxs("form", { className: "grid gap-3 rounded-md border p-3", onSubmit: submit, "aria-label": `Change who works ${pattern.title}`, children: [_jsxs("div", { className: "flex items-start justify-between gap-2", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: pattern.title }), _jsxs("p", { className: "text-sm text-muted-foreground", children: [pattern.objectLabel, " \u00B7 ", patternWhen(pattern), " \u00B7 ", pattern.zone] })] }), _jsx(Button, { type: "button", variant: "outline", onClick: onClose, children: "Close" })] }), _jsxs(Field, { className: "gap-1", children: [_jsx(FieldLabel, { htmlFor: `${id}-who`, children: "Regular person" }), _jsxs(Select, { value: account, onValueChange: setAccount, none: "Nobody", children: [_jsx(SelectTrigger, { id: `${id}-who`, children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: people.map((p) => (_jsx(SelectItem, { value: p.account, children: p.name }, p.account))) })] })] }), _jsxs(Field, { className: "gap-1", children: [_jsx(FieldLabel, { htmlFor: `${id}-from`, children: "From" }), _jsx(Input, { id: `${id}-from`, type: "date", value: from, onChange: (e) => setFrom(e.target.value) })] }), refusal ? (_jsxs(FieldError, { "data-refusal": refusal.kind, children: [_jsx("p", { children: refusal.message }), refusal.dates?.length ? (_jsxs("p", { children: ["On: ", refusal.dates.map((d) => dayLabel(d, locale)).join(", ")] })) : null, refusalNext(refusal.kind, true) ? _jsx("p", { children: refusalNext(refusal.kind, true) }) : null] })) : null, said ? (_jsx("p", { role: "status", className: "text-sm", children: said })) : null, _jsx(Button, { type: "submit", disabled: setPattern.isPending, children: "Save from this date" })] }));
|
|
58
62
|
}
|
|
@@ -12,29 +12,15 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
12
12
|
// (`me.pays`), so no one else's screen asks for any of it. Figures are kept in the app's cache no
|
|
13
13
|
// longer than they are shown, hidden when the page is left, and the CSV is handed to the person
|
|
14
14
|
// and not kept; why a period was reopened is forgotten once the call is over.
|
|
15
|
-
import { basisLabel, dayLabel, forgetAfter, refusalNext, rosterRefusal, } from "@composable-os/pack-rostering/client";
|
|
16
|
-
import {
|
|
15
|
+
import { basisLabel, dayLabel, forgetAfter, formatClockValue, refusalNext, rosterRefusal, } from "@composable-os/pack-rostering/client";
|
|
16
|
+
import { useId, useState } from "react";
|
|
17
17
|
import { Button } from "../ui-button/button.js";
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const show = (event) => {
|
|
25
|
-
if (!event.persisted)
|
|
26
|
-
return;
|
|
27
|
-
latest.current.forget();
|
|
28
|
-
latest.current.cameBack();
|
|
29
|
-
};
|
|
30
|
-
window.addEventListener("pagehide", hide);
|
|
31
|
-
window.addEventListener("pageshow", show);
|
|
32
|
-
return () => {
|
|
33
|
-
window.removeEventListener("pagehide", hide);
|
|
34
|
-
window.removeEventListener("pageshow", show);
|
|
35
|
-
};
|
|
36
|
-
}, []);
|
|
37
|
-
}
|
|
18
|
+
import { Field, FieldError, FieldLabel } from "../ui-field/field.js";
|
|
19
|
+
import { useForgetOnLeave } from "../ui-hooks/use-forget-on-leave.js";
|
|
20
|
+
import { Input } from "../ui-input/input.js";
|
|
21
|
+
import { ItemButton } from "../ui-item/item.js";
|
|
22
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "../ui-select/select.js";
|
|
23
|
+
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "../ui-table/table.js";
|
|
38
24
|
/** Hands a CSV to the person as a file to save; nothing of it is kept here. */
|
|
39
25
|
function saveFile(filename, csv) {
|
|
40
26
|
const url = URL.createObjectURL(new Blob([csv], { type: "text/csv" }));
|
|
@@ -61,14 +47,14 @@ export function Pay({ rostering, locale = "en-AU" }) {
|
|
|
61
47
|
if (me.isPending)
|
|
62
48
|
return _jsx("p", { "aria-busy": "true", children: "Loading\u2026" });
|
|
63
49
|
if (me.error || !me.data)
|
|
64
|
-
return _jsx(
|
|
50
|
+
return _jsx(FieldError, { children: rosterRefusal(me.error).message });
|
|
65
51
|
if (!pays) {
|
|
66
52
|
return (_jsx("p", { role: "status", "data-refusal": "forbidden", children: "Pay is seen only by whoever handles pay, at the screen themselves." }));
|
|
67
53
|
}
|
|
68
54
|
if (hidden)
|
|
69
55
|
return _jsx("p", { "aria-busy": "true", children: "Loading\u2026" });
|
|
70
56
|
const period = periods.data?.periods.find((p) => p.start === chosen) ?? null;
|
|
71
|
-
return (_jsxs("section", { className: "grid gap-4", "aria-labelledby": headingId, children: [_jsx("h2", { id: headingId, className: "text-lg font-medium", children: "Pay periods" }), _jsx("p", { className: "text-sm text-muted-foreground", children: "Hours and shifts for payroll. No rates or money are kept here: payroll applies them." }), periods.isPending ? _jsx("p", { "aria-busy": "true", children: "Loading the periods\u2026" }) : null, periods.error ? _jsx(
|
|
57
|
+
return (_jsxs("section", { className: "grid gap-4", "aria-labelledby": headingId, children: [_jsx("h2", { id: headingId, className: "text-lg font-medium", children: "Pay periods" }), _jsx("p", { className: "text-sm text-muted-foreground", children: "Hours and shifts for payroll. No rates or money are kept here: payroll applies them." }), periods.isPending ? _jsx("p", { "aria-busy": "true", children: "Loading the periods\u2026" }) : null, periods.error ? _jsx(FieldError, { children: rosterRefusal(periods.error).message }) : null, periods.data && !periods.data.set ? (_jsxs("p", { role: "status", "data-refusal": "pay_period_unset", children: ["The date a pay period starts is not set yet, so nothing is totalled. Set it in Settings, Rostering (", periods.data.setting.period, ")."] })) : null, periods.data?.set ? (_jsx("ul", { className: "grid gap-2 sm:grid-cols-2", "aria-label": "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)}, ${p.state === "locked" ? "locked" : p.ended ? "ended, open" : "open"}`, onClick: () => setChosen(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: p.state === "locked"
|
|
72
58
|
? `Locked (version ${p.versions.at(-1)?.version ?? 1})`
|
|
73
59
|
: p.ended
|
|
74
60
|
? "Ended, not locked"
|
|
@@ -121,14 +107,14 @@ function PeriodView({ rostering, period, locale, onChanged, }) {
|
|
|
121
107
|
}
|
|
122
108
|
const data = totals.data;
|
|
123
109
|
const locked = period.state === "locked";
|
|
124
|
-
return (_jsxs("section", { className: "grid gap-3 rounded-md border p-3", "aria-labelledby": `${id}-h`, children: [_jsxs("h3", { id: `${id}-h`, className: "font-medium", children: [dayLabel(period.start, locale, true), " to ", dayLabel(period.end, locale, true)] }), data?.period.preview ? (_jsx("p", { className: "text-sm", role: "status", children: "A preview from the roster as it stands: it changes until the period is locked." })) : null, refusal ? (_jsxs(
|
|
110
|
+
return (_jsxs("section", { className: "grid gap-3 rounded-md border p-3", "aria-labelledby": `${id}-h`, children: [_jsxs("h3", { id: `${id}-h`, className: "font-medium", children: [dayLabel(period.start, locale, true), " to ", dayLabel(period.end, locale, true)] }), data?.period.preview ? (_jsx("p", { className: "text-sm", role: "status", children: "A preview from the roster as it stands: it changes until the period is locked." })) : 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] })) : null, said ? (_jsx("p", { role: "status", className: "text-sm", children: said })) : null, totals.isPending ? _jsx("p", { "aria-busy": "true", children: "Loading\u2026" }) : null, totals.error ? _jsx(FieldError, { children: rosterRefusal(totals.error).message }) : null, data ? (_jsxs(_Fragment, { children: [_jsx("div", { className: "max-w-full overflow-x-auto", children: _jsxs(Table, { className: "text-sm", "aria-label": "Hours and shifts per person", children: [_jsx(TableHeader, { children: _jsxs(TableRow, { className: "text-left", children: [_jsx(TableHead, { scope: "col", className: "p-1", children: "Person" }), _jsx(TableHead, { scope: "col", className: "p-1", children: "Counted" }), _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(TableHead, { scope: "col", className: "p-1", children: "To check" })] }) }), _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.name }), _jsx(TableCell, { className: "p-1", children: basisLabel(t.basis) }), _jsx(TableCell, { className: "p-1", 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 }), _jsx(TableCell, { className: "p-1", children: t.flagged ? `${t.flagged} flagged` : "" })] }, `${t.account}:${t.kind?.id ?? ""}`))) })] }) }), _jsxs("p", { className: "text-sm", children: ["All counted hours: ", data.hours] }), _jsxs("details", { children: [_jsx("summary", { className: "cursor-pointer text-sm", children: "Each shift, with its evidence" }), _jsx("div", { className: "max-w-full overflow-x-auto", children: _jsxs(Table, { className: "text-sm", "aria-label": "Each shift", children: [_jsx(TableHeader, { children: _jsxs(TableRow, { className: "text-left", children: [_jsx(TableHead, { scope: "col", className: "p-1", children: "Date" }), _jsx(TableHead, { scope: "col", className: "p-1", children: "Time" }), _jsx(TableHead, { scope: "col", className: "p-1", children: "Person" }), _jsx(TableHead, { scope: "col", className: "p-1", children: "Shift" }), _jsx(TableHead, { scope: "col", className: "p-1", children: "Minutes counted" }), _jsx(TableHead, { scope: "col", className: "p-1", children: "Evidence" })] }) }), _jsx(TableBody, { children: data.lines.map((l) => (_jsxs(TableRow, { className: "border-t", "data-flagged": l.flagged ? "true" : undefined, children: [_jsx(TableCell, { className: "p-1", children: dayLabel(l.localDate, locale) }), _jsxs(TableCell, { className: "p-1", children: [formatClockValue(l.localStart.slice(11, 16)), "\u2013", formatClockValue(l.localEnd.slice(11, 16))] }), _jsx(TableCell, { className: "p-1", children: l.name }), _jsxs(TableCell, { className: "p-1", children: [l.title, l.place ? ` · ${l.place}` : ""] }), _jsxs(TableCell, { className: "p-1", children: [l.counted ? l.countedMinutes : "Not worked", l.notWorkedReason ? ` (${l.notWorkedReason})` : ""] }), _jsxs(TableCell, { className: "p-1", children: [l.listTaken === null
|
|
125
111
|
? ""
|
|
126
112
|
: l.listTaken
|
|
127
113
|
? `List taken${l.markedBy ? ` by ${l.markedBy}` : ""}`
|
|
128
114
|
: "List not taken", l.flagged ? " · check who ran it" : ""] })] }, `${l.object}:${l.id}`))) })] }) })] }), _jsxs("div", { className: "flex flex-wrap gap-2", children: [_jsx(Button, { type: "button", variant: "outline", disabled: exported.isPending, onClick: download, children: locked ? "Export CSV" : "Export a preview CSV" }), !locked && period.ended ? (confirmLock ? (_jsxs("div", { role: "alertdialog", "aria-label": "Lock this period", className: "grid gap-2 rounded-md border p-2", children: [_jsx("p", { className: "text-sm", children: "Lock it? Its hours are kept as they are now, and its shifts can no longer be changed until it is reopened." }), _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { type: "button", disabled: lock.isPending, onClick: () => {
|
|
129
115
|
setConfirmLock(false);
|
|
130
116
|
void run(() => lock.mutateAsync({ start: period.start }), "Locked.");
|
|
131
|
-
}, children: "Lock the period" }), _jsx(Button, { type: "button", variant: "outline", onClick: () => setConfirmLock(false), children: "Not yet" })] })] })) : (_jsx(Button, { type: "button", onClick: () => setConfirmLock(true), children: "Lock\u2026" }))) : null] }), !locked && !period.ended ? (_jsx("p", { className: "text-xs text-muted-foreground", children: "It can be locked once it has ended." })) : null, locked ? (_jsxs("form", { className: "grid gap-1", onSubmit: doReopen, "aria-label": "Reopen this period", children: [
|
|
117
|
+
}, children: "Lock the period" }), _jsx(Button, { type: "button", variant: "outline", onClick: () => setConfirmLock(false), children: "Not yet" })] })] })) : (_jsx(Button, { type: "button", onClick: () => setConfirmLock(true), children: "Lock\u2026" }))) : null] }), !locked && !period.ended ? (_jsx("p", { className: "text-xs text-muted-foreground", children: "It can be locked once it has ended." })) : null, locked ? (_jsxs("form", { className: "grid gap-1", onSubmit: doReopen, "aria-label": "Reopen this period", children: [_jsxs(Field, { className: "gap-1", children: [_jsx(FieldLabel, { htmlFor: `${id}-why`, children: "Reopen to correct it: why?" }), _jsx(Input, { id: `${id}-why`, value: reason, maxLength: 500, autoComplete: "off", onChange: (e) => setReason(e.target.value) })] }), _jsx(Button, { type: "submit", variant: "outline", disabled: reopen.isPending, children: "Reopen" })] })) : null] })) : null] }));
|
|
132
118
|
}
|
|
133
119
|
function Counted({ rostering, today, }) {
|
|
134
120
|
const bases = rostering.usePayBases({ everyone: true });
|
|
@@ -152,9 +138,9 @@ function Counted({ rostering, today, }) {
|
|
|
152
138
|
}
|
|
153
139
|
await bases.refetch?.();
|
|
154
140
|
}
|
|
155
|
-
return (_jsxs("section", { className: "grid gap-2", "aria-labelledby": `${id}-h`, children: [_jsx("h3", { id: `${id}-h`, className: "font-medium", children: "Who is counted" }), bases.isPending ? _jsx("p", { "aria-busy": "true", children: "Loading\u2026" }) : null, bases.error ? _jsx(
|
|
141
|
+
return (_jsxs("section", { className: "grid gap-2", "aria-labelledby": `${id}-h`, children: [_jsx("h3", { id: `${id}-h`, className: "font-medium", children: "Who is counted" }), bases.isPending ? _jsx("p", { "aria-busy": "true", children: "Loading\u2026" }) : null, bases.error ? _jsx(FieldError, { children: rosterRefusal(bases.error).message }) : null, refusal ? _jsx(FieldError, { "data-refusal": refusal.kind, children: refusal.message }) : null, _jsx("ul", { className: "grid gap-1 text-sm", children: (bases.data?.items ?? []).map((item) => (_jsxs("li", { className: "grid gap-1 rounded border p-2", children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [_jsxs("span", { children: [item.name, " \u00B7 ", basisLabel(item.basis)] }), _jsx(Button, { type: "button", size: "sm", variant: "outline", "aria-label": `Change how ${item.name} is counted`, onClick: () => {
|
|
156
142
|
setEditing(item.account);
|
|
157
143
|
setBasisValue(item.basis);
|
|
158
144
|
setFrom(today);
|
|
159
|
-
}, children: "Change" })] }), editing === item.account ? (_jsxs("form", { className: "flex flex-wrap items-end gap-2", onSubmit: save, "aria-label": `How ${item.name} is counted`, children: [_jsxs(
|
|
145
|
+
}, children: "Change" })] }), editing === item.account ? (_jsxs("form", { className: "flex flex-wrap items-end gap-2", onSubmit: save, "aria-label": `How ${item.name} is counted`, children: [_jsxs(Field, { className: "gap-1 w-auto", children: [_jsx(FieldLabel, { htmlFor: `${id}-basis`, children: "Counted" }), _jsxs(Select, { value: basis, onValueChange: (value) => setBasisValue(value), children: [_jsx(SelectTrigger, { id: `${id}-basis`, children: _jsx(SelectValue, {}) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: "not_counted", children: basisLabel("not_counted") }), _jsx(SelectItem, { value: "by_time", children: basisLabel("by_time") }), _jsx(SelectItem, { value: "by_class", children: basisLabel("by_class") })] })] })] }), _jsxs(Field, { className: "gap-1 w-auto", children: [_jsx(FieldLabel, { htmlFor: `${id}-from`, children: "From" }), _jsx(Input, { id: `${id}-from`, type: "date", value: from, onChange: (e) => setFrom(e.target.value) })] }), _jsx(Button, { type: "submit", size: "sm", disabled: setBasis.isPending, children: "Save" })] })) : null] }, item.account))) }), bases.data?.truncated ? (_jsx("p", { className: "text-xs text-muted-foreground", children: "Only the first people are listed." })) : null] }));
|
|
160
146
|
}
|
|
@@ -8,6 +8,9 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
8
8
|
// sideways inside its own box; the page does not.
|
|
9
9
|
import { rosterRefusal, } from "@composable-os/pack-rostering/client";
|
|
10
10
|
import { useId, useState } from "react";
|
|
11
|
+
import { Checkbox } from "../ui-checkbox/checkbox.js";
|
|
12
|
+
import { FieldError } from "../ui-field/field.js";
|
|
13
|
+
import { Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow, } from "../ui-table/table.js";
|
|
11
14
|
const key = (account, object, id) => `${account}\u0000${object}\u0000${id}`;
|
|
12
15
|
export function Qualifications({ rostering }) {
|
|
13
16
|
const me = rostering.useMe();
|
|
@@ -21,7 +24,7 @@ export function Qualifications({ rostering }) {
|
|
|
21
24
|
if (me.isPending)
|
|
22
25
|
return _jsx("p", { "aria-busy": "true", children: "Loading\u2026" });
|
|
23
26
|
if (me.error || !me.data)
|
|
24
|
-
return _jsx(
|
|
27
|
+
return _jsx(FieldError, { children: rosterRefusal(me.error).message });
|
|
25
28
|
if (!rosters) {
|
|
26
29
|
return (_jsx("p", { role: "status", "data-refusal": "rostering", children: "Who may do which work is set by whoever rosters." }));
|
|
27
30
|
}
|
|
@@ -40,9 +43,9 @@ export function Qualifications({ rostering }) {
|
|
|
40
43
|
await ticks.refetch?.();
|
|
41
44
|
setPending(null);
|
|
42
45
|
}
|
|
43
|
-
return (_jsxs("section", { className: "grid gap-3", "aria-labelledby": headingId, children: [_jsx("h2", { id: headingId, className: "text-lg font-medium", children: "Who may do which work" }), _jsx("p", { className: "text-sm text-muted-foreground", children: "A ticked person can take an offered shift of that kind without anyone approving it." }), refusal ?
|
|
46
|
+
return (_jsxs("section", { className: "grid gap-3", "aria-labelledby": headingId, children: [_jsx("h2", { id: headingId, className: "text-lg font-medium", children: "Who may do which work" }), _jsx("p", { className: "text-sm text-muted-foreground", children: "A ticked person can take an offered shift of that kind without anyone approving it." }), refusal ? _jsx(FieldError, { "data-refusal": refusal.kind, children: refusal.message }) : null, people.isPending || ticks.isPending ? _jsx("p", { "aria-busy": "true", children: "Loading\u2026" }) : null, people.error ? _jsx(FieldError, { children: rosterRefusal(people.error).message }) : null, people.data && !kinds.length ? (_jsx("p", { children: "There are no class types or duties yet. Add them first." })) : null, people.data && kinds.length ? (_jsx("div", { className: "max-w-full overflow-x-auto rounded-md border", "data-testid": "qualifications-grid", children: _jsxs(Table, { className: "text-sm", children: [_jsx(TableCaption, { className: "sr-only", children: "People down, kinds of work across" }), _jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { scope: "col", className: "sticky left-0 bg-background p-2 text-left", children: "Person" }), kinds.map((k) => (_jsxs(TableHead, { scope: "col", className: "p-2 text-left font-medium", children: [k.name, _jsx("span", { className: "block text-xs font-normal text-muted-foreground", children: k.objectLabel })] }, `${k.object}:${k.id}`)))] }) }), _jsx(TableBody, { children: people.data.people.map((p) => (_jsxs(TableRow, { className: "border-t", children: [_jsx(TableHead, { scope: "row", className: "sticky left-0 bg-background p-2 text-left font-normal", children: p.name }), kinds.map((k) => {
|
|
44
47
|
const ck = key(p.account, k.object, k.id);
|
|
45
48
|
const on = held.has(ck);
|
|
46
|
-
return (_jsx(
|
|
49
|
+
return (_jsx(TableCell, { className: "p-2 text-center", children: _jsx(Checkbox, { className: "size-5", "aria-label": `${p.name} may do ${k.name}`, checked: on, disabled: pending === ck, onCheckedChange: (next) => toggle(p.account, { object: k.object, id: k.id }, next === true) }) }, ck));
|
|
47
50
|
})] }, p.account))) })] }) })) : null, people.data?.truncated ? (_jsx("p", { className: "text-xs text-muted-foreground", children: "Only the first people are listed." })) : null] }));
|
|
48
51
|
}
|
|
@@ -11,26 +11,11 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
11
11
|
// other shift, nobody_qualified, the cut-off, a locked pay period, someone who no longer rosters).
|
|
12
12
|
// Why a shift was not worked is forgotten once the call is over and when the page is left.
|
|
13
13
|
import { dateIn, forgetAfter, refusalNext, rosterRefusal, shiftTime, warningLabel, } from "@composable-os/pack-rostering/client";
|
|
14
|
-
import {
|
|
14
|
+
import { useId, useState } from "react";
|
|
15
15
|
import { Button } from "../ui-button/button.js";
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
latest.current = forget;
|
|
20
|
-
useEffect(() => {
|
|
21
|
-
const hide = () => latest.current();
|
|
22
|
-
const show = (event) => {
|
|
23
|
-
if (event.persisted)
|
|
24
|
-
latest.current();
|
|
25
|
-
};
|
|
26
|
-
window.addEventListener("pagehide", hide);
|
|
27
|
-
window.addEventListener("pageshow", show);
|
|
28
|
-
return () => {
|
|
29
|
-
window.removeEventListener("pagehide", hide);
|
|
30
|
-
window.removeEventListener("pageshow", show);
|
|
31
|
-
};
|
|
32
|
-
}, []);
|
|
33
|
-
}
|
|
16
|
+
import { Field, FieldError, FieldLabel } from "../ui-field/field.js";
|
|
17
|
+
import { useForgetOnLeave } from "../ui-hooks/use-forget-on-leave.js";
|
|
18
|
+
import { Input } from "../ui-input/input.js";
|
|
34
19
|
export function Assign({ rostering, shift, zone, today, locale = "en-AU", onClose, onChanged, }) {
|
|
35
20
|
const candidates = rostering.useCandidates({ object: shift.object, id: shift.id });
|
|
36
21
|
const assign = rostering.useAssign();
|
|
@@ -91,9 +76,9 @@ export function Assign({ rostering, shift, zone, today, locale = "en-AU", onClos
|
|
|
91
76
|
},
|
|
92
77
|
]
|
|
93
78
|
: [];
|
|
94
|
-
return (_jsxs("aside", { className: "grid content-start gap-3 rounded-md border p-3", "aria-labelledby": headingId, children: [_jsxs("header", { className: "flex items-start justify-between gap-2", children: [_jsxs("div", { children: [_jsx("h3", { id: headingId, className: "font-medium", children: shift.title }), _jsxs("p", { className: "text-sm text-muted-foreground", children: [shiftTime(shift, zone, { withDate: true, locale }), shift.place ? ` · ${shift.place}` : ""] })] }), _jsx(Button, { type: "button", variant: "outline", onClick: onClose, "aria-label": "Close the shift", children: "Close" })] }), refusal ? (_jsxs(
|
|
79
|
+
return (_jsxs("aside", { className: "grid content-start gap-3 rounded-md border p-3", "aria-labelledby": headingId, children: [_jsxs("header", { className: "flex items-start justify-between gap-2", children: [_jsxs("div", { children: [_jsx("h3", { id: headingId, className: "font-medium", children: shift.title }), _jsxs("p", { className: "text-sm text-muted-foreground", children: [shiftTime(shift, zone, { withDate: true, locale }), shift.place ? ` · ${shift.place}` : ""] })] }), _jsx(Button, { type: "button", variant: "outline", onClick: onClose, "aria-label": "Close the shift", children: "Close" })] }), refusal ? (_jsxs(FieldError, { className: "rounded-md border border-destructive p-2", "data-refusal": refusal.kind, children: [_jsx("p", { children: refusal.message }), refusal.dates?.length ? _jsxs("p", { children: ["Dates: ", refusal.dates.join(", ")] }) : null, refusalNext(refusal.kind, true) ? _jsx("p", { children: refusalNext(refusal.kind, true) }) : null] })) : null, done ? (_jsx("p", { role: "status", className: "text-sm", children: done })) : null, candidates.isPending ? _jsx("p", { "aria-busy": "true", children: "Loading who could take it\u2026" }) : null, candidates.error ? (_jsx(FieldError, { "data-refusal": rosterRefusal(candidates.error).kind, children: rosterRefusal(candidates.error).message })) : null, data ? (_jsxs(_Fragment, { children: [_jsxs("p", { className: "text-sm", children: ["On it now: ", _jsx("strong", { children: data.current.name ?? "nobody" })] }), data.pattern ? (_jsxs("div", { className: "grid gap-1 text-sm", children: [_jsxs("p", { children: ["Its regular person: ", data.pattern.name ?? "nobody", data.pattern.own ? " (this date keeps its own person)" : ""] }), data.pattern.own ? (_jsx(Button, { type: "button", variant: "outline", disabled: busy, onClick: () => act(() => follow.mutateAsync({ object: shift.object, id: shift.id }), "Back to the pattern."), children: "Back to the pattern" })) : null] })) : null, _jsxs("div", { className: "flex flex-wrap gap-2", children: [data.current.account ? (_jsxs(Button, { type: "button", variant: "outline", disabled: busy, onClick: () => act(() => assign.mutateAsync({ object: shift.object, id: shift.id, account: null }), "Nobody is on it now."), children: ["Take ", data.current.name ?? "them", " off it"] })) : null, shift.offer ? null : (_jsx(Button, { type: "button", variant: "outline", disabled: busy, onClick: () => act(() => offer.mutateAsync({ object: shift.object, id: shift.id }), "Offered to everyone who could take it."), children: "Offer to everyone" }))] }), data.truncated ? (_jsx("p", { className: "text-xs text-muted-foreground", children: "Only the first people are listed." })) : null, groups.map((group) => group.people.length ? (_jsxs("section", { className: "grid gap-1", "aria-label": group.title, children: [_jsx("h4", { className: "text-sm font-medium", children: group.title }), _jsx("ul", { className: "grid gap-1", children: group.people.map((p) => (_jsxs("li", { className: "flex flex-wrap items-center justify-between gap-2 rounded border p-1.5 text-sm", children: [_jsxs("span", { children: [p.name, p.account === data.current.account ? " (on it)" : "", p.warnings.map((w) => (_jsx("span", { className: "ml-1 rounded border px-1 text-xs", title: w.message, "data-warning": w.code, children: warningLabel(w.code) }, w.code))), p.clash ? (_jsxs("span", { className: "block text-xs text-muted-foreground", children: ["On ", p.clash.title, ", ", shiftTime(p.clash, zone, { locale })] })) : null, p.noProfile ? (_jsx("span", { className: "block text-xs text-muted-foreground", children: "No profile this shift can name" })) : null] }), p.account === data.current.account ? null : (_jsx(Button, { type: "button", size: "sm", variant: p.eligible ? "default" : "outline", disabled: busy || Boolean(p.clash) || p.noProfile, "aria-label": `Put ${p.name} on it`, onClick: () => act(() => assign.mutateAsync({
|
|
95
80
|
object: shift.object,
|
|
96
81
|
id: shift.id,
|
|
97
82
|
account: p.account,
|
|
98
|
-
}), `${p.name} is on it now.`), children: "Put on" }))] }, p.account))) })] }, group.title)) : null), dateIn(shift.startsAt, zone) <= today && !shift.uncovered ? (_jsxs("form", { className: "grid gap-1", onSubmit: markNotWorked, "aria-label": "Mark not worked", children: [
|
|
83
|
+
}), `${p.name} is on it now.`), children: "Put on" }))] }, p.account))) })] }, group.title)) : null), dateIn(shift.startsAt, zone) <= today && !shift.uncovered ? (_jsxs("form", { className: "grid gap-1", onSubmit: markNotWorked, "aria-label": "Mark not worked", children: [_jsxs(Field, { className: "gap-1", children: [_jsx(FieldLabel, { htmlFor: reasonId, className: "font-medium", children: "Not worked? Say why (kept with the shift, for pay)" }), _jsx(Input, { id: reasonId, value: reason, maxLength: 500, autoComplete: "off", onChange: (e) => setReason(e.target.value) })] }), _jsx(Button, { type: "submit", variant: "outline", disabled: busy, children: "Mark not worked" })] })) : null] })) : null] }));
|
|
99
84
|
}
|
|
@@ -13,7 +13,10 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
13
13
|
// says the reader may see it; `shiftExtra` takes the checklist itself (rostering-checklist).
|
|
14
14
|
import { addDays, checklistStateLabel, clockChange, dayLabel, personOn, rosterRefusal, shiftName, shiftsByDay, shiftTime, warningLabel, weekOf, } from "@composable-os/pack-rostering/client";
|
|
15
15
|
import { useId, useState } from "react";
|
|
16
|
+
import { Badge } from "../ui-badge/badge.js";
|
|
16
17
|
import { Button } from "../ui-button/button.js";
|
|
18
|
+
import { FieldError } from "../ui-field/field.js";
|
|
19
|
+
import { ItemButton } from "../ui-item/item.js";
|
|
17
20
|
import { Assign } from "./assign.js";
|
|
18
21
|
/** The hooks the assign panel calls, when the client holds every one of them. */
|
|
19
22
|
function assignHooks(h) {
|
|
@@ -50,7 +53,7 @@ export function RosterWeek({ rostering, from, locale = "en-AU", shiftExtra, }) {
|
|
|
50
53
|
if (me.isPending)
|
|
51
54
|
return _jsx("p", { "aria-busy": "true", children: "Loading the roster\u2026" });
|
|
52
55
|
if (me.error || !me.data) {
|
|
53
|
-
return _jsx(
|
|
56
|
+
return _jsx(FieldError, { children: rosterRefusal(me.error).message });
|
|
54
57
|
}
|
|
55
58
|
const today = me.data.today;
|
|
56
59
|
const assigning = me.data.rosters ? assignHooks(rostering) : null;
|
|
@@ -60,13 +63,23 @@ export function RosterWeek({ rostering, from, locale = "en-AU", shiftExtra, }) {
|
|
|
60
63
|
setOpen(null);
|
|
61
64
|
setStart(weekOf(date));
|
|
62
65
|
};
|
|
63
|
-
return (_jsxs("section", { className: "grid gap-4", "aria-labelledby": headingId, children: [_jsxs("header", { className: "flex flex-wrap items-center justify-between gap-2", children: [_jsxs("h2", { id: headingId, className: "text-lg font-medium", children: ["Roster", 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", onClick: () => first && go(addDays(first, -7)), "aria-label": "Previous week", children: "\u2039 Previous" }), _jsx(Button, { type: "button", variant: "outline", onClick: () => go(today), children: "This week" }), _jsx(Button, { type: "button", variant: "outline", onClick: () => first && go(addDays(first, 7)), "aria-label": "Next week", children: "Next \u203A" })] })] }), _jsxs("p", { className: "text-sm text-muted-foreground", children: ["Times are in ", zone, ".", rosters ? " Choose a shift to put someone on it." : ""] }), week.isPending ? _jsx("p", { "aria-busy": "true", children: "Loading the week\u2026" }) : null, week.error ? _jsx(
|
|
66
|
+
return (_jsxs("section", { className: "grid gap-4", "aria-labelledby": headingId, children: [_jsxs("header", { className: "flex flex-wrap items-center justify-between gap-2", children: [_jsxs("h2", { id: headingId, className: "text-lg font-medium", children: ["Roster", 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", onClick: () => first && go(addDays(first, -7)), "aria-label": "Previous week", children: "\u2039 Previous" }), _jsx(Button, { type: "button", variant: "outline", onClick: () => go(today), children: "This week" }), _jsx(Button, { type: "button", variant: "outline", onClick: () => first && go(addDays(first, 7)), "aria-label": "Next week", children: "Next \u203A" })] })] }), _jsxs("p", { className: "text-sm text-muted-foreground", children: ["Times are in ", zone, ".", rosters ? " Choose a shift to put someone on it." : ""] }), week.isPending ? _jsx("p", { "aria-busy": "true", children: "Loading the week\u2026" }) : null, week.error ? _jsx(FieldError, { children: rosterRefusal(week.error).message }) : null, week.data?.truncated ? (_jsx("p", { role: "status", className: "rounded-md border p-2 text-sm", children: "This week has more shifts than one screen shows: the first ones are shown." })) : null, week.data ? (_jsxs("div", { className: "grid gap-4 lg:grid-cols-[1fr_minmax(18rem,22rem)]", children: [_jsx("ol", { className: "grid grid-cols-1 gap-3 md:grid-cols-7", "aria-label": "Days of the week", children: shiftsByDay(week.data).map(({ day, shifts }) => {
|
|
64
67
|
const change = clockChange(day);
|
|
65
68
|
return (_jsxs("li", { className: "min-w-0 rounded-md border p-2", "data-date": day.date, "data-today": day.date === today ? "true" : undefined, children: [_jsxs("h3", { className: "text-sm font-medium", children: [dayLabel(day.date, locale), day.date === today ? " (today)" : ""] }), change ? (_jsx("p", { className: "text-xs text-muted-foreground", "data-testid": "clock-change", children: change })) : null, shifts.length ? (_jsx("ul", { className: "mt-2 grid gap-2", "aria-label": `Shifts on ${dayLabel(day.date, locale, true)}`, children: shifts.map((shift) => (_jsxs("li", { children: [_jsx(ShiftCard, { shift: shift, zone: zone, locale: locale, selected: open?.id === shift.id, onOpen: rosters ? () => setOpen(shift) : undefined }), shiftExtra?.(shift)] }, `${shift.object}:${shift.id}`))) })) : (_jsx("p", { className: "mt-2 text-xs text-muted-foreground", children: "No shifts" }))] }, day.date));
|
|
66
69
|
}) }), open && assigning ? (_jsx(Assign, { rostering: assigning, shift: open, zone: zone, today: today, locale: locale, onClose: () => setOpen(null), onChanged: () => week.refetch?.() })) : null] })) : null] }));
|
|
67
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* A time range that breaks only after its dash: a narrow day column keeps `6:30 am` whole,
|
|
73
|
+
* never `6:30` on one line and `am` on the next.
|
|
74
|
+
*/
|
|
75
|
+
function Unbroken({ text }) {
|
|
76
|
+
const [start, end] = text.split("–", 2);
|
|
77
|
+
if (end === undefined)
|
|
78
|
+
return _jsx("span", { className: "whitespace-nowrap", children: text });
|
|
79
|
+
return (_jsxs(_Fragment, { children: [_jsxs("span", { className: "whitespace-nowrap", children: [start, "\u2013"] }), _jsx("wbr", {}), _jsx("span", { className: "whitespace-nowrap", children: end })] }));
|
|
80
|
+
}
|
|
68
81
|
function ShiftCard({ shift, zone, locale, selected, onOpen, }) {
|
|
69
|
-
const body = (_jsxs(_Fragment, { children: [_jsx("span", { className: "block text-xs text-muted-foreground", children: shiftTime(shift, zone, { locale }) }), _jsx("span", { className: "block font-medium", children: shift.title }), shift.place ? _jsx("span", { className: "block text-xs", children: shift.place }) : null, _jsx("span", { className: `block text-xs ${shift.uncovered ? "font-semibold" : ""}`, children: personOn(shift) }), shift.offer ? (_jsx("span", { className: "mt-1 inline-block rounded border px-1 text-xs", children: "Offered" })) : null, shift.checklist ? (_jsxs("span", { className: "mt-1 mr-1 inline-block rounded border px-1 text-xs", "data-checklist": shift.checklist.state ?? "hidden", children: [shift.checklist.name, shift.checklist.state ? `: ${checklistStateLabel(shift.checklist.state)}` : ""] })) : null, (shift.warnings ?? []).map((w) => (_jsx("
|
|
82
|
+
const body = (_jsxs(_Fragment, { children: [_jsx("span", { className: "block text-xs text-muted-foreground", children: _jsx(Unbroken, { text: shiftTime(shift, zone, { locale }) }) }), _jsx("span", { className: "block font-medium", children: shift.title }), shift.place ? _jsx("span", { className: "block text-xs", children: shift.place }) : null, _jsx("span", { className: `block text-xs ${shift.uncovered ? "font-semibold" : ""}`, children: personOn(shift) }), shift.offer ? (_jsx("span", { className: "mt-1 inline-block rounded border px-1 text-xs", children: "Offered" })) : null, shift.checklist ? (_jsxs("span", { className: "mt-1 mr-1 inline-block rounded border px-1 text-xs", "data-checklist": shift.checklist.state ?? "hidden", children: [shift.checklist.name, shift.checklist.state ? `: ${checklistStateLabel(shift.checklist.state)}` : ""] })) : null, (shift.warnings ?? []).map((w) => (_jsx(Badge, { variant: "destructive", className: "mt-1 mr-1", title: w.message, "data-warning": w.code, children: warningLabel(w.code) }, `${w.code}:${w.account ?? ""}`)))] }));
|
|
70
83
|
const look = [
|
|
71
84
|
"block w-full rounded-md border border-l-4 p-2 text-left text-sm",
|
|
72
85
|
colourOf(shift),
|
|
@@ -76,7 +89,7 @@ function ShiftCard({ shift, zone, locale, selected, onOpen, }) {
|
|
|
76
89
|
].join(" ");
|
|
77
90
|
const name = shiftName(shift, zone, locale);
|
|
78
91
|
if (onOpen) {
|
|
79
|
-
return (_jsx(
|
|
92
|
+
return (_jsx(ItemButton, { variant: "default", className: look, "aria-label": name, "aria-pressed": selected, "data-shift": shift.id, "data-mine": shift.mine ? "true" : undefined, "data-uncovered": shift.uncovered ? "true" : undefined, onClick: onOpen, children: body }));
|
|
80
93
|
}
|
|
81
94
|
return (_jsx("article", { className: look, "aria-label": name, "data-shift": shift.id, "data-mine": shift.mine ? "true" : undefined, "data-uncovered": shift.uncovered ? "true" : undefined, children: body }));
|
|
82
95
|
}
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ClientHolding, forgetAfter, type PackClient, type UseMutation, type UseQuery } from "@composable-os/client";
|
|
1
|
+
import { addDays, type ClientHolding, dateIn, forgetAfter, formatClockValue, formatDay, type PackClient, type UseMutation, type UseQuery, weekOf } from "@composable-os/client";
|
|
2
2
|
import type { z } from "@composable-os/sdk";
|
|
3
3
|
import type { assign, away, awayFor, awayList, back, candidates, check, checklist, checklistCorrect, checklistDone, checklistRuns, exportPeriod, feed, feedRevoke, feedRotate, follow, lock, markNotWorked, me, mine, myAway, myPay, myPayPeriods, offer, offers, patterns, payBases, payBasis, people, periods, periodTotals, planCheck, qualifications, qualify, reopen, setPattern, take, tick, uncovered, week, withdraw } from "../tools.ts";
|
|
4
4
|
export { forgetAfter };
|
|
@@ -181,19 +181,14 @@ export type RosteringClient = PackClient<RosteringOperations>;
|
|
|
181
181
|
/** The days of a regular week, Monday first, as the host names them and as a person reads them. */
|
|
182
182
|
export declare const WEEKDAYS: readonly [readonly ["mon", "Monday"], readonly ["tue", "Tuesday"], readonly ["wed", "Wednesday"], readonly ["thu", "Thursday"], readonly ["fri", "Friday"], readonly ["sat", "Saturday"], readonly ["sun", "Sunday"]];
|
|
183
183
|
export type Weekday = (typeof WEEKDAYS)[number][0];
|
|
184
|
-
|
|
185
|
-
export declare function addDays(date: string, days: number): string;
|
|
186
|
-
/** The Monday on or before a `YYYY-MM-DD` date (the week a date is in). */
|
|
187
|
-
export declare function weekOf(date: string): string;
|
|
184
|
+
export { addDays, dateIn, formatClockValue, formatDay, weekOf };
|
|
188
185
|
/** A `YYYY-MM-DD` date as a person reads it ("Tue 3 Mar"). The date as given, in no zone. */
|
|
189
186
|
export declare function dayLabel(date: string, locale?: string, long?: boolean): string;
|
|
190
|
-
/** An instant's time of day in a zone ("
|
|
191
|
-
export declare
|
|
192
|
-
/** An instant's local date in a zone (`YYYY-MM-DD`). */
|
|
193
|
-
export declare function dateIn(iso: string, zone: string): string;
|
|
187
|
+
/** An instant's time of day in a zone ("6:00 am"). */
|
|
188
|
+
export declare const timeIn: (iso: string, zone: string, locale?: string) => string;
|
|
194
189
|
/**
|
|
195
|
-
* A shift's times as a person reads them, in the shift's own zone (or the roster's): "
|
|
196
|
-
* with the date first when asked ("Tue 3 Mar,
|
|
190
|
+
* A shift's times as a person reads them, in the shift's own zone (or the roster's): "6:00 am–7:00 am",
|
|
191
|
+
* with the date first when asked ("Tue 3 Mar, 6:00 am–7:00 am"), and the end's date when it ends on
|
|
197
192
|
* another day (across midnight).
|
|
198
193
|
*/
|
|
199
194
|
export declare function shiftTime(shift: {
|
|
@@ -227,7 +222,7 @@ export declare function warningLabel(code: StaffWarning["code"]): string;
|
|
|
227
222
|
export declare function awayWhen(item: AwayItem, locale?: string): string;
|
|
228
223
|
/** A time off's kind as a person reads it. */
|
|
229
224
|
export declare function awayKind(kind: AwayItem["kind"]): string;
|
|
230
|
-
/** A pattern's regular week as a person reads it ("Mon, Wed
|
|
225
|
+
/** A pattern's regular week as a person reads it ("Mon, Wed 6:00 am 1 h"). */
|
|
231
226
|
export declare function patternWhen(p: Pattern): string;
|
|
232
227
|
/**
|
|
233
228
|
* A calendar feed's address, from the host's origin (`https://admin.example.com`) and the path the
|
package/dist/client/index.js
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
// call is over (`forgetAfter`).
|
|
20
20
|
// A checklist (step 4b, ADR 0650) is the same: what someone wrote on a step, why it was not done
|
|
21
21
|
// and why it was ticked for them are on screen only, and never sent in a query's key.
|
|
22
|
-
import { forgetAfter, packHooks, } from "@composable-os/client";
|
|
22
|
+
import { addDays, dateIn, forgetAfter, formatClock, formatClockValue, formatDay, formatMinutes, packHooks, weekOf, } from "@composable-os/client";
|
|
23
23
|
export { forgetAfter };
|
|
24
24
|
// --- Plain functions (display only) --------------------------------------------------------------
|
|
25
25
|
/** The days of a regular week, Monday first, as the host names them and as a person reads them. */
|
|
@@ -32,55 +32,25 @@ export const WEEKDAYS = [
|
|
|
32
32
|
["sat", "Saturday"],
|
|
33
33
|
["sun", "Sunday"],
|
|
34
34
|
];
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return new Date(Date.UTC(y, m - 1, d + days)).toISOString().slice(0, 10);
|
|
39
|
-
}
|
|
40
|
-
/** The Monday on or before a `YYYY-MM-DD` date (the week a date is in). */
|
|
41
|
-
export function weekOf(date) {
|
|
42
|
-
const [y, m, d] = date.split("-").map(Number);
|
|
43
|
-
const weekday = (new Date(Date.UTC(y, m - 1, d)).getUTCDay() + 6) % 7;
|
|
44
|
-
return addDays(date, -weekday);
|
|
45
|
-
}
|
|
35
|
+
// Calendar dates and clock times as every screen reads them (`@composable-os/client`, issue #577):
|
|
36
|
+
// a date `days` later, the Monday of a date's week, and a moment's date in a zone.
|
|
37
|
+
export { addDays, dateIn, formatClockValue, formatDay, weekOf };
|
|
46
38
|
/** A `YYYY-MM-DD` date as a person reads it ("Tue 3 Mar"). The date as given, in no zone. */
|
|
47
|
-
export function dayLabel(date, locale
|
|
48
|
-
|
|
49
|
-
return new Intl.DateTimeFormat(locale, {
|
|
50
|
-
weekday: long ? "long" : "short",
|
|
51
|
-
day: "numeric",
|
|
52
|
-
month: "short",
|
|
53
|
-
timeZone: "UTC",
|
|
54
|
-
}).format(new Date(Date.UTC(y, m - 1, d)));
|
|
55
|
-
}
|
|
56
|
-
/** An instant's time of day in a zone ("06:00"). */
|
|
57
|
-
export function timeIn(iso, zone, locale = "en-AU") {
|
|
58
|
-
return new Intl.DateTimeFormat(locale, {
|
|
59
|
-
hour: "2-digit",
|
|
60
|
-
minute: "2-digit",
|
|
61
|
-
hourCycle: "h23",
|
|
62
|
-
timeZone: zone,
|
|
63
|
-
}).format(new Date(iso));
|
|
64
|
-
}
|
|
65
|
-
/** An instant's local date in a zone (`YYYY-MM-DD`). */
|
|
66
|
-
export function dateIn(iso, zone) {
|
|
67
|
-
return new Intl.DateTimeFormat("en-CA", {
|
|
68
|
-
year: "numeric",
|
|
69
|
-
month: "2-digit",
|
|
70
|
-
day: "2-digit",
|
|
71
|
-
timeZone: zone,
|
|
72
|
-
}).format(new Date(iso));
|
|
39
|
+
export function dayLabel(date, locale, long = false) {
|
|
40
|
+
return formatDay(date, { weekday: long ? "long" : "short", year: false, locale });
|
|
73
41
|
}
|
|
42
|
+
/** An instant's time of day in a zone ("6:00 am"). */
|
|
43
|
+
export const timeIn = formatClock;
|
|
74
44
|
/**
|
|
75
|
-
* A shift's times as a person reads them, in the shift's own zone (or the roster's): "
|
|
76
|
-
* with the date first when asked ("Tue 3 Mar,
|
|
45
|
+
* A shift's times as a person reads them, in the shift's own zone (or the roster's): "6:00 am–7:00 am",
|
|
46
|
+
* with the date first when asked ("Tue 3 Mar, 6:00 am–7:00 am"), and the end's date when it ends on
|
|
77
47
|
* another day (across midnight).
|
|
78
48
|
*/
|
|
79
49
|
export function shiftTime(shift, zone, options = {}) {
|
|
80
50
|
if (!shift.startsAt)
|
|
81
51
|
return "";
|
|
82
52
|
const z = shift.zone ?? zone;
|
|
83
|
-
const locale = options.locale
|
|
53
|
+
const locale = options.locale;
|
|
84
54
|
const startDate = dateIn(shift.startsAt, z);
|
|
85
55
|
const start = timeIn(shift.startsAt, z, locale);
|
|
86
56
|
let end = "";
|
|
@@ -153,7 +123,7 @@ export function awayWhen(item, locale = "en-AU") {
|
|
|
153
123
|
const range = item.untilDate
|
|
154
124
|
? `from ${dayLabel(item.fromDate ?? "", locale)} until ${dayLabel(item.untilDate, locale)}`
|
|
155
125
|
: `from ${dayLabel(item.fromDate ?? "", locale)}`;
|
|
156
|
-
return `Every ${days}, ${item.startTime}–${item.endTime}, ${range}`;
|
|
126
|
+
return `Every ${days}, ${formatClockValue(item.startTime ?? "")}–${formatClockValue(item.endTime ?? "")}, ${range}`;
|
|
157
127
|
}
|
|
158
128
|
if (!item.startsAt || !item.endsAt)
|
|
159
129
|
return "";
|
|
@@ -163,12 +133,14 @@ export function awayWhen(item, locale = "en-AU") {
|
|
|
163
133
|
export function awayKind(kind) {
|
|
164
134
|
return kind === "leave" ? "Leave" : kind === "regular" ? "Regular time off" : "Away";
|
|
165
135
|
}
|
|
166
|
-
/** A pattern's regular week as a person reads it ("Mon, Wed
|
|
136
|
+
/** A pattern's regular week as a person reads it ("Mon, Wed 6:00 am 1 h"). */
|
|
167
137
|
export function patternWhen(p) {
|
|
168
138
|
const days = WEEKDAYS.filter(([d]) => p.weekdays.includes(d))
|
|
169
139
|
.map(([, name]) => name.slice(0, 3))
|
|
170
140
|
.join(", ");
|
|
171
|
-
return [days, p.time
|
|
141
|
+
return [days, p.time ? formatClockValue(p.time) : null, formatMinutes(p.length) || null]
|
|
142
|
+
.filter(Boolean)
|
|
143
|
+
.join(" ");
|
|
172
144
|
}
|
|
173
145
|
/**
|
|
174
146
|
* A calendar feed's address, from the host's origin (`https://admin.example.com`) and the path the
|