()
| 406 | } |
| 407 | |
| 408 | export function useUploadWorkspaceFile() { |
| 409 | const queryClient = useQueryClient() |
| 410 | |
| 411 | return useMutation({ |
| 412 | mutationFn: ({ workspaceId, file, folderId, onProgress, signal }: UploadFileParams) => |
| 413 | uploadWorkspaceFile(workspaceId, file, folderId, onProgress, signal), |
| 414 | onSettled: (_data, _error, variables) => { |
| 415 | if (variables.skipInvalidation) return |
| 416 | queryClient.invalidateQueries({ |
| 417 | queryKey: workspaceFilesKeys.workspaceLists(variables.workspaceId), |
| 418 | }) |
| 419 | queryClient.invalidateQueries({ queryKey: workspaceFilesKeys.storageInfo() }) |
| 420 | }, |
| 421 | onSuccess: (_data, variables) => { |
| 422 | if (!variables.skipToast) { |
| 423 | toast.success(`Uploaded "${variables.file.name}"`) |
| 424 | } |
| 425 | }, |
| 426 | onError: (error, variables) => { |
| 427 | logger.error('Failed to upload file:', error) |
| 428 | if (!variables.skipToast) { |
| 429 | toast.error(`Failed to upload "${variables.file.name}": ${error.message}`, { |
| 430 | duration: 5000, |
| 431 | }) |
| 432 | } |
| 433 | }, |
| 434 | }) |
| 435 | } |
| 436 | |
| 437 | /** |
| 438 | * Update workspace file content mutation |
no test coverage detected