Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

1.2 KB
Raw Blame
import { useQuery } from '@tanstack/react-query'

import { actionKeys } from './keys'
import type { operations } from '@/data/api'
import { get, handleError } from '@/data/fetchers'
import type { ResponseError, UseCustomQueryOptions } from '@/types'

export type ActionsVariables = operations['v1-list-action-runs']['parameters']['path']

export async function listActionRuns(params: ActionsVariables, signal?: AbortSignal) {
  const { data, error } = await get(`/v1/projects/{ref}/actions`, {
    params: { path: params },
    signal,
  })
  if (error) handleError(error)
  return data
}

export type ActionsData = Awaited<ReturnType<typeof listActionRuns>>
export type ActionsError = ResponseError

export type ActionRunStep = ActionsData[number]['run_steps'][number]
export type ActionName = ActionRunStep['name']
export type ActionStatus = ActionRunStep['status']

export const useActionsQuery = <TData = ActionsData>(
  { ref }: ActionsVariables,
  { enabled = true, ...options }: UseCustomQueryOptions<ActionsData, ActionsError, TData> = {}
) =>
  useQuery<ActionsData, ActionsError, TData>({
    queryKey: actionKeys.list(ref),
    queryFn: ({ signal }) => listActionRuns({ ref }, signal),
    enabled: enabled && Boolean(ref),
    staleTime: 0,
    ...options,
  })