RoomKitFrontend
useCreateBooking
Create a new booking with automatic idempotency
Overview
useCreateBooking is a mutation hook that creates a new booking. It calls POST {apiUrl}/bookings and automatically generates an idempotency key.
import { useCreateBooking } from '@roomkit/react';Usage
function NewBooking({ roomId }: { roomId: string }) {
const { mutate, data, isLoading, error } = useCreateBooking({
onSuccess: (booking) => {
console.log('Booking created:', booking.id);
},
onError: (err) => {
console.error('Failed to create booking:', err.message);
},
});
const handleSubmit = () => {
mutate({
roomId,
requesterId: 'user-1',
title: 'Team Meeting',
startsAt: '2026-03-02T10:00:00Z',
endsAt: '2026-03-02T11:00:00Z',
purposeType: 'SEMINAR',
});
};
return (
<div>
<button onClick={handleSubmit} disabled={isLoading}>
{isLoading ? 'Creating...' : 'Book Room'}
</button>
{error && <p>Error: {error.message}</p>}
{data && <p>Booked: {data.id}</p>}
</div>
);
}CreateBookingInput
interface CreateBookingInput {
roomId: string;
requesterId: string;
onBehalfOfId?: string | null;
title: string;
description?: string | null;
startsAt: string;
endsAt: string;
priority?: number;
purposeType: string;
recurrenceRuleId?: string | null;
recurrenceModType?: RecurrenceModType | null;
metadata?: string | null;
}| Field | Type | Required | Description |
|---|---|---|---|
roomId | string | Yes | Target room ID |
requesterId | string | Yes | ID of the person requesting |
title | string | Yes | Booking title |
startsAt | string | Yes | ISO 8601 start time |
endsAt | string | Yes | ISO 8601 end time |
purposeType | string | Yes | Purpose (e.g., "LECTURE", "SEMINAR") |
onBehalfOfId | string | null | No | Delegate ID |
description | string | null | No | Description |
priority | number | No | Explicit priority (overrides purpose-based resolution) |
recurrenceRuleId | string | null | No | Link to recurrence series |
recurrenceModType | RecurrenceModType | null | No | Recurrence modification type |
metadata | string | null | No | Arbitrary JSON string |
UseCreateBookingOptions
interface UseCreateBookingOptions {
onSuccess?: (data: Booking) => void;
onError?: (error: Error) => void;
}Return Value
| Field | Type | Description |
|---|---|---|
mutate | (input: CreateBookingInput) => Promise<Booking> | Trigger the creation |
data | Booking | null | The created booking |
isLoading | boolean | true while the request is in flight |
error | Error | null | The error if the request failed |
API Endpoint
POST {apiUrl}/bookingsAn idempotencyKey is automatically generated using crypto.randomUUID() to prevent duplicate bookings on network retries.