ProSchedulerSign in

Scheduler · Drag & drop

Blocked time ranges

invalid blocks lunch every day, weekends and a one-off holiday. A move into one snaps back and onEventUpdateFailed says why; the drag turns red before you let go.

Live demo

Drag a session into lunch · Draw a new one on the holiday

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

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

export function BlockedRangesDemo() {
  const { events, handlers } = useEvents(studioSessions)
  const { lines, log } = useLog()
  const [holiday] = useState(() => {
    const day = weekStart()
    return { start: new Date(day.getFullYear(), day.getMonth(), day.getDate() + 3), allDay: true, title: "Holiday" }
  })

  return (
    <div className="docs-demo__stack">
      <ProScheduler
        data={events}
        resources={studioResources}
        view={{ scheduler: { type: "week", startTime: "07:00", endTime: "20:00" } }}
        invalid={[...blocked, holiday]}
        onEventCreateFailed={(f) => log(`Can't create at ${when(f.event.start)}: ${reason(f)}`)}
        onEventUpdateFailed={(f) => log(`"${f.event.title}" snapped back: ${reason(f)}`)}
        height={520}
        {...handlers}
      />
      <Log lines={lines} empty="Drag a session into lunch, the holiday or the weekend…" />
    </div>
  )
}

About this demo

invalid blocks lunch every day, weekends and a one-off holiday. A move into one snaps back and onEventUpdateFailed says why; the drag turns red before you let go.

Things to try

  • Drag a session into lunch
  • Draw a new one on the holiday

The props behind it are explained in Rules and backgrounds.

Use ProScheduler in your project