ProSchedulerSign in

Timeline · Use cases

Resource availability

Resource-scoped ranges: Hana doesn't work Mondays and Farah is on holiday (blocked), two pairs are on call (shaded). Nothing can be assigned into a block.

Live demo

Drag an assignment onto Farah's holiday · Move one onto Hana's Monday

Fullscreen
import { useMemo } from "react"
import { ProScheduler, type PschColor, type PschInvalid, type PschValidationFailure } from "@andreisaac/pro-scheduler"
import { monthStart, studioAssignments, studioResources } from "./data/studio"
import { Log, useEvents, useLog, when } from "./kit"

function reason(failure: PschValidationFailure) {
  return failure.reason === "invalid"
    ? `blocked (${failure.invalid?.title ?? "unavailable"})`
    : `overlaps "${failure.overlapping?.title}"`
}

const day = (base: Date, n: number) => new Date(base.getFullYear(), base.getMonth(), base.getDate() + n)

export function ResourceAvailabilityDemo() {
  const { events, handlers } = useEvents(studioAssignments)
  const { lines, log } = useLog()

  // Who works when: part-timers' days off, and a holiday for one person.
  const availability = useMemo(() => {
    const month = monthStart()
    // Blocked per person. (Weekends are only shaded: multi-day work spans them.)
    const off: PschInvalid[] = [
      { recurring: { repeat: "weekly", weekDays: [1] }, resource: "hana", title: "Part-time" },
      { start: day(month, 9), end: day(month, 16), resource: "farah", title: "Holiday" },
    ]
    const onCall: PschColor[] = [
      { recurring: { repeat: "weekly", weekDays: [0, 6] }, background: "color-mix(in oklab, currentColor 6%, transparent)" },
      { start: day(month, 0), end: day(month, 7), resource: ["ada", "ben"], title: "On call", background: "color-mix(in oklab, #10b981 14%, transparent)" },
      { start: day(month, 14), end: day(month, 21), resource: ["chloe", "dev"], title: "On call", background: "color-mix(in oklab, #10b981 14%, transparent)" },
    ]
    return { off, onCall }
  }, [])

  return (
    <div className="docs-demo__stack">
      <ProScheduler
        data={events}
        resources={studioResources}
        view={{ timeline: { type: "month" } }}
        invalid={availability.off}
        colors={availability.onCall}
        onEventUpdateFailed={(f) => log(`"${f.event.title}" snapped back: ${reason(f)}`)}
        onEventCreateFailed={(f) => log(`Can't assign then: ${reason(f)}`)}
        height={520}
        {...handlers}
      />
      <Log lines={lines} empty="Drag an assignment onto Farah's holiday…" />
    </div>
  )
}

About this demo

Resource-scoped ranges: Hana doesn't work Mondays and Farah is on holiday (blocked), two pairs are on call (shaded). Nothing can be assigned into a block.

Things to try

  • Drag an assignment onto Farah's holiday
  • Move one onto Hana's Monday

The props behind it are explained in Rules and backgrounds.

Use ProScheduler in your project