My App
RoomKitFrontend

useBulkOperationStatus

Poll bulk operation progress until completion

Overview

useBulkOperationStatus polls a bulk operation's status at a configurable interval. It calls GET {apiUrl}/bulk-operations/{operationId} repeatedly until the operation reaches a terminal status (completed or failed).

import { useBulkOperationStatus } from '@roomkit/react';

Usage

function ImportProgress({ operationId }: { operationId: string }) {
    const { data, isLoading } = useBulkOperationStatus({
        operationId,
        pollIntervalMs: 2000,
        onComplete: (op) => {
            console.log('Import finished:', op.processedItems, 'items');
        },
    });

    if (!data) return <div>Loading...</div>;

    const progress = data.totalItems > 0
        ? Math.round((data.processedItems / data.totalItems) * 100)
        : 0;

    return (
        <div>
            <p>Status: {data.status}</p>
            <progress value={data.processedItems} max={data.totalItems} />
            <p>{progress}% — {data.processedItems}/{data.totalItems} items</p>
            {data.conflictsDetected > 0 && (
                <p>{data.conflictsDetected} conflicts detected</p>
            )}
        </div>
    );
}

UseBulkOperationStatusOptions

interface UseBulkOperationStatusOptions {
    operationId: string;
    pollIntervalMs?: number;
    enabled?: boolean;
    onSuccess?: (data: BulkOperation) => void;
    onError?: (error: Error) => void;
    onComplete?: (data: BulkOperation) => void;
}
OptionTypeRequiredDescription
operationIdstringYesThe bulk operation ID to poll
pollIntervalMsnumberNoPolling interval in milliseconds (default: 2000)
enabledbooleanNoSet to false to pause polling
onSuccess(data) => voidNoCalled on each successful poll
onError(error) => voidNoCalled when a poll request fails
onComplete(data) => voidNoCalled once when the operation reaches a terminal status

Return Value

FieldTypeDescription
dataBulkOperation | nullLatest operation status
isLoadingbooleantrue while a poll request is in flight
errorError | nullThe error if the last poll failed
refetch() => Promise<void>Manually trigger a poll

Polling automatically stops when the operation status is completed or failed.

API Endpoint

GET {apiUrl}/bulk-operations/{operationId}

On this page