Files
supabase/apps/studio/data/subscriptions/project-addons-query.ts
dff6c817ae Chore/assistant in self hosted (#33422)
* Add layoutheader to self-hosted to allow showing assistant

* Fix layout

* Remove debug checks

* Check for key

* Dont load tables

* Fix assistant error handling

* Yeet

* Update turbo.json

* Another one

* god

* Fix

* Add fallback

* last attempt to fix

* Clean up

* take the wheel

* Tiny fix

* Skip enrich query for local, to match prod

---------

Co-authored-by: Alaister Young <alaister@users.noreply.github.com>
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2025-02-18 17:37:53 +08:00

42 lines
1.3 KiB
TypeScript

import { useQuery, UseQueryOptions } from '@tanstack/react-query'
import { get, handleError } from 'data/fetchers'
import { IS_PLATFORM } from 'lib/constants'
import type { ResponseError } from 'types'
import { subscriptionKeys } from './keys'
export type ProjectAddonsVariables = {
projectRef?: string
}
export async function getProjectAddons(
{ projectRef }: ProjectAddonsVariables,
signal?: AbortSignal
) {
if (!projectRef) throw new Error('projectRef is required')
const { error, data } = await get(`/platform/projects/{ref}/billing/addons`, {
params: { path: { ref: projectRef } },
signal,
})
if (error) handleError(error)
return data
}
export type ProjectAddonsData = Awaited<ReturnType<typeof getProjectAddons>>
export type ProjectAddonsError = ResponseError
export const useProjectAddonsQuery = <TData = ProjectAddonsData>(
{ projectRef }: ProjectAddonsVariables,
{ enabled = true, ...options }: UseQueryOptions<ProjectAddonsData, ProjectAddonsError, TData> = {}
) =>
useQuery<ProjectAddonsData, ProjectAddonsError, TData>(
subscriptionKeys.addons(projectRef),
({ signal }) => getProjectAddons({ projectRef }, signal),
{
enabled: enabled && IS_PLATFORM && typeof projectRef !== 'undefined',
...options,
}
)