
React employee shifts and coverage gaps
Plan weekly shifts, reject work during time off, and expose an afternoon staffing gap that a whole-day count would miss.
Two people can open the same room calendar, see a free slot, and try to book it at the same time. To prevent a double booking, check availability and save the reservation in a single database transaction.
This example combines a RevoGrid Scheduler timeline with a Node.js and SQLite API. The calendar gives immediate feedback for overlaps, closed hours and maintenance. The API makes the final booking decision.
The example source includes the React app and API. Use Node 24.13 or later for its built-in SQLite module.
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=booking. The package's .npmrc selects the public trial registry; no npm token is needed. The trial is an evaluation build. See trial installation and limitations before choosing packages for production.
The application starts a real HTTP server, creates .data/bookings.sqlite, and seeds these records:
| Resource | Booking or exception | Monday 8 June 2026, UTC |
|---|---|---|
| Room A | Customer workshop | 09:00–11:00 |
| Room A | Maintenance, unavailable | 13:00–15:00 |
| Room B | Interview | 11:00–12:00 |
| Portable projector | Available | 08:00–18:00 |
Drag the workshop to 11:00–13:00: it should save. Drag it into maintenance: it should be rejected locally. A new Room B booking starting at 12:00 is valid because the interview ends at 12:00. Select Reset demo to restore the fixture.
The resource list describes what can be reserved. The normal RevoGrid source holds event records, with stable IDs and start/end instants. In remote mode the loaders supply those records; generated timeline rows are internal projection data.
const resources = [
{ id: 'room-a', name: 'Room A', capacity: 1 },
{ id: 'room-b', name: 'Room B', capacity: 1 },
{ id: 'projector', name: 'Portable projector', capacity: 1 },
];
const booking = {
id: 'workshop',
resourceId: 'room-a',
title: 'Customer workshop',
startDateTime: '2026-06-08T09:00:00.000Z',
endDateTime: '2026-06-08T11:00:00.000Z',
};Use one resource per reservation for this example. Reserving a room and projector together is a different transaction: both resources must be checked and reserved atomically. Setting allowMultiResourceAssignment: false makes the example's UI match its single-resource endpoint.
Use dated working availability for opening hours and a blocked interval for maintenance. The full fixture generates one opening interval for each day of the example week.
const availability = [
{
id: 'monday-hours',
kind: 'working',
startDateTime: '2026-06-08T08:00:00.000Z',
endDateTime: '2026-06-08T18:00:00.000Z',
},
{
id: 'maintenance',
resourceId: 'room-a',
kind: 'blocked',
title: 'Projector maintenance',
startDateTime: '2026-06-08T13:00:00.000Z',
endDateTime: '2026-06-08T15:00:00.000Z',
},
];Configure blocking rules in eventScheduler.conflicts:
const conflicts = {
enabled: true,
scope: 'same-resource',
policy: 'mark',
rules: {
overlap: 'error',
'outside-availability': 'error',
'blocked-time': 'error',
'invalid-duration': 'error',
},
} as const;An error rule rejects the mutation before updating source. nonWorkingTime alone only shades the timeline; it does not enforce booking policy. Use availability or named calendars as the scheduling input, with conflict rules controlling acceptance.
The React screen mounts the actual wrapper:
<RevoGrid
ref={grid}
plugins={plugins}
columns={emptyColumns}
eventScheduler={config}
onAftergridinit={() => void connect()}
/>plugins, emptyColumns and config keep stable references. config.remote loads events, resources and availability. The remote screen omits the React source prop so rerendering a status message does not reassign an empty source over the remotely loaded canonical events. The example includes a small declaration file extending the wrapper's JSX properties with Scheduler's published element types; it adds no new runtime API.
Two browsers can both see an empty slot. A separate availability request followed by an insert still leaves a race between those operations. The example's server/store.ts takes a SQLite write transaction before checking overlaps, then saves the booking and its operation receipt before committing.
The overlap query uses half-open intervals: [start, end). Its bound values are the proposed room ID, booking ID, end instant and start instant.
SELECT id
FROM bookings
WHERE resource_id = ? AND id <> ?
AND start_ms < ? AND end_ms > ?
LIMIT 1;That condition allows adjacent bookings. It also detects a long existing reservation that begins before the proposed reservation and ends after it.
The complete transaction performs these steps:
BEGIN IMMEDIATE acquires the database write transaction.SQLite's transaction documentation explains why an immediate write transaction prevents another writer from passing the same check concurrently. This sample serializes writes to one database; a production database needs an equivalent constraint, locking or serializable transaction design appropriate to its workload.
The server accepts only create, edit, move and resize for one booking. It rejects bulk requests and unknown resources. It returns a canonical event containing the next revision rather than trusting a browser-supplied revision.
The runnable app uses remote.commands, with an application endpoint returning a correlated receipt:
// Example accepted response from this application's endpoint.
{
operationId: 'the-submitted-operation-id',
status: 'accepted',
revision: '2',
changes: {
event: {
id: 'workshop', resourceId: 'room-a', title: 'Customer workshop',
startDateTime: '2026-06-08T11:00:00.000Z',
endDateTime: '2026-06-08T13:00:00.000Z',
metadata: { revision: '2' },
},
},
}Scheduler owns pending presentation and rejection rollback. The app supplies HTTP calls, revision selection and receipt lookup. A lost response remains unknown until recovery; it is not evidence that the room is available again. See the API, optimistic updates and recovery tutorial for the complete client flow.
Run pnpm test. The automated example test submits overlapping bookings concurrently through two HTTP clients and asserts one accepted receipt, one rejected receipt and one stored reservation. Other checks cover adjacent bookings, maintenance, closed hours, stale edits, receipt persistence and a response lost after commit.
For a manual check, open two tabs, create different bookings for the same free Room B interval, and reload both. Only the server-accepted reservation should remain. A browser's overlap rules only know the records it has loaded.
The demo is deliberately a single-tenant, loopback-only application without login. Before deployment, derive tenant and permission scope from authenticated server state, authorize each resource and operation, and scope database keys and receipts accordingly. The library does not provide those backend services. UTC keeps this fixture reproducible; an office calendar should use its named time zone and define daylight-saving behavior explicitly.
Continue with the Scheduler product page, live Scheduler demos, remote saving contract, or the employee shift planner when the main question is staffing coverage.