Files
supabase/apps/studio/data/profile/profile-query.ts
T
Joshen Lim 336d623910 Chore/refactor telemetry calls for dashboard to support PH (#29747)
* Refactor telemetry event into RQ hook, and update to support PH

* Refactor telemetry identify into RQ hook, and update to support PH

* Refactor telemetry page into RQ hook, and update to support PH

* Clean up and deprecate lib/telemetry

* Pretty

* Add ts-ignore in docs for telemetry calls temporarily

* Add credentials include for send event, page and identify mutation hooks

* Add consent check for event and page telemetry, allow RQ mutations for those to fail silently without a toast
2024-10-09 14:32:30 +08:00

44 lines
1.1 KiB
TypeScript

import { useQuery, UseQueryOptions } from '@tanstack/react-query'
import { get, handleError } from 'data/fetchers'
import { IS_PLATFORM } from 'lib/constants'
import type { ResponseError } from 'types'
import { profileKeys } from './keys'
import type { Profile } from './types'
export async function getProfile(signal?: AbortSignal) {
const { data, error } = await get('/platform/profile', {
signal,
headers: { Version: '2' },
})
if (error) handleError(error)
if (!IS_PLATFORM) {
return {
...data,
disabled_features: process.env.NEXT_PUBLIC_DISABLED_FEATURES?.split(',') ?? [],
} as Profile
} else {
return data as Profile
}
}
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,
}
)
}