
React resource booking without double booking
Validate bookings in the timeline and commit them atomically when two users reserve the same resource.
Tuesday needs two people on support from 09:00 to 17:00. Bruno works the full shift, Clara leaves at 13:00, and Ana is on leave. The team is one person short for the last four hours.
This React example uses RevoGrid Scheduler to show each employee’s shifts, block assignments during time off, and create shifts from templates. To show the afternoon shortage, split the staffing requirement at 13:00 and check coverage in each interval.
Clone the React example and run it with Node 24.13 or later.
git clone https://github.com/revolist/revogrid-docs.git
cd revogrid-docs/examples/scheduler-workflows
pnpm install --ignore-scripts
pnpm devOpen http://127.0.0.1:49313/?example=shifts and select Inspect coverage. All fixture times are UTC.
| Tuesday, 9 June 2026 | Required | Assigned | Missing |
|---|---|---|---|
| 09:00–13:00 | 2 | 2 | 0 |
| 13:00–17:00 | 2 | 1 | 1 |
Select Extend Clara to 17:00, then inspect again. The result becomes one 09:00–17:00 interval with required 2, assigned 2, missing 0. Select Try Ana during time off: the attempted shift must be rejected. Reload this page to reset the local staffing fixture.
Employees are eventSchedulerResources. Each has a stable ID, role and capacity. Here one person's capacity is one staff member; it is not their maximum weekly hours.
const employees = [
{ id: 'ana', name: 'Ana', role: 'support', group: 'Service', capacity: 1 },
{
id: 'bruno',
name: 'Bruno',
role: 'support',
group: 'Service',
capacity: 1,
},
{
id: 'clara',
name: 'Clara',
role: 'support',
group: 'Service',
capacity: 1,
},
];
const staffingDemand = [
{
id: 'tuesday-support',
label: 'Tuesday support',
role: 'support',
required: 2,
startDateTime: '2026-06-09T09:00:00.000Z',
endDateTime: '2026-06-09T17:00:00.000Z',
},
];The source array contains shifts. A shift links to an employee through resourceId, has explicit start/end instants, and can carry type: 'shift' and status: 'confirmed'. An open shift without an assigned resource is demand awaiting assignment; it should not count as staffed capacity.
The Scheduler API also supports assignment sidecars when your backend stores event-to-resource links separately. This tutorial uses direct resourceId fields to keep one-person shift ownership visible.
The runnable fixture supplies a dated working interval from 09:00 to 17:00 for each weekday. Ana's leave is a resource-specific unavailable interval:
const timeOff = {
id: 'ana-time-off',
resourceId: 'ana',
kind: 'holiday',
title: 'Ana: approved time off',
startDateTime: '2026-06-09T00:00:00.000Z',
endDateTime: '2026-06-10T00:00:00.000Z',
};Pass the working and leave records through eventSchedulerAvailability, then make overlap, outside-availability and blocked-time error rules. Creating or moving a shift into Ana's leave fails before the event is accepted.
For ongoing schedules, use a recurring working calendar as the baseline and dated availability exceptions for leave, training and temporary hours. Working availability for a matching resource/date takes precedence over the calendar fallback. Shading non-working slots is a presentation choice; configure conflict rules to enforce the policy.
The current coverage engine counts each matching resource once when one of its event segments overlaps a requirement. A broad 09:00–17:00 requirement is not a continuous minimum-headcount calculation. Bruno and Clara both overlap it, even though Clara leaves at 13:00.
The example's application helper splitDemand splits the demand at every shift start and end. Inside each resulting interval the active set of employees is constant. The input demand remains 09:00–17:00; the derived requirements become 09:00–13:00 and 13:00–17:00.
const requirements = useMemo(
() => splitDemand(staffingDemand, events),
[events],
);The helper is included in shared/coverage.ts, with tests for both the afternoon gap and a 15-minute gap inside a coarse requirement. Recompute it after every accepted shift change. If breaks are separate availability records rather than gaps in shift events, split effective working segments around those breaks too; merely displaying a break does not remove a person from a coverage count.
Configure the built-in coverage calculation to count confirmed shifts only:
import type { EventSchedulerConfig } from '@revolist/scheduler';
const coverage: EventSchedulerConfig['coverage'] = {
enabled: true,
countEvent: ({ event }) =>
event.type === 'shift' && event.status === 'confirmed',
};false excludes an event. Returning true uses the matched resource's capacity; all three people have capacity one. Requirement role and group fields select matching resources, and resourceMatchesRequirement can add your application's qualification checks.
Do not count cancelled shifts, leave records or an unassigned job as available staff. Keep capacity units consistent: comparing a requirement measured in people with a capacity measured in hours produces an uninterpretable total.
The example uses a normal React RevoGrid component with Scheduler installed once:
<RevoGrid
ref={grid}
plugins={plugins}
columns={columns}
source={events}
eventScheduler={config}
eventSchedulerResources={employees}
eventSchedulerAvailability={shiftAvailability}
eventSchedulerTemplates={templates}
eventSchedulerCoverageRequirements={requirements}
onAftergridinit={() => void connect()}
/>It listens for accepted event-scheduler-event-created, event-scheduler-event-changed and event-scheduler-event-deleted events, then replaces React state with a copy of event.detail.events. The resulting render updates derived requirements. Event objects remain immutable; editing one source object in place is not the state synchronization contract.
The Inspect coverage control reads scheduler.getProjection()?.coverageResults. Each row supplies required, assigned, missing, surplus, resource IDs and event IDs. Use those results for a review panel or export through the documented coverage export.
A missing count is attached to an interval. The afternoon shortage here is one person for four hours, or four person-hours if the application calculates duration-weighted demand. Summing missing across differently sized intervals does not calculate missing hours.
The included template defines four hours of confirmed support work. The button invokes the public recurrence helper on the mounted plugin:
scheduler.createRecurringEvents({
templateId: 'morning',
resourceId: 'ana',
startDateTime: '2026-06-08T09:00:00.000Z',
recurrence: {
frequency: 'weekly',
weekdays: [1, 3, 5],
count: 3,
},
seriesId: 'ana-mornings',
});The result is three 09:00–13:00 shifts on Monday, Wednesday and Friday. Tuesday is deliberately excluded. The template and recurrence helpers use the same permission and validation flow as interactive editing. They create events with recurrence metadata; the application still decides how to present series edits, exceptions and durable storage. The documented recurrence rule supports daily and weekly patterns, not an unrestricted calendar recurrence language.
This example stores shift edits in React memory. Reopening the page restores the fixture. Add the remote persistence workflow when managers need shared, durable schedules, and repeat leave, qualification and overlap checks in the backend.
Coverage describes the schedule supplied to the component. It does not automatically optimize a roster, enforce labor rules, validate every professional qualification or turn a missing-capacity result into an assigned shift. Those policies belong in your application or scheduling service.
End Clara’s shift at 12:30 and check that the shortage starts at 12:30. Add a cancelled shift over the gap and check that the shortage stays at one person.
Explore RevoGrid Scheduler, the live Scheduler examples, and resource booking for the separate problem of reserving a room or piece of equipment without collisions.