Scheduler · Use cases
Appointment booking
A clinic's day with a column per doctor (resources: true). Lunch is blocked for everyone and Dr. Weber's afternoon for her alone; with overlaps off, a doctor sees one patient at a time.
Live demo
Drag a patient to another doctor · Book Dr. Weber after 12:00 · Book over lunch
Fullscreenimport { ProScheduler, type PschInvalid } from "@andreisaac/pro-scheduler"
import { clinicDay, doctors, type Appointment } from "./data/bookings"
import { Log, useEvents, useLog, when } from "./kit"
const lunch: PschInvalid[] = [
{ recurring: { repeat: "daily" }, startTime: "12:30", endTime: "13:30", title: "Lunch" },
// Dr. Weber only sees patients in the morning on this rota.
{ recurring: { repeat: "daily" }, startTime: "12:00", endTime: "24:00", resource: "dr-weber", title: "Surgery" },
]
export function AppointmentBookingDemo() {
const { events, handlers } = useEvents(clinicDay)
const { lines, log } = useLog()
return (
<div className="docs-demo__stack">
<ProScheduler
data={events}
resources={doctors}
// One column per doctor for the day.
view={{ scheduler: { type: "day", resources: true, startTime: "07:30", endTime: "18:00", timeCellStep: 15, dragTimeStep: 15 } }}
invalid={lunch}
eventOverlap={false}
extendDefaultEvent={({ resource }) => ({ title: "New patient", color: doctors.find((d) => d.id === resource)?.color })}
onEventUpdateFailed={(f) => log(`Can't move ${f.event.title}: ${f.reason === "invalid" ? f.invalid?.title : "that doctor is busy"}`)}
onEventCreateFailed={(f) => log(`Can't book ${when(f.event.start)}: ${f.reason === "invalid" ? f.invalid?.title : "already booked"}`)}
renderResource={(doctor) => (
<div className="grid justify-items-center leading-tight">
<span className="text-xs font-semibold">{doctor.name}</span>
<span className="text-[10px] text-muted-foreground">{String(doctor.specialty)}</span>
</div>
)}
renderEventContent={({ original }) => (
<div className="grid text-[11px] leading-tight">
<strong className="truncate">{original.title}</strong>
<span className="truncate opacity-85">{(original as Appointment).reason}</span>
</div>
)}
height={600}
{...handlers}
/>
<Log lines={lines} empty="Drag a patient to another doctor, or into lunch…" />
</div>
)
}// data/bookings.ts — sample data, relative to the current week or month.
import type { SchedulerEvent, SchedulerResource } from "@andreisaac/pro-scheduler"
import { weekStart } from "./studio"
const at = (base: Date, day: number, hour: number, minute = 0) =>
new Date(base.getFullYear(), base.getMonth(), base.getDate() + day, hour, minute)
export type Appointment = SchedulerEvent & {
id: string
start: Date
end: Date
patient: string
reason: string
kind: "Check-up" | "Follow-up" | "Vaccination" | "Consultation"
}
export const appointmentColors: Record<Appointment["kind"], string> = {
"Check-up": "#2563eb",
"Follow-up": "#059669",
Vaccination: "#d97706",
Consultation: "#7c3aed",
}
const visits: [number, number, number, number, string, Appointment["kind"], string][] = [
[0, 9, 0, 30, "Maria Silva", "Check-up", "Annual check-up"],
[0, 10, 0, 20, "Tom Becker", "Follow-up", "Blood results"],
[0, 14, 30, 30, "Aisha Khan", "Consultation", "Back pain"],
[1, 8, 30, 15, "Leo Rossi", "Vaccination", "Flu jab"],
[1, 9, 0, 45, "Nina Holm", "Consultation", "Migraine"],
[1, 15, 0, 30, "Paulo Reis", "Check-up", "Pre-travel"],
[2, 11, 0, 30, "Emma Clarke", "Follow-up", "Blood pressure"],
[2, 13, 30, 20, "Yusuf Demir", "Vaccination", "Tetanus"],
[3, 9, 30, 60, "Sara Lind", "Consultation", "Sleep"],
[3, 16, 0, 30, "Ivan Petrov", "Follow-up", "Medication review"],
[4, 8, 30, 30, "Chloe Martin", "Check-up", "Sports clearance"],
[4, 10, 30, 20, "Ben Adams", "Vaccination", "Hepatitis B"],
]
/** Twelve appointments in the doctor's week, each with a 5-minute turnaround. */
export function appointments(base = weekStart()): Appointment[] {
return visits.map(([day, h, m, minutes, patient, kind, reason], i) => {
const start = at(base, day, h, m)
return {
id: `apt-${i + 1}`,
title: patient,
patient,
reason,
kind,
start,
end: new Date(start.getTime() + minutes * 60_000),
color: appointmentColors[kind],
bufferAfter: 5,
}
})
}
export const doctors: SchedulerResource[] = [
{ id: "dr-lee", name: "Dr. Lee", specialty: "GP", color: "#2563eb" },
{ id: "dr-costa", name: "Dr. Costa", specialty: "Paediatrics", color: "#059669" },
{ id: "dr-weber", name: "Dr. Weber", specialty: "Cardiology", color: "#d97706" },
{ id: "dr-okafor", name: "Dr. Okafor", specialty: "GP", color: "#7c3aed" },
]
/** Today's appointments, spread over the four doctors. */
export function clinicDay(today = new Date()): Appointment[] {
const slots: [string, number, number, number][] = [
["dr-lee", 8, 30, 30], ["dr-lee", 9, 15, 20], ["dr-lee", 11, 0, 30], ["dr-lee", 14, 0, 45],
["dr-costa", 8, 0, 30], ["dr-costa", 9, 30, 30], ["dr-costa", 13, 30, 30], ["dr-costa", 15, 0, 20],
["dr-weber", 9, 0, 60], ["dr-weber", 10, 30, 45], ["dr-weber", 14, 30, 60],
["dr-okafor", 8, 0, 20], ["dr-okafor", 10, 0, 30], ["dr-okafor", 11, 15, 30], ["dr-okafor", 16, 0, 30],
]
return slots.map(([doctor, h, m, minutes], i) => {
const [, , , , , kind, reason] = visits[i % visits.length]
const [, , , , patient] = visits[(i + 3) % visits.length]
const start = new Date(today.getFullYear(), today.getMonth(), today.getDate(), h, m)
return {
id: `visit-${i + 1}`,
title: String(patient),
patient: String(patient),
reason: String(reason),
kind: kind as Appointment["kind"],
start,
end: new Date(start.getTime() + minutes * 60_000),
resource: doctor,
color: appointmentColors[kind as Appointment["kind"]],
}
})
}About this demo
A clinic's day with a column per doctor (resources: true). Lunch is blocked for everyone and Dr. Weber's afternoon for her alone; with overlaps off, a doctor sees one patient at a time.
Things to try
- Drag a patient to another doctor
- Book Dr. Weber after 12:00
- Book over lunch
The props behind it are explained in Resources.