mirror of
https://github.com/supabase/supabase.git
synced 2026-09-08 19:08:44 +08:00
Don't fire the `available-versions` request when `dbRegion` is falsy (undefined or empty string). Fixes race condition where the request fires before a region is selected. ## To test - Confirm no invalid `available-versions` request in the network tab - Confirm create new project still works <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved database region validation during project creation to consistently handle empty or undefined values. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
76 lines
2.4 KiB
TypeScript
76 lines
2.4 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
import { CloudProvider } from 'shared-data'
|
|
|
|
import { configKeys } from './keys'
|
|
import { handleError, post } from '@/data/fetchers'
|
|
import type { ResponseError, UseCustomQueryOptions } from '@/types'
|
|
|
|
export type ProjectCreationPostgresVersionsVariables = {
|
|
cloudProvider: CloudProvider
|
|
dbRegion: string
|
|
organizationSlug: string | undefined
|
|
}
|
|
|
|
export async function getPostgresCreationVersions(
|
|
{ cloudProvider, dbRegion, organizationSlug }: ProjectCreationPostgresVersionsVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!organizationSlug) throw new Error('organizationSlug is required')
|
|
|
|
const { data, error } = await post('/platform/organizations/{slug}/available-versions', {
|
|
params: { path: { slug: organizationSlug } },
|
|
body: { provider: cloudProvider, region: dbRegion },
|
|
signal,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
export type ProjectCreationPostgresVersionData = Awaited<
|
|
ReturnType<typeof getPostgresCreationVersions>
|
|
>
|
|
export type ProjectCreationPostgresVersionError = ResponseError
|
|
|
|
export const useProjectCreationPostgresVersionsQuery = <TData = ProjectCreationPostgresVersionData>(
|
|
{ cloudProvider, dbRegion, organizationSlug }: ProjectCreationPostgresVersionsVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<
|
|
ProjectCreationPostgresVersionData,
|
|
ProjectCreationPostgresVersionError,
|
|
TData
|
|
> = {}
|
|
) => {
|
|
return useQuery<ProjectCreationPostgresVersionData, ProjectCreationPostgresVersionError, TData>({
|
|
queryKey: configKeys.projectCreationPostgresVersions(organizationSlug, cloudProvider, dbRegion),
|
|
queryFn: ({ signal }) =>
|
|
getPostgresCreationVersions({ organizationSlug, cloudProvider, dbRegion }, signal),
|
|
enabled:
|
|
enabled && typeof organizationSlug !== 'undefined' && organizationSlug !== '_' && !!dbRegion,
|
|
...options,
|
|
})
|
|
}
|
|
|
|
export const useAvailableOrioleImageVersion = (
|
|
{ cloudProvider, dbRegion, organizationSlug }: ProjectCreationPostgresVersionsVariables,
|
|
{ enabled = true }: { enabled?: boolean } = {}
|
|
) => {
|
|
const { data } = useProjectCreationPostgresVersionsQuery(
|
|
{
|
|
cloudProvider,
|
|
dbRegion,
|
|
organizationSlug,
|
|
},
|
|
{
|
|
enabled,
|
|
select(data) {
|
|
return (data?.available_versions ?? []).find((x) => x.postgres_engine === '17-oriole')
|
|
},
|
|
}
|
|
)
|
|
|
|
return data
|
|
}
|