import { useQuery } from '@tanstack/react-query' import { projectKeys } from './keys' import { get, handleError } from '@/data/fetchers' import type { ResponseError, UseCustomQueryOptions } from '@/types' 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> export type ProjectStatusError = ResponseError export const useProjectStatusQuery = ( { projectRef }: ProjectStatusVariables, { enabled = true, ...options }: UseCustomQueryOptions = {} ) => useQuery({ queryKey: projectKeys.status(projectRef), queryFn: ({ signal }) => getProjectStatus({ projectRef }, signal), enabled: enabled && typeof projectRef !== 'undefined', ...options, })