()
| 1470 | * terminal state arrive over the table-events SSE stream (see `useTableEventStream`). |
| 1471 | */ |
| 1472 | export function useImportCsvAsync() { |
| 1473 | const queryClient = useQueryClient() |
| 1474 | return useMutation({ |
| 1475 | mutationFn: async ({ workspaceId, file, onProgress }: ImportCsvAsyncParams) => { |
| 1476 | const fileKey = await uploadCsvToWorkspaceStorage(file, workspaceId, onProgress) |
| 1477 | const response = await requestJson(importTableAsyncContract, { |
| 1478 | body: { workspaceId, fileKey, fileName: file.name }, |
| 1479 | }) |
| 1480 | return response.data |
| 1481 | }, |
| 1482 | onError: (error) => { |
| 1483 | logger.error('Failed to start async CSV import:', error) |
| 1484 | toast.error(error.message, { duration: 5000 }) |
| 1485 | }, |
| 1486 | onSettled: () => { |
| 1487 | queryClient.invalidateQueries({ queryKey: tableKeys.lists() }) |
| 1488 | }, |
| 1489 | }) |
| 1490 | } |
| 1491 | |
| 1492 | interface ImportFileAsTableParams { |
| 1493 | workspaceId: string |
no test coverage detected