mirror of
https://github.com/supabase/supabase.git
synced 2026-05-30 17:32:00 +08:00
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
|
|
import { IS_PLATFORM } from 'common'
|
|
import type { components } from 'data/api'
|
|
import { get, handleError } from 'data/fetchers'
|
|
import type { ResponseError } from 'types'
|
|
import { usageKeys } from './keys'
|
|
|
|
export async function getResourceWarnings(signal?: AbortSignal) {
|
|
const { data, error } = await get(`/platform/projects-resource-warnings`, { signal })
|
|
if (error) handleError(error)
|
|
|
|
return data
|
|
}
|
|
|
|
export type ResourceWarning = components['schemas']['ProjectResourceWarningsResponse']
|
|
export type ResourceWarningsData = Awaited<ReturnType<typeof getResourceWarnings>>
|
|
export type ResourceWarningsError = ResponseError
|
|
|
|
export const useResourceWarningsQuery = <TData = ResourceWarningsData>({
|
|
enabled = true,
|
|
...options
|
|
}: UseQueryOptions<ResourceWarningsData, ResourceWarningsError, TData> = {}) =>
|
|
useQuery<ResourceWarningsData, ResourceWarningsError, TData>(
|
|
usageKeys.resourceWarnings(),
|
|
({ signal }) => getResourceWarnings(signal),
|
|
{
|
|
enabled: IS_PLATFORM && enabled,
|
|
staleTime: 1000 * 60 * 60, // default 60 minutes
|
|
...options,
|
|
}
|
|
)
|