ProSchedulerSign in

Scheduler · Drag & drop

Prevent double booking

With eventOverlap={false} a person can't have two sessions at once; other people's sessions don't count.

Live demo

Drag a session onto another of the same person · Turn overlaps back on

Fullscreen
import { useState } from "react"
import { ProScheduler, type PschInvalid, type PschValidationFailure } from "@andreisaac/pro-scheduler"
import { studioResources, studioSessions } from "./data/studio"
import { Choice, Log, Toolbar, useEvents, useLog } 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}"`
}

const blocked: PschInvalid[] = [
  { recurring: { repeat: "daily" }, startTime: "12:00", endTime: "13:00", title: "Lunch" },
  { recurring: { repeat: "weekly", weekDays: [0, 6] }, title: "Weekend" },
]

export function DoubleBookingDemo() {
  const { events, handlers } = useEvents(studioSessions)
  const { lines, log } = useLog()
  const [allow, setAllow] = useState(false)

  return (
    <div className="docs-demo__stack">
      <Toolbar>
        <Choice active={allow} onClick={() => setAllow(!allow)}>
          Allow overlaps
        </Choice>
        <span className="demo-muted">Overlaps are checked per person.</span>
      </Toolbar>
      <ProScheduler
        data={events}
        resources={studioResources}
        view={{ scheduler: { type: "week", startTime: "07:00", endTime: "20:00", dragTimeStep: 15 } }}
        eventOverlap={allow}
        onEventUpdateFailed={(f) => log(`"${f.event.title}" ${reason(f)}`)}
        onEventCreateFailed={(f) => log(`New booking ${reason(f)}`)}
        height={520}
        {...handlers}
      />
      <Log lines={lines} empty="Drag a session onto another of the same person's…" />
    </div>
  )
}

About this demo

With eventOverlap={false} a person can't have two sessions at once; other people's sessions don't count.

Things to try

  • Drag a session onto another of the same person
  • Turn overlaps back on

The props behind it are explained in Rules and backgrounds.

Use ProScheduler in your project