You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

use-datasource.ts 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import {
  2. useMutation,
  3. useQuery,
  4. } from '@tanstack/react-query'
  5. import { get } from './base'
  6. import { useInvalid } from './use-base'
  7. import type { DataSourceAuth } from '@/app/components/header/account-setting/data-source-page-new/types'
  8. const NAME_SPACE = 'data-source-auth'
  9. export const useGetDataSourceListAuth = () => {
  10. return useQuery({
  11. queryKey: [NAME_SPACE, 'list'],
  12. queryFn: () => get<{ result: DataSourceAuth[] }>('/auth/plugin/datasource/list'),
  13. retry: 0,
  14. })
  15. }
  16. export const useInvalidDataSourceListAuth = (
  17. ) => {
  18. return useInvalid([NAME_SPACE, 'list'])
  19. }
  20. // !This hook is used for fetching the default data source list, which will be legacy and deprecated in the near future.
  21. export const useGetDefaultDataSourceListAuth = () => {
  22. return useQuery({
  23. queryKey: [NAME_SPACE, 'default-list'],
  24. queryFn: () => get<{ result: DataSourceAuth[] }>('/auth/plugin/datasource/default-list'),
  25. retry: 0,
  26. })
  27. }
  28. export const useInvalidDefaultDataSourceListAuth = (
  29. ) => {
  30. return useInvalid([NAME_SPACE, 'default-list'])
  31. }
  32. export const useGetDataSourceOAuthUrl = (
  33. provider: string,
  34. ) => {
  35. return useMutation({
  36. mutationKey: [NAME_SPACE, 'oauth-url', provider],
  37. mutationFn: (credentialId?: string) => {
  38. return get<
  39. {
  40. authorization_url: string
  41. state: string
  42. context_id: string
  43. }>(`/oauth/plugin/${provider}/datasource/get-authorization-url?credential_id=${credentialId}`)
  44. },
  45. })
  46. }