Files
supabase/apps/studio/data/subscriptions/project-addons-query.ts
Joshen Lim 0a4166a587 Support for Dedicated Pooler in Connection Pooling Part 2 (#33829)
* Init

* Initial set up for hooking up supavisor and pgbouncer

* Hook up pgbouncer status check after swapping pooler type

* Add check for nano compute for switching to pg bouncer

* Add check for ipv4 addon

* Remove expect error tag

* Update copy in IPv4SidePanel

* Add badge to select options for pooler types

* Hook up pgbouncer config for connect UI

* Refactor pooling-configuration react queries to supavisor-configuration

* Update Ipv4 compatability UI indicators in Connect UI when on pgbouncer

* Remove statement mode

* Resolve undefined problem with react hook form

* Fix

* Update UI texts from PgBouncer to Dedicated Pooler

* Feature flag changes

* Add pooler settings link in Connect UI

* Smol update

* Update session pooler description for pgbouncer
2025-02-28 16:26:47 +08:00

46 lines
1.4 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
}
// [Joshen] For any customer facing text - let's use "Add-on" hyphenated
// Will need to address consistency across the dashboard
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',
staleTime: 60 * 60 * 1000, // 60 minutes
...options,
}
)