Files
supabase/studio/data/profile/profile-query.ts
T
3dca7ff61c feat: disable features (#17553)
* feat: groundwork for disabling features

* update to use profile endpoint & disable features

* fix ts error

* add useIsFeatureEnabled mock

* fix merge conflicts

* fix test

* upgrade to pro

* prettier

* add more billing enabled feature checks

* disable more stuff

* update useIsFeatureEnabled hook

* Fix database reports disk size

* Fix database reports disk size

* disable log sources

* disable moar things

* Tiny fix

---------

Co-authored-by: Kevin Grüneberg <k.grueneberg1994@gmail.com>
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2023-10-16 12:59:36 +08:00

42 lines
1.1 KiB
TypeScript

import { useQuery, UseQueryOptions } from '@tanstack/react-query'
import { get } from 'lib/common/fetch'
import { API_URL, IS_PLATFORM } from 'lib/constants'
import { ResponseError } from 'types'
import { profileKeys } from './keys'
import { Profile } from './types'
export type ProfileResponse = Profile
export async function getProfile(signal?: AbortSignal) {
const response = await get(`${API_URL}/profile`, {
signal,
headers: { Version: '2' },
})
if (response.error) throw response.error
if (!IS_PLATFORM) {
response.disabled_features = process.env.NEXT_PUBLIC_DISABLED_FEATURES?.split(',') ?? []
}
return response as ProfileResponse
}
export type ProfileData = Awaited<ReturnType<typeof getProfile>>
export type ProfileError = ResponseError
export const useProfileQuery = <TData = ProfileData>({
enabled = true,
...options
}: UseQueryOptions<ProfileData, ProfileError, TData> = {}) => {
return useQuery<ProfileData, ProfileError, TData>(
profileKeys.profile(),
({ signal }) => getProfile(signal),
{
staleTime: 1000 * 60 * 30, // default good for 30 mins
...options,
enabled,
}
)
}