ProSchedulerSign in

Scheduler · Drag & drop

Validation and locked events

Client reviews are editable: false. The before-callbacks refuse weekends, times outside 08:00–18:00 and new bookings in the past — refused changes snap back.

Live demo

Try to drag a review · Move a session onto Saturday · Create something in the past

Fullscreen
import { ProScheduler, type EventDraft } from "@andreisaac/pro-scheduler"
import { studioResources, studioSessions } from "./data/studio"
import { Log, useEvents, useLog, when } from "./kit"

export function ValidationDemo() {
  const { events, handlers } = useEvents(() =>
    // Client reviews are locked in place: they render, but can't be dragged.
    studioSessions().map((event) => (event.kind === "Review" ? { ...event, editable: false } : event))
  )
  const { lines, log } = useLog()

  const isWeekend = (d: Date) => d.getDay() === 0 || d.getDay() === 6
  const outsideHours = (start: Date, end: Date) =>
    start.getHours() < 8 || end.getHours() + end.getMinutes() / 60 > 18

  return (
    <div className="docs-demo__stack">
      <ProScheduler
        data={events}
        resources={studioResources}
        view={{ scheduler: { type: "week", startTime: "07:00", endTime: "20:00", dragTimeStep: 30 } }}
        height={520}
        // Returning false cancels the change and the event snaps back.
        onEventUpdate={(event) => {
          const start = new Date(event.start)
          const end = new Date(event.end!)
          if (isWeekend(start)) {
            log(`Refused: "${event.title}" can't move to a weekend`)
            return false
          }
          if (outsideHours(start, end)) {
            log(`Refused: "${event.title}" is outside 08:00–18:00`)
            return false
          }
        }}
        onEventCreate={(draft: EventDraft) => {
          if (isWeekend(draft.start)) {
            log("Refused: no new bookings at weekends")
            return false
          }
          if (draft.start < new Date()) {
            log("Refused: that slot is in the past")
            return false
          }
        }}
        onEventUpdated={(event) => {
          log(`Saved "${event.title}" at ${when(event.start)}`)
          handlers.onEventUpdated(event)
        }}
        onEventCreated={handlers.onEventCreated}
        onEventDeleted={handlers.onEventDeleted}
      />
      <Log lines={lines} empty="Try moving a review, or anything onto a weekend…" />
    </div>
  )
}

About this demo

Client reviews are editable: false. The before-callbacks refuse weekends, times outside 08:00–18:00 and new bookings in the past — refused changes snap back.

Things to try

  • Try to drag a review
  • Move a session onto Saturday
  • Create something in the past

The props behind it are explained in Drag, resize & create.

Use ProScheduler in your project