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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/LICENSE +109 -0
  2. package/dist/blocks/rostering-away/away-list.d.ts +8 -0
  3. package/dist/blocks/rostering-away/away-list.js +101 -0
  4. package/dist/blocks/rostering-checklist/checklist.d.ts +9 -0
  5. package/dist/blocks/rostering-checklist/checklist.js +132 -0
  6. package/dist/blocks/rostering-checklist/my-shifts-with-checklist.d.ts +11 -0
  7. package/dist/blocks/rostering-checklist/my-shifts-with-checklist.js +6 -0
  8. package/dist/blocks/rostering-checklists/checklists.d.ts +11 -0
  9. package/dist/blocks/rostering-checklists/checklists.js +76 -0
  10. package/dist/blocks/rostering-my-availability/my-availability.d.ts +7 -0
  11. package/dist/blocks/rostering-my-availability/my-availability.js +143 -0
  12. package/dist/blocks/rostering-my-calendar/my-calendar.d.ts +6 -0
  13. package/dist/blocks/rostering-my-calendar/my-calendar.js +92 -0
  14. package/dist/blocks/rostering-my-shifts/my-hours.d.ts +6 -0
  15. package/dist/blocks/rostering-my-shifts/my-hours.js +63 -0
  16. package/dist/blocks/rostering-my-shifts/my-shifts.d.ts +17 -0
  17. package/dist/blocks/rostering-my-shifts/my-shifts.js +53 -0
  18. package/dist/blocks/rostering-native-checklist/checklist-screen.d.ts +8 -0
  19. package/dist/blocks/rostering-native-checklist/checklist-screen.js +110 -0
  20. package/dist/blocks/rostering-native-my-availability/my-availability-screen.d.ts +7 -0
  21. package/dist/blocks/rostering-native-my-availability/my-availability-screen.js +110 -0
  22. package/dist/blocks/rostering-native-my-calendar/my-calendar-screen.d.ts +10 -0
  23. package/dist/blocks/rostering-native-my-calendar/my-calendar-screen.js +72 -0
  24. package/dist/blocks/rostering-native-my-shifts/my-hours-screen.d.ts +6 -0
  25. package/dist/blocks/rostering-native-my-shifts/my-hours-screen.js +60 -0
  26. package/dist/blocks/rostering-native-my-shifts/my-shifts-screen.d.ts +12 -0
  27. package/dist/blocks/rostering-native-my-shifts/my-shifts-screen.js +56 -0
  28. package/dist/blocks/rostering-native-offers/offers-screen.d.ts +7 -0
  29. package/dist/blocks/rostering-native-offers/offers-screen.js +56 -0
  30. package/dist/blocks/rostering-native-roster/roster-screen.d.ts +7 -0
  31. package/dist/blocks/rostering-native-roster/roster-screen.js +31 -0
  32. package/dist/blocks/rostering-offers/offers.d.ts +7 -0
  33. package/dist/blocks/rostering-offers/offers.js +52 -0
  34. package/dist/blocks/rostering-patterns/patterns.d.ts +7 -0
  35. package/dist/blocks/rostering-patterns/patterns.js +58 -0
  36. package/dist/blocks/rostering-pay/pay.d.ts +7 -0
  37. package/dist/blocks/rostering-pay/pay.js +160 -0
  38. package/dist/blocks/rostering-qualifications/qualifications.d.ts +6 -0
  39. package/dist/blocks/rostering-qualifications/qualifications.js +48 -0
  40. package/dist/blocks/rostering-week/assign.d.ts +12 -0
  41. package/dist/blocks/rostering-week/assign.js +99 -0
  42. package/dist/blocks/rostering-week/week.d.ts +13 -0
  43. package/dist/blocks/rostering-week/week.js +82 -0
  44. package/dist/client/index.d.ts +3113 -0
  45. package/dist/client/index.js +654 -0
  46. package/dist/index.d.ts +1594 -0
  47. package/dist/index.js +541 -0
  48. package/dist/tools.d.ts +1094 -0
  49. package/dist/tools.js +1047 -0
  50. package/package.json +36 -4
  51. package/README.md +0 -3
