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
Fullscreenimport { 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." />
</>
)
}// data/rituals.ts — sample data, relative to the current week or month.
import type { SchedulerEvent, SchedulerResource } from "@andreisaac/pro-scheduler"
import { weekStart } from "./studio"
export const teamRooms: SchedulerResource[] = [
{ id: "team", name: "Whole team", color: "#2563eb" },
{ id: "eng", name: "Engineering", color: "#059669" },
{ id: "design", name: "Design", color: "#d97706" },
{ id: "leads", name: "Leads", color: "#7c3aed" },
]
const at = (base: Date, day: number, hour: number, minute = 0) =>
new Date(base.getFullYear(), base.getMonth(), base.getDate() + day, hour, minute)
/** "YYYY-MM-DD" of a local day. */
const iso = (d: Date) =>
`${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`
export function teamRituals(base = weekStart()): SchedulerEvent[] {
return [
{
id: "standup",
title: "Standup",
start: at(base, 0, 9, 30),
end: at(base, 0, 9, 45),
resource: "eng",
// every weekday; skipped next Wednesday (offsite)
recurring: { repeat: "weekly", weekDays: "MO,TU,WE,TH,FR" },
recurringException: [iso(at(base, 9, 0))],
},
{
id: "design-crit",
title: "Design crit",
start: at(base, 1, 14),
end: at(base, 1, 15),
resource: "design",
recurring: "FREQ=WEEKLY;BYDAY=TU,TH",
},
{
id: "planning",
title: "Sprint planning",
start: at(base, 0, 10),
end: at(base, 0, 11, 30),
resource: "team",
recurring: { repeat: "weekly", interval: 2 },
},
{
id: "retro",
title: "Retro",
start: at(base, 11, 16),
end: at(base, 11, 17),
resource: "team",
recurring: { repeat: "weekly", interval: 2, weekDays: "FR" },
},
{
id: "one-to-ones",
title: "Leads 1:1s",
start: at(base, 2, 11),
end: at(base, 2, 12),
resource: "leads",
recurring: { repeat: "weekly", count: 12 },
},
{
id: "all-hands",
title: "All-hands",
start: at(base, 3, 17),
end: at(base, 3, 18),
resource: "team",
// the first Thursday of every month
recurring: { repeat: "monthly", weekDays: "1TH" },
},
{ id: "launch", title: "Launch review", start: at(base, 3, 13), end: at(base, 3, 14, 30), resource: "leads" },
{ id: "offsite", title: "Team offsite", start: at(base, 9, 0), end: at(base, 10, 0), allDay: true, resource: "team" },
]
}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.