Timeline · Use cases
Restaurant shift management
Lunch and dinner services for the floor team, coloured by role; the restaurant is closed on Mondays.
Live demo
Move a dinner service · Find who covers Sunday lunch
Fullscreenimport { ProScheduler } from "@andreisaac/pro-scheduler"
import { floorTeam, restaurantShifts } from "./data/shifts"
import { useEvents } from "./kit"
const hhmm = (d: Date) => d.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" })
const roleColors: Record<string, string> = {
Chef: "#dc2626",
Waiter: "#2563eb",
Bartender: "#db2777",
Host: "#059669",
}
export function RestaurantShiftsDemo() {
const { events, handlers } = useEvents(() =>
restaurantShifts().map((service) => {
const role = String(floorTeam.find((p) => p.id === service.resource)?.role)
return { ...service, color: roleColors[role] }
})
)
return (
<ProScheduler
data={events}
resources={floorTeam}
view={{ timeline: { type: "week", resolutionHorizontal: "hour", dragTimeStep: 30 } }}
styleConfig={{ unitWidthPx: 16, fitToWidth: false, laneHeight: 30 }}
renderResource={(person) => (
<div className="flex items-center gap-2">
<span className="size-2.5 rounded-full" style={{ background: roleColors[String(person.role)] }} />
<span className="text-sm font-medium">{person.name}</span>
<span className="text-xs text-muted-foreground">{String(person.role)}</span>
</div>
)}
renderEventContent={({ original, start, end }) => (
<span className="truncate">
{original.title} {hhmm(start)}–{hhmm(end)}
</span>
)}
height={460}
{...handlers}
/>
)
}// data/shifts.ts — sample data, relative to the current week or month.
import type { SchedulerEvent, SchedulerResource } from "@andreisaac/pro-scheduler"
import { weekStart } from "./studio"
export type Shift = "Morning" | "Evening" | "Night"
export type ShiftEvent = SchedulerEvent & {
id: string
start: Date
end: Date
resource: string
shift: Shift
}
export const floorTeam: SchedulerResource[] = [
{ id: "r1", name: "Marco", role: "Chef", color: "#dc2626" },
{ id: "r2", name: "Sofia", role: "Chef", color: "#ea580c" },
{ id: "r3", name: "Liam", role: "Waiter", color: "#2563eb" },
{ id: "r4", name: "Nora", role: "Waiter", color: "#0891b2" },
{ id: "r5", name: "Omar", role: "Waiter", color: "#7c3aed" },
{ id: "r6", name: "Pia", role: "Bartender", color: "#db2777" },
{ id: "r7", name: "Quinn", role: "Host", color: "#059669" },
]
/** Lunch and dinner services; the restaurant is closed on Mondays. */
export function restaurantShifts(base = weekStart()): ShiftEvent[] {
const events: ShiftEvent[] = []
floorTeam.forEach((person, p) => {
for (let day = 1; day < 7; day++) {
const services: [number, number][] = []
if ((p + day) % 3 !== 0) services.push([11, 15])
if ((p + day) % 4 !== 1) services.push([18, 23])
for (const [from, to] of services) {
const start = new Date(base.getFullYear(), base.getMonth(), base.getDate() + day, from)
events.push({
id: `svc-${person.id}-${day}-${from}`,
title: from < 16 ? "Lunch" : "Dinner",
start,
end: new Date(start.getFullYear(), start.getMonth(), start.getDate(), to),
resource: String(person.id),
shift: from < 16 ? "Morning" : "Evening",
})
}
}
})
return events
}About this demo
Lunch and dinner services for the floor team, coloured by role; the restaurant is closed on Mondays.
Things to try
- Move a dinner service
- Find who covers Sunday lunch
The props behind it are explained in Resources.