@@ -0,0 +1,654 @@
1
+ // The Rostering pack's headless entry (stage 45 step 7; ADR 0418): functions and hooks over the
2
+ // typed client, no markup. A client app imports it as `@composable-os/pack-rostering/client` and
3
+ // hands it its client; the rostering blocks (web and native) render what it returns. Web and
4
+ // native share this logic, not their screens (ADR 0403).
5
+ //
6
+ // As every pack's entry: the operations are typed from the pack's own tool schemas, it takes the
7
+ // client and the app's `useQuery` and `useMutation` as arguments (no React or TanStack import),
8
+ // and it holds no rules. Who may roster, who handles pay, who is qualified, whether a shift
9
+ // clashes, whether a take is allowed, what a pay period totals, and how long each day is in the
10
+ // business's zone are the host's: a block shows the host's answer (`me`, the roster, a refusal),
11
+ // never works one out. The plain functions below only format what the host gave.
12
+ //
13
+ // Who sees what is the host's too: a team member's client may hold the rosterers' hooks (an
14
+ // ordinary staff role holds every pack tool), but a block asks `useMe()` first and shows the
15
+ // rosterers' and pay screens only when the host says `rosters` or `pays`, so it never fetches what
16
+ // the viewer may not see. What someone writes about their time off, why a period was reopened,
17
+ // why a shift was not worked, and pay figures (a person's own hours too) are kept in the app's
18
+ // cache no longer than they are on screen (`gcTime: 0`), and what was sent is forgotten once the
19
+ // call is over (`forgetAfter`).
20
+ // A checklist (step 4b, ADR 0650) is the same: what someone wrote on a step, why it was not done
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";
23
+ export { forgetAfter };
24
+ // --- Plain functions (display only) --------------------------------------------------------------
25
+ /** The days of a regular week, Monday first, as the host names them and as a person reads them. */
26
+ export const WEEKDAYS = [
27
+ ["mon", "Monday"],
28
+ ["tue", "Tuesday"],
29
+ ["wed", "Wednesday"],
30
+ ["thu", "Thursday"],
31
+ ["fri", "Friday"],
32
+ ["sat", "Saturday"],
33
+ ["sun", "Sunday"],
34
+ ];
35
+ /** A `YYYY-MM-DD` date `days` later (or earlier): calendar dates only, no time of day or zone. */
36
+ export function addDays(date, days) {
37
+ const [y, m, d] = date.split("-").map(Number);
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
+ }
46
+ /** 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 = "en-AU", long = false) {
48
+ const [y, m, d] = date.split("-").map(Number);
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));
73
+ }
74
+ /**
75
+ * A shift's times as a person reads them, in the shift's own zone (or the roster's): "06:00–07:00",
76
+ * with the date first when asked ("Tue 3 Mar, 06:00–07:00"), and the end's date when it ends on
77
+ * another day (across midnight).
78
+ */
79
+ export function shiftTime(shift, zone, options = {}) {
80
+ if (!shift.startsAt)
81
+ return "";
82
+ const z = shift.zone ?? zone;
83
+ const locale = options.locale ?? "en-AU";
84
+ const startDate = dateIn(shift.startsAt, z);
85
+ const start = timeIn(shift.startsAt, z, locale);
86
+ let end = "";
87
+ if (shift.endsAt) {
88
+ const endDate = dateIn(shift.endsAt, z);
89
+ end = `–${endDate !== startDate ? `${dayLabel(endDate, locale)} ` : ""}${timeIn(shift.endsAt, z, locale)}`;
90
+ }
91
+ return `${options.withDate ? `${dayLabel(startDate, locale)}, ` : ""}${start}${end}`;
92
+ }
93
+ /** Who is on a shift, as the roster shows it. */
94
+ export function personOn(shift) {
95
+ if (shift.uncovered)
96
+ return "Nobody on it";
97
+ if (shift.noAccount)
98
+ return `${shift.name ?? "A visiting coach"} (no account)`;
99
+ return shift.mine ? `${shift.name ?? "You"} (you)` : (shift.name ?? "Someone");
100
+ }
101
+ /**
102
+ * A shift's accessible name: what it is, when, where and who is on it, in one line a screen
103
+ * reader says ("Close-down clean, Tue 3 Mar, 18:00–19:00, Main floor, Sam (you)").
104
+ */
105
+ export function shiftName(shift, zone, locale = "en-AU") {
106
+ return [
107
+ shift.title,
108
+ shiftTime(shift, zone, { withDate: true, locale }),
109
+ shift.place,
110
+ personOn(shift),
111
+ shift.offer ? "offered" : null,
112
+ ]
113
+ .filter(Boolean)
114
+ .join(", ");
115
+ }
116
+ /**
117
+ * The roster's shifts by local date, in the order the host's `days` lists them (every date of the
118
+ * range, empty ones too). Each shift is put on its start's date in the roster's zone.
119
+ */
120
+ export function shiftsByDay(roster) {
121
+ const byDate = new Map(roster.days.map((d) => [d.date, []]));
122
+ for (const shift of roster.shifts) {
123
+ byDate.get(dateIn(shift.startsAt, roster.zone))?.push(shift);
124
+ }
125
+ return roster.days.map((day) => ({ day, shifts: byDate.get(day.date) ?? [] }));
126
+ }
127
+ /** What a day's length says when the clocks change that day (the host's hours), or null. */
128
+ export function clockChange(day) {
129
+ if (day.hours === 24)
130
+ return null;
131
+ return day.hours < 24
132
+ ? `Clocks go forward: a ${day.hours}-hour day`
133
+ : `Clocks go back: a ${day.hours}-hour day`;
134
+ }
135
+ /** A warning's short words for a badge. */
136
+ export function warningLabel(code) {
137
+ if (code === "unavailable")
138
+ return "Away";
139
+ if (code === "not_qualified")
140
+ return "Not qualified";
141
+ if (code === "outside_hours")
142
+ return "Outside open hours";
143
+ if (code === "client_busy")
144
+ return "Client already booked";
145
+ return "Nobody on it";
146
+ }
147
+ /** A time off as a person reads it, in its own zone. */
148
+ export function awayWhen(item, locale = "en-AU") {
149
+ if (item.kind === "regular") {
150
+ const days = WEEKDAYS.filter(([d]) => item.weekdays.includes(d))
151
+ .map(([, name]) => name)
152
+ .join(", ");
153
+ const range = item.untilDate
154
+ ? `from ${dayLabel(item.fromDate ?? "", locale)} until ${dayLabel(item.untilDate, locale)}`
155
+ : `from ${dayLabel(item.fromDate ?? "", locale)}`;
156
+ return `Every ${days}, ${item.startTime}–${item.endTime}, ${range}`;
157
+ }
158
+ if (!item.startsAt || !item.endsAt)
159
+ return "";
160
+ return `${shiftTime({ startsAt: item.startsAt, endsAt: item.endsAt }, item.zone, { withDate: true, locale })}`;
161
+ }
162
+ /** A time off's kind as a person reads it. */
163
+ export function awayKind(kind) {
164
+ return kind === "leave" ? "Leave" : kind === "regular" ? "Regular time off" : "Away";
165
+ }
166
+ /** A pattern's regular week as a person reads it ("Mon, Wed 06:00, 60 minutes"). */
167
+ export function patternWhen(p) {
168
+ const days = WEEKDAYS.filter(([d]) => p.weekdays.includes(d))
169
+ .map(([, name]) => name.slice(0, 3))
170
+ .join(", ");
171
+ return [days, p.time, p.length ? `${p.length} minutes` : null].filter(Boolean).join(" ");
172
+ }
173
+ /**
174
+ * A calendar feed's address, from the host's origin (`https://admin.example.com`) and the path the
175
+ * host gave once (`feedRotate`): the https address to copy into a calendar app, and the webcal one
176
+ * that opens a phone's calendar to subscribe. Never kept: the screen shows it and forgets it.
177
+ */
178
+ export function feedAddresses(hostUrl, path) {
179
+ const origin = new URL(hostUrl).origin;
180
+ const https = new URL(path, origin).toString().replace(/^http:/, "https:");
181
+ return { https, webcal: https.replace(/^https:/, "webcal:") };
182
+ }
183
+ /** How a shift's checklist is going, as a person reads it. */
184
+ export function checklistStateLabel(state) {
185
+ switch (state) {
186
+ case "not_started":
187
+ return "Not started";
188
+ case "in_progress":
189
+ case "open":
190
+ return "In progress";
191
+ case "done":
192
+ return "Done";
193
+ case "missed":
194
+ return "Missed";
195
+ default:
196
+ return "Cancelled";
197
+ }
198
+ }
199
+ /** A step's tick as every screen shows it: what was ticked, by whom and for whom. */
200
+ export function tickLabel(tick) {
201
+ if (tick.state === "cleared")
202
+ return tick.label;
203
+ return `${tick.done ? "Done" : "Not done"}: ${tick.label}`;
204
+ }
205
+ /** One of your pay periods' state as a person reads it. */
206
+ export function payPeriodState(p) {
207
+ if (p.state === "locked")
208
+ return `Locked${p.version && p.version > 1 ? ` (version ${p.version})` : ""}`;
209
+ return p.ended ? "Ended, not locked yet" : "Open";
210
+ }
211
+ /** A pay basis as a person reads it. */
212
+ export function basisLabel(basis) {
213
+ if (basis === "by_time")
214
+ return "By time (hours)";
215
+ if (basis === "by_class")
216
+ return "By class (shifts)";
217
+ return "Not counted";
218
+ }
219
+ // --- Refusals --------------------------------------------------------------------------------------
220
+ /** A rule the host's refusal names, each with its own designed state. */
221
+ const HOST_RULES = [
222
+ "double_booked",
223
+ "nobody_qualified",
224
+ "not_qualified",
225
+ "no_profile",
226
+ "offer_stale",
227
+ "offer_taken",
228
+ "offer_closed",
229
+ "offer_open",
230
+ "offer_cutoff",
231
+ "own_offer",
232
+ "offered_to_someone_else",
233
+ "unavailable_confirm",
234
+ "shift_not_live",
235
+ "shift_not_started",
236
+ "not_yours",
237
+ "rostering",
238
+ "pay_period_locked",
239
+ "pay_period_held",
240
+ "pay_period_unset",
241
+ "pay_period_open",
242
+ "pay_period_not_locked",
243
+ "pay_period_too_large",
244
+ "roster_changed",
245
+ "recurring_not_generated",
246
+ "recurring_moved",
247
+ "recurring_past",
248
+ "deactivate_confirm",
249
+ "checklist_window",
250
+ "checklist_closed",
251
+ "checklist_not_live",
252
+ "checklist_nobody",
253
+ "checklist_not_yours",
254
+ "checklist_not_your_tick",
255
+ "checklist_nothing_to_clear",
256
+ "checklist_too_many_ticks",
257
+ "checklist_for_why",
258
+ "checklist_note_needed",
259
+ "checklist_why",
260
+ "checklist_incomplete",
261
+ "checklist_open",
262
+ "human_only",
263
+ ];
264
+ function record(value) {
265
+ return value && typeof value === "object" ? value : null;
266
+ }
267
+ /** The host's details of an error: its own, or a pack tool's that carries the host's inside. */
268
+ function hostDetails(error) {
269
+ const details = record(record(error)?.details);
270
+ if (!details)
271
+ return null;
272
+ if (typeof details.rule === "string")
273
+ return details;
274
+ const inner = record(details.details);
275
+ return inner && typeof inner.rule === "string" ? inner : null;
276
+ }
277
+ const KNOWN_RULES = new Set(HOST_RULES);
278
+ const isHostRule = (rule) => KNOWN_RULES.has(rule);
279
+ /** The words for a refusal the host gave without its own (it always gives some). */
280
+ const FALLBACK = {
281
+ forbidden: "You can't do that on the roster. If you think you should, ask whoever runs the roster.",
282
+ not_found: "That is no longer there. It may have been changed or removed: refresh the roster.",
283
+ network: "We could not reach the business just now. Check your connection and try again.",
284
+ other: "That did not work. Try again.",
285
+ };
286
+ /** What the host's refusal of a roster call was, for the screen's designed state. */
287
+ export function rosterRefusal(error) {
288
+ const e = record(error);
289
+ if (e?.name === "NetworkError")
290
+ return { kind: "network", message: FALLBACK.network };
291
+ const outer = record(e?.details);
292
+ // A retried call whose answer the host never keeps (a new calendar address): it was made, but
293
+ // cannot be shown again.
294
+ if (outer?.reason === "idempotency_response_lost") {
295
+ return {
296
+ kind: "address_lost",
297
+ message: "A new address was made, but it could not be shown again, and it is never kept. Make a new address: the one just made stops working.",
298
+ };
299
+ }
300
+ const details = hostDetails(error);
301
+ const rule = typeof details?.rule === "string" ? details.rule : null;
302
+ const message = typeof e?.message === "string" && e.message ? e.message : null;
303
+ if (rule && isHostRule(rule)) {
304
+ const kind = rule;
305
+ const out = { kind, message: message ?? FALLBACK.other };
306
+ if (kind === "offer_taken") {
307
+ out.takenBy = typeof details?.takenBy === "string" ? details.takenBy : null;
308
+ }
309
+ if (kind === "double_booked") {
310
+ if (Array.isArray(details?.dates))
311
+ out.dates = details.dates.map(String);
312
+ const clashes = Array.isArray(details?.clashes) ? details.clashes : [];
313
+ const first = record(record(clashes[0])?.other);
314
+ const other = first ?? record(details?.other);
315
+ if (other && typeof other.title === "string") {
316
+ out.other = {
317
+ title: other.title,
318
+ startsAt: String(other.startsAt ?? ""),
319
+ endsAt: String(other.endsAt ?? ""),
320
+ };
321
+ }
322
+ }
323
+ return out;
324
+ }
325
+ const code = typeof e?.code === "string" ? e.code : null;
326
+ const inner = typeof outer?.code === "string" ? outer.code : null;
327
+ const surface = inner ?? code;
328
+ if (surface === "forbidden")
329
+ return { kind: "forbidden", message: FALLBACK.forbidden };
330
+ if (surface === "not_found")
331
+ return { kind: "not_found", message: FALLBACK.not_found };
332
+ if (surface === "invalid_input" || surface === "validation") {
333
+ return { kind: "invalid", message: message ?? "Something entered is not right." };
334
+ }
335
+ return { kind: "other", message: message ?? FALLBACK.other };
336
+ }
337
+ /** The roster's own copy for a refusal kind that asks the person to do something next. */
338
+ export function refusalNext(kind, rosters) {
339
+ switch (kind) {
340
+ case "double_booked":
341
+ return "Choose someone else, or settle their other shift first.";
342
+ case "nobody_qualified":
343
+ return rosters
344
+ ? "Mark who may do this kind of work on Qualifications, or put someone on it."
345
+ : "Ask whoever rosters to find someone for it.";
346
+ case "offer_taken":
347
+ case "offer_closed":
348
+ case "offer_stale":
349
+ return "The list of offers has been refreshed.";
350
+ case "offer_cutoff":
351
+ return "Offers close before a shift starts: whoever rosters reassigns it now.";
352
+ case "pay_period_locked":
353
+ return "Reopen the pay period first, saying why, then change the shift.";
354
+ case "roster_changed":
355
+ return "Look over the totals again, then lock it.";
356
+ case "rostering":
357
+ case "forbidden":
358
+ return "The screen has been refreshed to what you may do.";
359
+ case "checklist_closed":
360
+ case "checklist_not_yours":
361
+ case "checklist_not_live":
362
+ return "The checklist has been refreshed.";
363
+ case "checklist_not_your_tick":
364
+ return "Someone else ticked this step: whoever rosters can change it.";
365
+ case "checklist_nothing_to_clear":
366
+ return "That step is not ticked, so there is nothing to clear.";
367
+ case "checklist_window":
368
+ return "A checklist can be ticked from when the shift starts until 2 hours after it ends.";
369
+ default:
370
+ return null;
371
+ }
372
+ }
373
+ /**
374
+ * The operations each hook calls (ADR 0453). A `rostering.team` role's client gets the team's
375
+ * hooks; a coach's role client with the grant `rostering:roster` the same; the staff client all
376
+ * of them (the host still refuses what the account does not hold).
377
+ */
378
+ export const ROSTERING_HOOKS_CALL = {
379
+ useMe: ["x.rostering.me"],
380
+ useWeek: ["x.rostering.week"],
381
+ useMine: ["x.rostering.mine"],
382
+ useOffers: ["x.rostering.offers"],
383
+ useOffer: ["x.rostering.offer"],
384
+ useWithdraw: ["x.rostering.withdraw"],
385
+ useTake: ["x.rostering.take"],
386
+ useAway: ["x.rostering.away"],
387
+ useBack: ["x.rostering.back"],
388
+ useMyAway: ["x.rostering.myAway"],
389
+ useMyPayPeriods: ["x.rostering.myPayPeriods"],
390
+ useMyPay: ["x.rostering.myPay"],
391
+ useAssign: ["x.rostering.assign"],
392
+ useCheck: ["x.rostering.check"],
393
+ useCandidates: ["x.rostering.candidates"],
394
+ useFollow: ["x.rostering.follow"],
395
+ usePeople: ["x.rostering.people"],
396
+ usePatterns: ["x.rostering.patterns"],
397
+ useSetPattern: ["x.rostering.setPattern"],
398
+ useQualify: ["x.rostering.qualify"],
399
+ useQualifications: ["x.rostering.qualifications"],
400
+ useAwayFor: ["x.rostering.awayFor"],
401
+ useAwayList: ["x.rostering.awayList"],
402
+ useUncovered: ["x.rostering.uncovered"],
403
+ useMarkNotWorked: ["x.rostering.markNotWorked"],
404
+ usePayBases: ["x.rostering.payBases"],
405
+ usePayBasis: ["x.rostering.payBasis"],
406
+ usePeriods: ["x.rostering.periods"],
407
+ usePeriodTotals: ["x.rostering.periodTotals"],
408
+ useLock: ["x.rostering.lock"],
409
+ useReopen: ["x.rostering.reopen"],
410
+ useExport: ["x.rostering.export"],
411
+ useFeed: ["x.rostering.feed"],
412
+ useFeedRotate: ["x.rostering.feedRotate"],
413
+ useFeedRevoke: ["x.rostering.feedRevoke"],
414
+ useChecklist: ["x.rostering.checklist"],
415
+ useTick: ["x.rostering.tick"],
416
+ useChecklistDone: ["x.rostering.checklistDone"],
417
+ useChecklistRuns: ["x.rostering.checklistRuns"],
418
+ useChecklistCorrect: ["x.rostering.checklistCorrect"],
419
+ };
420
+ /**
421
+ * Hooks for a React or React Native app:
422
+ * `const rostering = createRosteringHooks({ useQuery, useMutation }, api)`. `api` is the client the
423
+ * screen's user holds: a role client (`roles/rostering.team.ts`, or `roles/bookings.coach.ts`
424
+ * generated with the grant `rostering:roster`) or the staff client. The hooks it cannot back are
425
+ * not there.
426
+ */
427
+ export function createRosteringHooks(react, client) {
428
+ return packHooks(client, ROSTERING_HOOKS_CALL, (api) => allRosteringHooks(react, api));
429
+ }
430
+ function allRosteringHooks(react, api) {
431
+ const { useQuery, useMutation } = react;
432
+ return {
433
+ /** Who is reading and what the host lets them do (rosters, pays), the zone and today there. */
434
+ useMe() {
435
+ return useQuery(api.query("x.rostering.me", {}));
436
+ },
437
+ /** The roster from..to (local dates); a rosterer's answer carries each shift's warnings. */
438
+ useWeek(input, enabled = true) {
439
+ // A rosterer's roster carries who is away: kept no longer than it is on screen.
440
+ return useQuery({ ...api.query("x.rostering.week", input), enabled, gcTime: 0 });
441
+ },
442
+ /** My own shifts from..to. */
443
+ useMine(input, enabled = true) {
444
+ return useQuery({ ...api.query("x.rostering.mine", input), enabled });
445
+ },
446
+ /** Offers I could take now, and my own open offers. */
447
+ useOffers() {
448
+ return useQuery(api.query("x.rostering.offers", {}));
449
+ },
450
+ /** Offer a shift (a person's own act). */
451
+ useOffer() {
452
+ return useMutation(api.mutation("x.rostering.offer"));
453
+ },
454
+ /** Withdraw an open offer. */
455
+ useWithdraw() {
456
+ return useMutation(api.mutation("x.rostering.withdraw"));
457
+ },
458
+ /** Take an offered shift; the host may ask to confirm when I said I am away then. */
459
+ useTake() {
460
+ return useMutation(api.mutation("x.rostering.take"));
461
+ },
462
+ /**
463
+ * Say when I cannot work. What I write about it (the note) is not kept once the call is
464
+ * over: call it through `forgetAfter`.
465
+ */
466
+ useAway() {
467
+ return useMutation({ ...api.mutation("x.rostering.away"), gcTime: 0 });
468
+ },
469
+ /** Remove a time off. */
470
+ useBack() {
471
+ return useMutation(api.mutation("x.rostering.back"));
472
+ },
473
+ /** My time off, with my notes: kept no longer than it is on screen. */
474
+ useMyAway(input = {}) {
475
+ return useQuery({ ...api.query("x.rostering.myAway", input), gcTime: 0 });
476
+ },
477
+ /** The pay periods I can see my own hours for: dates and state only. */
478
+ useMyPayPeriods(enabled = true) {
479
+ return useQuery({ ...api.query("x.rostering.myPayPeriods", {}), enabled, gcTime: 0 });
480
+ },
481
+ /**
482
+ * My own hours for one pay period: pay figures, kept no longer than they are on screen. The
483
+ * query's key holds the period's first date only, never a figure.
484
+ */
485
+ useMyPay(input) {
486
+ return useQuery({
487
+ ...api.query("x.rostering.myPay", input ?? {}),
488
+ enabled: input !== null,
489
+ gcTime: 0,
490
+ });
491
+ },
492
+ /** A rosterer: put someone (or nobody) on a shift. */
493
+ useAssign() {
494
+ return useMutation(api.mutation("x.rostering.assign"));
495
+ },
496
+ /** A rosterer: what putting someone on a shift would be made with. */
497
+ useCheck(input) {
498
+ return useQuery({
499
+ ...api.query("x.rostering.check", input ?? { object: "", id: "" }),
500
+ enabled: input !== null,
501
+ // A rosterer's warnings say who is away: on this screen only.
502
+ gcTime: 0,
503
+ });
504
+ },
505
+ /** A rosterer: who could be put on a shift, eligible first, with the pattern's person. */
506
+ useCandidates(input) {
507
+ return useQuery({
508
+ ...api.query("x.rostering.candidates", input ?? { object: "", id: "" }),
509
+ enabled: input !== null,
510
+ // Who is away is a rosterer's to read, on this screen only.
511
+ gcTime: 0,
512
+ });
513
+ },
514
+ /** A rosterer: a shift back to its pattern's person. */
515
+ useFollow() {
516
+ return useMutation(api.mutation("x.rostering.follow"));
517
+ },
518
+ /** A rosterer: the staff and the kinds of work. */
519
+ usePeople(enabled = true) {
520
+ return useQuery({ ...api.query("x.rostering.people", {}), enabled });
521
+ },
522
+ /** A rosterer: the regular week. */
523
+ usePatterns(enabled = true) {
524
+ return useQuery({ ...api.query("x.rostering.patterns", {}), enabled });
525
+ },
526
+ /** A rosterer: a pattern's person from a date. */
527
+ useSetPattern() {
528
+ return useMutation(api.mutation("x.rostering.setPattern"));
529
+ },
530
+ /** A rosterer: say whether someone may do a kind of work. */
531
+ useQualify() {
532
+ return useMutation(api.mutation("x.rostering.qualify"));
533
+ },
534
+ /** A rosterer: who may do which kind of work. */
535
+ useQualifications(input = {}, enabled = true) {
536
+ return useQuery({ ...api.query("x.rostering.qualifications", input), enabled });
537
+ },
538
+ /** A rosterer: say someone else is away. The note is forgotten once the call is over. */
539
+ useAwayFor() {
540
+ return useMutation({ ...api.mutation("x.rostering.awayFor"), gcTime: 0 });
541
+ },
542
+ /** A rosterer: everyone's time off, with notes, kept no longer than it is on screen. */
543
+ useAwayList(input, enabled = true) {
544
+ return useQuery({ ...api.query("x.rostering.awayList", input), enabled, gcTime: 0 });
545
+ },
546
+ /** A rosterer: shifts with nobody on them. */
547
+ useUncovered(input = {}, enabled = true) {
548
+ return useQuery({ ...api.query("x.rostering.uncovered", input), enabled });
549
+ },
550
+ /** A rosterer: mark a started shift not worked, with why (forgotten once the call is over). */
551
+ useMarkNotWorked() {
552
+ return useMutation({ ...api.mutation("x.rostering.markNotWorked"), gcTime: 0 });
553
+ },
554
+ /** Pay: who is counted and how (kept no longer than it is on screen). */
555
+ usePayBases(input, enabled = true) {
556
+ return useQuery({ ...api.query("x.rostering.payBases", input), enabled, gcTime: 0 });
557
+ },
558
+ /** Pay: say how someone is counted from a date. */
559
+ usePayBasis() {
560
+ return useMutation({ ...api.mutation("x.rostering.payBasis"), gcTime: 0 });
561
+ },
562
+ /** Pay: the periods. */
563
+ usePeriods(input = {}, enabled = true) {
564
+ return useQuery({ ...api.query("x.rostering.periods", input), enabled, gcTime: 0 });
565
+ },
566
+ /** Pay: one period's totals and lines (kept no longer than they are on screen). */
567
+ usePeriodTotals(input) {
568
+ return useQuery({
569
+ ...api.query("x.rostering.periodTotals", input ?? { start: "" }),
570
+ enabled: input !== null,
571
+ gcTime: 0,
572
+ });
573
+ },
574
+ /** Pay: lock a period that has ended. */
575
+ useLock() {
576
+ return useMutation(api.mutation("x.rostering.lock"));
577
+ },
578
+ /** Pay: reopen a locked period with why (forgotten once the call is over). */
579
+ useReopen() {
580
+ return useMutation({ ...api.mutation("x.rostering.reopen"), gcTime: 0 });
581
+ },
582
+ /**
583
+ * Pay: a period's CSV for payroll, fetched when asked and never cached: the screen hands it
584
+ * to the person (a download, a share sheet) and keeps nothing.
585
+ */
586
+ useExport() {
587
+ return useMutation({
588
+ mutationKey: ["x.rostering.export"],
589
+ mutationFn: (input) => api.query("x.rostering.export", input).queryFn(),
590
+ gcTime: 0,
591
+ });
592
+ },
593
+ /** Whether I have a calendar feed (never its address). */
594
+ useFeed() {
595
+ return useQuery(api.query("x.rostering.feed", {}));
596
+ },
597
+ /**
598
+ * A new calendar address (any old one stops working): shown once, as https and webcal on the
599
+ * host this client talks to (its `baseUrl`), never on an address the page was given. Call it
600
+ * through `forgetAfter`, keep the address only on screen, and forget it on leaving.
601
+ */
602
+ useFeedRotate() {
603
+ const rotate = api.mutation("x.rostering.feedRotate");
604
+ return useMutation({
605
+ mutationKey: rotate.mutationKey,
606
+ mutationFn: async (input) => {
607
+ if (!api.baseUrl)
608
+ throw new Error("This client has no host address to show the calendar on.");
609
+ const made = await rotate.mutationFn(input);
610
+ return { ...feedAddresses(api.baseUrl, made.path), createdAt: made.createdAt };
611
+ },
612
+ gcTime: 0,
613
+ });
614
+ },
615
+ /** Turn my calendar feed off. */
616
+ useFeedRevoke() {
617
+ return useMutation(api.mutation("x.rostering.feedRevoke"));
618
+ },
619
+ /**
620
+ * A shift's checklist, its ticks and notes: its person's and whoever rosters' only, kept no
621
+ * longer than it is on screen.
622
+ */
623
+ useChecklist(input) {
624
+ return useQuery({
625
+ ...api.query("x.rostering.checklist", input ?? { object: "", id: "" }),
626
+ enabled: input !== null,
627
+ gcTime: 0,
628
+ });
629
+ },
630
+ /**
631
+ * Tick a step (a person's own act). What is written on it is forgotten once the call is over:
632
+ * call it through `forgetAfter`.
633
+ */
634
+ useTick() {
635
+ return useMutation({ ...api.mutation("x.rostering.tick"), gcTime: 0 });
636
+ },
637
+ /** Mark a checklist done: final. Why, for someone else's, is forgotten once the call is over. */
638
+ useChecklistDone() {
639
+ return useMutation({ ...api.mutation("x.rostering.checklistDone"), gcTime: 0 });
640
+ },
641
+ /** A rosterer: how checklists went, by checklist and date (on screen only). */
642
+ useChecklistRuns(input) {
643
+ return useQuery({
644
+ ...api.query("x.rostering.checklistRuns", input ?? { from: "", to: "" }),
645
+ enabled: input !== null,
646
+ gcTime: 0,
647
+ });
648
+ },
649
+ /** A rosterer: a correction beside a closed checklist (forgotten once the call is over). */
650
+ useChecklistCorrect() {
651
+ return useMutation({ ...api.mutation("x.rostering.checklistCorrect"), gcTime: 0 });
652
+ },
653
+ };
654
+ }