Files
supabase/apps/studio/data/profile/profile-query.ts
T
Ivan Vasilov 8b657165b5 chore: Migrate to use custom type for ReactQuery queries and mutations (#40073)
* Add custom types for queries, mutations and infinite queries.

* Migrate all queries to use the new type.

* Migrate all infinite queries to useCustomInfiniteQueryOptions.

* Migrate all mutations to use useCustomMutationOptions.

* Add type to all imports in `types` folder.
2025-11-03 13:18:13 +01:00

42 lines
1.1 KiB
TypeScript

import { useQuery } from '@tanstack/react-query'
import { get, handleError } from 'data/fetchers'
import { IS_PLATFORM } from 'lib/constants'
import type { ResponseError, UseCustomQueryOptions } 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
}: UseCustomQueryOptions<ProfileData, ProfileError, TData> = {}) => {
return useQuery<ProfileData, ProfileError, TData>({
queryKey: profileKeys.profile(),
queryFn: ({ signal }) => getProfile(signal),
staleTime: 1000 * 60 * 30,
...options,
enabled,
})
}