ProSchedulerSign in

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

Fullscreen
import { 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" },
]

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.

Use ProScheduler in your project