Collection
Hospitality / Front Desk & Rack · v0.3.0Validated
See which sections still have open tasks and check whether the handover note has been recorded.
Front Desk Handover · Preview
Loading widget…
Preparing source code…
Idle
Hospitality / Front Desk & Rack · v0.3.0Validated
See which sections still have open tasks and check whether the handover note has been recorded.
Loading widget…
Preparing source code…
Import @lumo/widgets/widget-utilities.css in your Tailwind stylesheet, alongside the Lumo theme.
import "@lumo/tokens/tokens.css";
import { EndOfDayWidget } from "@lumo/widgets/catalog/hotel-desk/end-of-day";
export default function Example() {
return <EndOfDayWidget />;
}Props for integrating the React component in your app.
snapshotEndOfDaySnapshot | null (optional)onTaskChange(change: ShiftTaskChange) => void | Promise<void>onHandover(request: HandoverRequest) => void | Promise<void>{
"shiftId": "evening-04",
"site": "Dune House",
"shift": "Evening shift",
"sections": [
{
"id": "desk",
"label": "Front desk",
"tasks": [
{
"id": "keys",
"label": "Log outstanding key returns",
"done": false
}
]
}
]
}"use client";
import { Button, FormError, Textarea, WidgetCard, WidgetDialog } from "@lumo/ui";
import { ClipboardCheck, ClipboardList, MessageSquareText } from "lucide-react";
import { useId, useRef, useState, type FormEvent } from "react";
import shared from "../../shared/operations-list.module.css";
import { useWidgetCommand } from "../../shared/use-widget-command";
import { handoverSchema, type HandoverRequest } from "./end-of-day.schema";
import { demo } from "./end-of-day.constants";
import { ShiftChecklistSections, ShiftOverview } from "./end-of-day.visuals";
import type { EndOfDaySnapshot, ShiftTaskChange } from "./end-of-day.types";
import styles from "./end-of-day.module.css";
export type { HandoverRequest } from "./end-of-day.schema";
export type { ShiftTask, ShiftChecklist, EndOfDaySnapshot, ShiftTaskChange } from "./end-of-day.types";
type Panel = { kind: "checklist"; sectionId?: string } | { kind: "handover" };
export function EndOfDayWidget({ snapshot, onTaskChange, onHandover }: {
index?: number; snapshot?: EndOfDaySnapshot | null;
onTaskChange?: (change: ShiftTaskChange) => void | Promise<void>;
onHandover?: (request: HandoverRequest) => void | Promise<void>;
} = {}) {
const [sample, setSample] = useState(demo);
const [panel, setPanel] = useState<Panel>();
const [editingShiftId, setEditingShiftId] = useState<string>();
const [note, setNote] = useState("");
const [noteError, setNoteError] = useState<string>();
const [requestedTasks, setRequestedTasks] = useState<ReadonlyMap<string, boolean>>(() => new Map());
const [requestedShift, setRequestedShift] = useState<string>();
const [requestedNote, setRequestedNote] = useState<{ shiftId: string; note: string; previousNote: string | undefined }>();
const opener = useRef<HTMLButtonElement>(null);
const noteInput = useRef<HTMLTextAreaElement>(null);
const handoverForm = useId();
const current = snapshot === undefined ? sample : snapshot;
const sections = current?.sections ?? [];
const tasks = sections.flatMap(section => section.tasks);
const pendingTasks = [...requestedTasks].filter(([id, previous]) => current?.shiftId === requestedShift
&& tasks.some(task => task.id === id && task.done === previous));
if (pendingTasks.length !== requestedTasks.size) setRequestedTasks(new Map(pendingTasks));
const waitingForNote = requestedNote !== undefined && current?.shiftId === requestedNote.shiftId && current?.handoverNote === requestedNote.previousNote;
if (requestedNote && current?.shiftId !== requestedNote.shiftId) setRequestedNote(undefined);
const noteConfirmed = requestedNote && current?.shiftId === requestedNote.shiftId && current.handoverNote === requestedNote.note;
const done = tasks.filter(task => task.done).length;
const remaining = tasks.length - done;
const taskCommand = useWidgetCommand(snapshot === undefined ? (change: ShiftTaskChange) => {
setSample(next => ({ ...next, sections: next.sections.map(section => ({ ...section, tasks: section.tasks.map(task =>
task.id === change.taskId ? { ...task, done: change.done } : task) })) }));
} : onTaskChange);
const handoverCommand = useWidgetCommand(snapshot === undefined ? (request: HandoverRequest) => {
setSample(next => ({ ...next, handoverNote: request.note }));
} : onHandover);
const editable = onTaskChange !== undefined || snapshot === undefined;
const canHandover = onHandover !== undefined || snapshot === undefined;
const selectedSection = panel?.kind === "checklist" && panel.sectionId !== undefined
? sections.find(section => section.id === panel.sectionId) : undefined;
const sheetSections = selectedSection ? [selectedSection] : sections;
const handoverOpen = panel?.kind === "handover";
const hasNote = Boolean(current?.handoverNote?.trim());
function open(next: Panel, button: HTMLButtonElement) {
opener.current = button;
setPanel(next);
setEditingShiftId(current?.shiftId);
setNote("");
setNoteError(undefined);
if (!waitingForNote) setRequestedNote(undefined);
taskCommand.reset();
handoverCommand.reset();
}
async function submit(event: FormEvent<HTMLFormElement>) {
event.preventDefault();
if (!current || current.shiftId !== editingShiftId || waitingForNote) return;
const result = handoverSchema.safeParse({ shiftId: current.shiftId, note });
if (!result.success) {
setNoteError(result.error.flatten().fieldErrors.note?.[0] ?? "The shift is unavailable.");
noteInput.current?.focus();
return;
}
if (result.data.note === current.handoverNote) {
setNoteError("This is already the latest handover note.");
noteInput.current?.focus();
return;
}
noteInput.current?.focus({ preventScroll: true });
if (await handoverCommand.run(result.data) && snapshot !== undefined) {
setRequestedNote({ ...result.data, previousNote: current.handoverNote });
}
}
async function changeTask(taskId: string, done: boolean) {
if (!current || current.shiftId !== editingShiftId || requestedTasks.has(taskId)) return;
if (await taskCommand.run({ shiftId: current.shiftId, taskId, done }) && snapshot !== undefined) {
setRequestedShift(current.shiftId);
setRequestedTasks(items => new Map(items).set(taskId, !done));
}
}
const surface = <WidgetCard title="End of Day" description={current ? `${current.site} · ${current.shift}` : "Front desk"}
size="large" icon={<ClipboardCheck />} className={`${shared.largeCard} ${styles.card}`}>
<div className={styles.body}>
{current ? <>
<ShiftOverview sections={sections} done={done} total={tasks.length} handover={waitingForNote ? "waiting" : hasNote ? "saved" : "missing"}
onSection={(sectionId, button) => open({ kind: "checklist", sectionId }, button)} />
<div className={styles.actions}>
{sections.length > 0 && <Button type="button" size="xs" variant="secondary" aria-haspopup="dialog"
onClick={event => open({ kind: "checklist" }, event.currentTarget)}><ClipboardList size={13} aria-hidden /> View checklist</Button>}
{(canHandover || hasNote) && <Button type="button" size="xs" className={styles.handoverAction}
variant={remaining === 0 ? "primary" : "secondary"} aria-haspopup="dialog"
onClick={event => open({ kind: "handover" }, event.currentTarget)}><MessageSquareText size={13} aria-hidden /> Handover</Button>}
</div>
</> : <p className={shared.muted}>Shift data unavailable.</p>}
</div>
</WidgetCard>;
return <WidgetDialog className={styles.frame} placement="bottom" dragFromScrollStart
title={handoverOpen ? "Shift handover" : selectedSection?.label ?? "Shift checklist"}
open={panel !== undefined && current !== null && current.shiftId === editingShiftId} onClose={() => setPanel(undefined)} returnFocusRef={opener} surface={surface}
footer={handoverOpen && canHandover ? <Button form={handoverForm} type="submit" size="xs"
disabled={handoverCommand.status === "saving" || handoverCommand.status === "saved" || waitingForNote}>Save handover</Button> : undefined}>
{current && panel?.kind === "checklist" && <div className={shared.stack}>
<ShiftChecklistSections sections={sheetSections} pending={taskCommand.status === "saving"} requested={requestedTasks} showHeadings={!selectedSection}
onChange={editable ? changeTask : undefined} />
{sheetSections.length === 0 && <p className={shared.muted}>No checklist tasks.</p>}
{taskCommand.status === "error" && <FormError>Couldn’t update the checklist. Try again.</FormError>}
</div>}
{current && handoverOpen && <div className={shared.stack}>
<p className={shared.muted}>{remaining} {remaining === 1 ? "task" : "tasks"} still open.</p>
{hasNote && current.handoverNote?.trim() !== note.trim() && <div className={styles.noteDetail}><strong>Last note</strong><p>{current.handoverNote}</p></div>}
{canHandover && <form id={handoverForm} className={shared.stack} onSubmit={submit} noValidate>
<Textarea ref={noteInput} label="Note for the next shift" name="note" rows={3} size="sm" value={note}
error={noteError} readOnly={handoverCommand.status === "saving" || waitingForNote} onChange={event => {
setNote(event.currentTarget.value);
setNoteError(undefined);
setRequestedNote(undefined);
handoverCommand.reset();
}} />
{handoverCommand.status === "error" && <FormError>Couldn’t save the handover. Try again.</FormError>}
{waitingForNote ? <p role="status">Handover sent. Awaiting update.</p>
: (noteConfirmed || snapshot === undefined && handoverCommand.status === "saved") && <p role="status">Handover saved.</p>}
</form>}
</div>}
</WidgetDialog>;
}
lucide-reactmotionreactreact-domzod