Files
supabase/apps/studio/data/config/project-upgrade-eligibility-query.ts
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

58 lines
2.0 KiB
TypeScript

import { useQuery } from '@tanstack/react-query'
import { components } from 'api-types'
import { IS_PLATFORM } from 'common'
import { get, handleError } from 'data/fetchers'
import { useProjectDetailQuery } from 'data/projects/project-detail-query'
import { PROJECT_STATUS } from 'lib/constants/infrastructure'
import type { ResponseError, UseCustomQueryOptions } from 'types'
import { configKeys } from './keys'
export type ProjectUpgradeTargetVersion = { postgres_version: string; release_channel: string }
export type ProjectUpgradeEligibilityVariables = { projectRef?: string }
export type ProjectUpgradeEligibilityResponse =
components['schemas']['ProjectUpgradeEligibilityResponse']
export async function getProjectUpgradeEligibility(
{ projectRef }: ProjectUpgradeEligibilityVariables,
signal?: AbortSignal
) {
if (!projectRef) throw new Error('projectRef is required')
const { data, error } = await get('/v1/projects/{ref}/upgrade/eligibility', {
params: { path: { ref: projectRef } },
signal,
})
if (error) handleError(error)
return data
}
export type ProjectUpgradeEligibilityData = Awaited<ReturnType<typeof getProjectUpgradeEligibility>>
export type ProjectUpgradeEligibilityError = ResponseError
export const useProjectUpgradeEligibilityQuery = <TData = ProjectUpgradeEligibilityData>(
{ projectRef }: ProjectUpgradeEligibilityVariables,
{
enabled = true,
...options
}: UseCustomQueryOptions<
ProjectUpgradeEligibilityData,
ProjectUpgradeEligibilityError,
TData
> = {}
) => {
const { data: project } = useProjectDetailQuery({ ref: projectRef })
return useQuery<ProjectUpgradeEligibilityData, ProjectUpgradeEligibilityError, TData>({
queryKey: configKeys.upgradeEligibility(projectRef),
queryFn: ({ signal }) => getProjectUpgradeEligibility({ projectRef }, signal),
enabled:
enabled &&
project !== undefined &&
project.status === PROJECT_STATUS.ACTIVE_HEALTHY &&
typeof projectRef !== 'undefined' &&
IS_PLATFORM,
...options,
})
}