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-share.ts 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { useGlobalPublicStore } from '@/context/global-public-context'
  2. import { AccessMode } from '@/models/access-control'
  3. import { useQuery } from '@tanstack/react-query'
  4. import { fetchAppInfo, fetchAppMeta, fetchAppParams, getAppAccessModeByAppCode } from './share'
  5. const NAME_SPACE = 'webapp'
  6. export const useGetWebAppAccessModeByCode = (code: string | null) => {
  7. const systemFeatures = useGlobalPublicStore(s => s.systemFeatures)
  8. return useQuery({
  9. queryKey: [NAME_SPACE, 'appAccessMode', code],
  10. queryFn: () => {
  11. if (systemFeatures.webapp_auth.enabled === false) {
  12. return {
  13. accessMode: AccessMode.PUBLIC,
  14. }
  15. }
  16. if (!code || code.length === 0)
  17. return Promise.reject(new Error('App code is required to get access mode'))
  18. return getAppAccessModeByAppCode(code)
  19. },
  20. enabled: !!code,
  21. })
  22. }
  23. export const useGetWebAppInfo = () => {
  24. return useQuery({
  25. queryKey: [NAME_SPACE, 'appInfo'],
  26. queryFn: () => {
  27. return fetchAppInfo()
  28. },
  29. })
  30. }
  31. export const useGetWebAppParams = () => {
  32. return useQuery({
  33. queryKey: [NAME_SPACE, 'appParams'],
  34. queryFn: () => {
  35. return fetchAppParams(false)
  36. },
  37. })
  38. }
  39. export const useGetWebAppMeta = () => {
  40. return useQuery({
  41. queryKey: [NAME_SPACE, 'appMeta'],
  42. queryFn: () => {
  43. return fetchAppMeta(false)
  44. },
  45. })
  46. }