mirror of
https://github.com/supabase/supabase.git
synced 2026-10-17 23:29:08 +03:00
30 lines
1.0 KiB
TypeScript
30 lines
1.0 KiB
TypeScript
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
import type { components } from 'data/api'
|
|
import { get, handleError } from 'data/fetchers'
|
|
import { invoicesKeys } from './keys'
|
|
import { IS_PLATFORM } from 'lib/constants'
|
|
|
|
export type OverdueInvoicesResponse = components['schemas']['OverdueInvoiceCount']
|
|
|
|
export async function getOverdueInvoices(signal?: AbortSignal) {
|
|
const { data, error } = await get('/platform/stripe/invoices/overdue', {
|
|
signal,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
export type OverdueInvoicesData = Awaited<ReturnType<typeof getOverdueInvoices>>
|
|
export type OverdueInvoicesError = unknown
|
|
|
|
export const useOverdueInvoicesQuery = <TData = OverdueInvoicesData>({
|
|
enabled = true,
|
|
...options
|
|
}: UseQueryOptions<OverdueInvoicesData, OverdueInvoicesError, TData> = {}) =>
|
|
useQuery<OverdueInvoicesData, OverdueInvoicesError, TData>(
|
|
invoicesKeys.overdueInvoices(),
|
|
({ signal }) => getOverdueInvoices(signal),
|
|
{ enabled: enabled && IS_PLATFORM, ...options }
|
|
)
|