ProSchedulerSign in

Scheduler · CRUD

Recurring add and edit

Change one occurrence and the scheduler asks: this event, this and the following, or all. Your handlers receive plain changes — the series updated, an exception added, a single event created — with info saying where they came from.

Live demo

Drag Wednesday's standup to 10:00 — choose “This event” · Open a design crit and set it to Daily

Fullscreen
import { useState } from "react"
import { ProScheduler, type PschChangeInfo, type PschRecurringEditMode, type SchedulerEvent } from "@andreisaac/pro-scheduler"
import { teamRituals, teamRooms } from "./data/rituals"
import { Choice, Log, Toolbar, useEvents, useLog } from "./kit"

const modes: { mode: "ask" | PschRecurringEditMode; label: string }[] = [
  { mode: "ask", label: "Ask" },
  { mode: "current", label: "This event" },
  { mode: "following", label: "This and following" },
  { mode: "all", label: "All events" },
]

export function RecurringEditDemo() {
  const { events, setEvents } = useEvents(() => teamRituals())
  const [mode, setMode] = useState<"ask" | PschRecurringEditMode>("ask")
  const { lines, log } = useLog(8)
  const note = (info?: PschChangeInfo) => (info ? ` (${info.mode}, from “${info.originEvent.title}”)` : "")

  // The usual controlled handlers: a change to one occurrence arrives as
  // changes to your own events — the series, a new single event, …
  return (
    <>
      <Toolbar label="Recurring edit mode">
        {modes.map((m) => (
          <Choice key={m.mode} active={mode === m.mode} onClick={() => setMode(m.mode)}>
            {m.label}
          </Choice>
        ))}
      </Toolbar>
      <ProScheduler
        data={events}
        resources={teamRooms}
        view={{ scheduler: { type: "week", startTime: "08:00", endTime: "19:00" } }}
        recurringEditMode={mode}
        clickToCreate
        height={560}
        onEventCreated={(event, info) => {
          const id = `new-${Date.now()}-${Math.round(Math.random() * 1e4)}`
          setEvents((list) => [...list, { ...event, id }])
          log(`created “${event.title}”${event.recurring ? " series" : ""}${note(info)}`)
        }}
        onEventUpdated={(event, info) => {
          setEvents((list) => list.map((e) => (e.id === event.id ? event : e)))
          log(`updated “${event.title}”${note(info)}`)
        }}
        onEventDeleted={(event: SchedulerEvent, info) => {
          setEvents((list) => list.filter((e) => e.id !== event.id))
          log(`deleted “${event.title}”${note(info)}`)
        }}
      />
      <Log lines={lines} empty="Drag a standup, or open one and change it." />
    </>
  )
}

About this demo

Change one occurrence and the scheduler asks: this event, this and the following, or all. Your handlers receive plain changes — the series updated, an exception added, a single event created — with info saying where they came from.

recurringEditMode skips the question. The editor's repeat field makes any event a series.

Things to try

  • Drag Wednesday's standup to 10:00 — choose “This event”
  • Open a design crit and set it to Daily

The props behind it are explained in Recurrence, time zones and order.

Use ProScheduler in your project