mirror of
https://github.com/supabase/supabase.git
synced 2026-10-07 02:15:05 +03:00
* chore: use data/fetchers and API spec * Remove unused imports --------- Co-authored-by: Thomas Eckl <31189692+ecktoteckto@users.noreply.github.com> Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
import { get } from 'data/fetchers'
|
|
import { subscriptionKeys } from './keys'
|
|
|
|
export type OrgPlansVariables = {
|
|
orgSlug?: string
|
|
}
|
|
|
|
export async function getOrgPlans({ orgSlug }: OrgPlansVariables, signal?: AbortSignal) {
|
|
if (!orgSlug) throw new Error('orgSlug is required')
|
|
|
|
const { error, data } = await get('/platform/organizations/{slug}/billing/plans', {
|
|
params: { path: { slug: orgSlug } },
|
|
signal,
|
|
})
|
|
if (error) throw error
|
|
|
|
return data
|
|
}
|
|
|
|
export type OrgPlansData = Awaited<ReturnType<typeof getOrgPlans>>
|
|
export type OrgPlansError = unknown
|
|
|
|
export const useOrgPlansQuery = <TData = OrgPlansData>(
|
|
{ orgSlug }: OrgPlansVariables,
|
|
{ enabled = true, ...options }: UseQueryOptions<OrgPlansData, OrgPlansError, TData> = {}
|
|
) =>
|
|
useQuery<OrgPlansData, OrgPlansError, TData>(
|
|
subscriptionKeys.orgPlans(orgSlug),
|
|
({ signal }) => getOrgPlans({ orgSlug }, signal),
|
|
{
|
|
enabled: enabled && typeof orgSlug !== 'undefined',
|
|
...options,
|
|
}
|
|
)
|