()
| 1539 | * Resolves immediately; progress + completion arrive over the table-events SSE stream. |
| 1540 | */ |
| 1541 | export function useImportCsvIntoTableAsync() { |
| 1542 | const queryClient = useQueryClient() |
| 1543 | return useMutation({ |
| 1544 | mutationFn: async ({ |
| 1545 | workspaceId, |
| 1546 | tableId, |
| 1547 | file, |
| 1548 | mode, |
| 1549 | mapping, |
| 1550 | createColumns, |
| 1551 | onProgress, |
| 1552 | }: ImportCsvIntoTableAsyncParams) => { |
| 1553 | const fileKey = await uploadCsvToWorkspaceStorage(file, workspaceId, onProgress) |
| 1554 | const response = await requestJson(importIntoTableAsyncContract, { |
| 1555 | params: { tableId }, |
| 1556 | body: { workspaceId, fileKey, fileName: file.name, mode, mapping, createColumns }, |
| 1557 | }) |
| 1558 | return response.data |
| 1559 | }, |
| 1560 | onError: (error) => { |
| 1561 | logger.error('Failed to start async CSV import:', error) |
| 1562 | toast.error(error.message, { duration: 5000 }) |
| 1563 | }, |
| 1564 | onSettled: (_data, _error, variables) => { |
| 1565 | invalidateRowCount(queryClient, variables.tableId) |
| 1566 | }, |
| 1567 | }) |
| 1568 | } |
| 1569 | |
| 1570 | interface ImportCsvIntoTableParams { |
| 1571 | workspaceId: string |
no test coverage detected