mirror of
https://github.com/supabase/supabase.git
synced 2026-05-22 08:23:28 +08:00
* 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.
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { get, handleError } from 'data/fetchers'
|
|
import type { ResponseError, UseCustomQueryOptions } from 'types'
|
|
import { projectKeys } from './keys'
|
|
|
|
export type ProjectStatusVariables = {
|
|
projectRef?: string
|
|
}
|
|
|
|
export async function getProjectStatus(
|
|
{ projectRef }: ProjectStatusVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!projectRef) throw new Error('Project ref is required')
|
|
|
|
const { data, error } = await get(`/platform/projects/{ref}/status`, {
|
|
params: { path: { ref: projectRef } },
|
|
signal,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data as { status: string }
|
|
}
|
|
|
|
export type ProjectStatusData = Awaited<ReturnType<typeof getProjectStatus>>
|
|
export type ProjectStatusError = ResponseError
|
|
|
|
export const useProjectStatusQuery = <TData = ProjectStatusData>(
|
|
{ projectRef }: ProjectStatusVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<ProjectStatusData, ProjectStatusError, TData> = {}
|
|
) =>
|
|
useQuery<ProjectStatusData, ProjectStatusError, TData>({
|
|
queryKey: projectKeys.status(projectRef),
|
|
queryFn: ({ signal }) => getProjectStatus({ projectRef }, signal),
|
|
enabled: enabled && typeof projectRef !== 'undefined',
|
|
...options,
|
|
})
|