Scheduler · Use cases
Doctor's availability
A GP's week: office hours shaded green with colors; lunch, evenings, weekends and the past blocked with invalid; one patient at a time with eventOverlap={false} — each appointment's five-minute turnaround (bufferAfter) included.
Live demo
Book a slot over lunch · Drag an appointment onto another · Book a free slot in the afternoon
Fullscreenimport { ProScheduler, type PschInvalid, type PschValidationFailure } from "@andreisaac/pro-scheduler"
import { appointments, clinicClosed, officeHours, type Appointment } from "./data/bookings"
import { Log, useEvents, useLog, when } from "./kit"
/** One line explaining why a change was refused. */
function reason(failure: PschValidationFailure) {
return failure.reason === "invalid"
? `blocked (${failure.invalid?.title ?? "unavailable"})`
: `overlaps "${failure.overlapping?.title}"`
}
export function DoctorsAvailabilityDemo() {
const { events, handlers } = useEvents(appointments)
const { lines, log } = useLog()
return (
<div className="docs-demo__stack">
<ProScheduler
data={events}
view={{ scheduler: { type: "week", startTime: "07:00", endTime: "19:00", dragTimeStep: 5, timeCellStep: 15 } }}
colors={officeHours} // green: office hours
invalid={[...clinicClosed, { end: new Date(), title: "Past" }]} // hatched: can't book
eventOverlap={false} // one patient at a time, 5-minute turnaround included
extendDefaultEvent={() => ({ bufferAfter: 5, color: "#2563eb" })}
onEventCreateFailed={(f) => log(`Can't book ${when(f.event.start)}: ${reason(f)}`)}
onEventUpdateFailed={(f) => log(`Can't move ${f.event.title}: ${reason(f)}`)}
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={560}
{...handlers}
/>
<Log lines={lines} empty="Book a slot, or try the lunch hour…" />
</div>
)
}
const blocked: PschInvalid[] = [
{ recurring: { repeat: "daily" }, startTime: "12:00", endTime: "13:00", title: "Lunch" },
{ recurring: { repeat: "weekly", weekDays: [0, 6] }, title: "Weekend" },
]// data/bookings.ts — sample data, relative to the current week or month.
import type { PschColor, PschInvalid, SchedulerEvent } 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,
}
})
}
const weekdays = [1, 2, 3, 4, 5]
/** When the doctor sees patients: shaded green in the grid. */
export const officeHours: PschColor[] = [
{
recurring: { repeat: "weekly", weekDays: weekdays },
startTime: "08:00",
endTime: "12:00",
background: "color-mix(in oklab, #10b981 10%, transparent)",
},
{
recurring: { repeat: "weekly", weekDays: weekdays },
startTime: "13:00",
endTime: "17:00",
background: "color-mix(in oklab, #10b981 10%, transparent)",
},
]
/** Nothing can be booked here: lunch, evenings and weekends. */
export const clinicClosed: PschInvalid[] = [
{ recurring: { repeat: "weekly", weekDays: weekdays }, startTime: "12:00", endTime: "13:00", title: "Lunch" },
{ recurring: { repeat: "weekly", weekDays: weekdays }, startTime: "17:00", endTime: "24:00", title: "Closed" },
{ recurring: { repeat: "weekly", weekDays: weekdays }, startTime: "00:00", endTime: "08:00" },
{ recurring: { repeat: "weekly", weekDays: [0, 6] }, title: "Weekend" },
]About this demo
A GP's week: office hours shaded green with colors; lunch, evenings, weekends and the past blocked with invalid; one patient at a time with eventOverlap={false} — each appointment's five-minute turnaround (bufferAfter) included.
Things to try
- Book a slot over lunch
- Drag an appointment onto another
- Book a free slot in the afternoon
The props behind it are explained in Rules and backgrounds.