mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 18:05:11 +03:00
18 lines
558 B
TypeScript
18 lines
558 B
TypeScript
import useSWR from 'swr'
|
|
import { get } from 'lib/common/fetch'
|
|
import { API_URL } from 'lib/constants'
|
|
import { UsageStats } from 'components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.types'
|
|
|
|
export function useProjectUsage(ref?: string) {
|
|
const url = `${API_URL}/projects/${ref}/usage`
|
|
const { data, error } = useSWR<any>(ref ? url : null, get)
|
|
const anyError = data?.error || error
|
|
|
|
return {
|
|
usage: anyError ? undefined : (data as UsageStats),
|
|
error: anyError,
|
|
isLoading: !anyError && !data,
|
|
isError: !!anyError,
|
|
}
|
|
}
|