Collection
Facilities & IT / SaaS & DevOps · v0.2.0Validated
Find the primary engineer, next handoff and any gap in the on-call schedule.
Engineer On-Call Coverage · Preview
Loading widget…
Preparing source code…
Idle
Facilities & IT / SaaS & DevOps · v0.2.0Validated
Find the primary engineer, next handoff and any gap in the on-call schedule.
Loading widget…
Preparing source code…
Load the Lumo theme once in your app entry point. The example uses the local Lumo workspace packages.
import "@lumo/tokens/tokens.css";
import { OnCallWidget } from "@lumo/widgets/catalog/saas/on-call";
export default function Example() {
return <OnCallWidget />;
}Props for integrating the React component in your app.
snapshotOnCallRotationSnapshot | null (optional)onAction(action: OnCallRotationAction) => void | Promise<void>{
"snapshot": {
"service": "Checkout",
"asOf": 1795616400000,
"timeZone": "Europe/Paris",
"shifts": [
{
"id": "shift-12",
"name": "Nadia Bello",
"startsAt": 1795602000000,
"endsAt": 1795630800000,
"backup": "Sam Baker"
}
]
}
}"use client";
import { Radio } from "lucide-react";
import { useOperationSnapshot, validTimestamp } from "../../shared/operation-snapshot";
import { WidgetOperations, type OperationRow } from "../../shared/WidgetOperations";
import { rotationDemo } from "./on-call.constants";
import type { OnCallRotationSnapshot, OnCallRotationAction } from "./on-call.types";
export type { OnCallRotationSnapshot, OnCallRotationAction, RotationShift } from "./on-call.types";
function shiftClock(timeZone?: string) {
const format: Intl.DateTimeFormatOptions = { weekday: "short", hour: "2-digit", minute: "2-digit", timeZoneName: "short" };
try { return new Intl.DateTimeFormat("en-GB", { ...format, timeZone: timeZone ?? "UTC" }); }
catch { return new Intl.DateTimeFormat("en-GB", { ...format, timeZone: "UTC" }); }
}
export function OnCallWidget({ snapshot, onAction }: {
index?: number; snapshot?: OnCallRotationSnapshot | null;
onAction?: (action: OnCallRotationAction) => void | Promise<void>;
} = {}) {
const { data, action } = useOperationSnapshot(snapshot, rotationDemo, onAction, (state, request) => ({
...state, shifts: state.shifts.map(shift => shift.id === request.shiftId ? { ...shift, pageStatus: "pending" as const } : shift),
}));
const asOf = data?.asOf;
const validClock = validTimestamp(asOf);
const clock = shiftClock(data?.timeZone);
const shifts = (data?.shifts ?? []).filter(shift => validTimestamp(shift.startsAt) && validTimestamp(shift.endsAt)
&& shift.startsAt < shift.endsAt && (!validClock || shift.endsAt > asOf)).sort((a, b) => a.startsAt - b.startsAt);
const primaries = validClock ? shifts.filter(shift => shift.startsAt <= asOf) : [];
const primary = primaries.length === 1 ? primaries[0] : undefined;
const next = validClock ? shifts.find(shift => shift.startsAt > asOf) : undefined;
const rows = data ? shifts.map<OperationRow<OnCallRotationAction>>(shift => ({
id: shift.id, label: shift.name, person: shift,
caption: shift === primary ? `Until ${clock.format(shift.endsAt)}` : `From ${clock.format(shift.startsAt)}`,
status: shift.pageStatus === "pending" ? { label: "Page pending", tone: "info" }
: shift.pageStatus === "acknowledged" ? { label: "Acknowledged", tone: "success" }
: shift === primary ? { label: "Primary", tone: "success" } : undefined,
details: [["Start", clock.format(shift.startsAt)], ["End", clock.format(shift.endsAt)], ["Backup", shift.backup ?? "Not assigned"]],
actions: shift === primary && shift.pageStatus !== "pending"
? [{ label: "Page primary", command: { type: "page-primary", shiftId: shift.id }, confirmation: `Page ${shift.name} for ${data.service}?` }] : [],
})) : null;
return <WidgetOperations title="On-call Rotation" icon={<Radio />} description={data?.service} rows={rows}
empty="No current or upcoming shifts" onAction={action} summary={data && <span>{
!validClock ? "Schedule time unavailable" : primaries.length > 1 ? "Overlapping primary shifts" : !primary ? "No primary on duty"
: next && next.startsAt > primary.endsAt ? "Coverage gap after this shift" : next ? `Next handoff · ${clock.format(next.startsAt)}` : "Next handoff not scheduled"
}</span>} />;
}
lucide-reactmotionreactreact-dom