Files
supabase/apps/studio/data/usage/resource-warnings-query.ts
2024-03-04 20:48:22 +08:00

33 lines
1.1 KiB
TypeScript

import { useQuery, UseQueryOptions } from '@tanstack/react-query'
import { get } from 'data/fetchers'
import { usageKeys } from './keys'
import type { ResponseError } from 'types'
import type { components } from 'data/api'
import { IS_PLATFORM } from 'common'
export async function getResourceWarnings(signal?: AbortSignal) {
const { data, error } = await get(`/platform/projects-resource-warnings`, { signal })
if (error) throw 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 * 30, // default 30 minutes
...options,
}
)