Skip to content
Snippets Groups Projects
API.ts 991 B
Newer Older
  • Learn to ignore specific revisions
  • import axios, { AxiosRequestConfig } from 'axios'
    
    import { useQuery } from 'react-query'
    import { toast } from 'react-toastify'
    import { User } from './models/user.model'
    
    const fetchWhoAmI = async () => {
      const { data } = await axios.get<User | null>('/api/common/WhoAmI')
      return data
    }
    
    export const useWhoAmI = () => {
      return useQuery({
        queryKey: ['WhoAmI'],
        queryFn: fetchWhoAmI,
        retry: false,
        onError: error => {
          console.error('error whoami', error)
          toast.error('Accès refusé, veuillez vous connecter')
        },
        refetchOnMount: false,
      })
    }
    
    export const fetchLogout = async () => {
      return await axios.get('/Logout')
    }
    
    
    export const fetchEcogestureImages = async (
      axiosHeaders: AxiosRequestConfig
    ) => {
      const { data: imageNames } = await axios.get<string[]>(
        `/api/animator/imageNames`,
        axiosHeaders
      )
      if (imageNames && imageNames !== null) {
        return imageNames.map(image => `/assets/ecogesture/${image}`)
      }
      return []
    }