Skip to content

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

1.1 KB
Raw Blame
import { queryOptions } from '@tanstack/react-query'
import type { components } from 'api-types'

import { partnersKeys } from './keys'
import { get, handleError } from '@/data/fetchers'

type GetAccountRequestVariables = {
  arId?: string
}

export type AccountRequestDetails = components['schemas']['AccountRequestDetailsDto_Output']

async function getAccountRequest({ arId }: GetAccountRequestVariables, signal?: AbortSignal) {
  if (!arId) throw new Error('Account request ID is required')

  const { data, error } = await get(
    '/platform/stripe/projects/provisioning/account_requests/{id}',
    {
      params: { path: { id: arId } },
      signal,
    }
  )

  if (error) handleError(error)
  return data
}

export const accountRequestQueryOptions = (
  { arId }: GetAccountRequestVariables,
  { enabled = true }: { enabled?: boolean } = { enabled: true }
) => {
  return queryOptions({
    queryKey: partnersKeys.getStripeProjects(arId),
    queryFn: ({ signal }) => getAccountRequest({ arId }, signal),
    enabled: enabled && typeof arId !== 'undefined',
  })
}