Files
supabase/apps/studio/data/config/project-unpause-postgres-versions-query.ts
Alaister YoungandJoshen Lim 8855d05803 chore(studio): swap react-query to object syntax (#39842)
* chore(studio): swap react-query to object syntax

* Fix small issues found

* Fix realtime settings

* Nit

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2025-10-27 09:38:27 +01:00

49 lines
1.5 KiB
TypeScript

import { useQuery, UseQueryOptions } from '@tanstack/react-query'
import { get, handleError } from 'data/fetchers'
import { ResponseError } from 'types'
import { configKeys } from './keys'
export type ProjectUnpausePostgresVersionsVariables = {
projectRef?: string
}
export async function getPostgresUnpauseVersions(
{ projectRef }: ProjectUnpausePostgresVersionsVariables,
signal?: AbortSignal
) {
if (!projectRef) throw new Error('projectRef is required')
const { data, error } = await get('/platform/projects/{ref}/restore/versions', {
params: { path: { ref: projectRef } },
signal,
})
if (error) handleError(error)
return data
}
export type ProjectUnpausePostgresVersionData = Awaited<
ReturnType<typeof getPostgresUnpauseVersions>
>
export type ProjectUnpausePostgresVersionError = ResponseError
export const useProjectUnpausePostgresVersionsQuery = <TData = ProjectUnpausePostgresVersionData>(
{ projectRef }: ProjectUnpausePostgresVersionsVariables,
{
enabled = true,
...options
}: UseQueryOptions<
ProjectUnpausePostgresVersionData,
ProjectUnpausePostgresVersionError,
TData
> = {}
) => {
return useQuery<ProjectUnpausePostgresVersionData, ProjectUnpausePostgresVersionError, TData>({
queryKey: configKeys.projectUnpausePostgresVersions(projectRef),
queryFn: ({ signal }) => getPostgresUnpauseVersions({ projectRef }, signal),
enabled: enabled && typeof projectRef !== 'undefined',
...options,
})
}