Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Address comments

Joshen Lim11382970080b
diff --git a/studio/data/fetchers.ts b/studio/data/fetchers.ts
index 295ee9b7578..6c5ca18facd 100644
--- a/studio/data/fetchers.ts
+++ b/studio/data/fetchers.ts
@@ -89,11 +89,9 @@ export const del: typeof _del = async (url, init) => {
export const head: typeof _head = async (url, init) => {
const headers = await constructHeaders(init?.headers)
- // @ts-ignore
return await _head(url, {
...init,
headers,
- parseAs: 'text',
})
}
diff --git a/studio/data/invoices/invoices-count-query.ts b/studio/data/invoices/invoices-count-query.ts
index 8d8fe650e3d..241ff0c5341 100644
--- a/studio/data/invoices/invoices-count-query.ts
+++ b/studio/data/invoices/invoices-count-query.ts
@@ -18,6 +18,7 @@ export async function getInvoicesCount(
const res = await head(`/platform/stripe/invoices`, {
params: { query: { customer: customerId, slug } },
signal,
+ parseAs: 'text',
})
if (res.error) throw (res as any).error
diff --git a/studio/data/invoices/invoices-query.ts b/studio/data/invoices/invoices-query.ts
index 1c63e92b39a..617fd32b6a3 100644
--- a/studio/data/invoices/invoices-query.ts
+++ b/studio/data/invoices/invoices-query.ts
@@ -6,12 +6,12 @@ import { invoicesKeys } from './keys'
export type InvoicesVariables = {
customerId?: string
slug?: string
- offset: number
- limit: number
+ offset?: number
+ limit?: number
}
export async function getInvoices(
- { customerId, slug, offset, limit }: InvoicesVariables,
+ { customerId, slug, offset = 0, limit = 10 }: InvoicesVariables,
signal?: AbortSignal
) {
if (!customerId) throw new Error('Customer ID is required')
@@ -36,16 +36,12 @@ export const useInvoicesQuery = <TData = InvoicesData>(
{ customerId, slug, offset, limit }: InvoicesVariables,
{ enabled = true, ...options }: UseQueryOptions<InvoicesData, InvoicesError, TData> = {}
) =>
+ // [Joshen] Switch to useInfiniteQuery
useQuery<InvoicesData, InvoicesError, TData>(
- invoicesKeys.list(customerId, slug),
+ invoicesKeys.list(customerId, slug, offset),
({ signal }) => getInvoices({ customerId, slug, offset, limit }, signal),
{
- enabled:
- enabled &&
- typeof customerId !== 'undefined' &&
- typeof slug !== 'undefined' &&
- typeof limit !== 'undefined' &&
- typeof offset !== 'undefined',
+ enabled: enabled && typeof customerId !== 'undefined' && typeof slug !== 'undefined',
...options,
}
)
diff --git a/studio/data/invoices/keys.ts b/studio/data/invoices/keys.ts
index 6c25d4fe23e..5b1a5a482a8 100644
--- a/studio/data/invoices/keys.ts
+++ b/studio/data/invoices/keys.ts
@@ -2,12 +2,13 @@ export const invoicesKeys = {
overdueInvoices: () => ['invoices', 'overdue'] as const,
invoice: (id: string | undefined) => ['invoice', id] as const,
- list: (customerId: string | undefined, slug: string | undefined) =>
- ['invoices', customerId, slug] as const,
+ list: (customerId: string | undefined, slug: string | undefined, offset: number | undefined) =>
+ ['invoices', customerId, slug, offset] as const,
count: (customerId: string | undefined, slug: string | undefined) =>
['invoices', customerId, slug, 'count'] as const,
- projectInvoices: (projectRef: string | undefined) => ['invoices', projectRef] as const,
+ projectInvoices: (projectRef: string | undefined, offset: number | undefined) =>
+ ['invoices', projectRef, offset] as const,
projectInvoicesCount: (projectRef: string | undefined) =>
['invoices', projectRef, 'count'] as const,
upcomingPreview: (projectRef: string | undefined) =>
diff --git a/studio/data/invoices/project-invoices-count-query.ts b/studio/data/invoices/project-invoices-count-query.ts
index a3a165816de..7453d934013 100644
--- a/studio/data/invoices/project-invoices-count-query.ts
+++ b/studio/data/invoices/project-invoices-count-query.ts
@@ -16,6 +16,7 @@ export async function getProjectInvoicesCount(
const res = await head(`/platform/projects/{ref}/invoices`, {
params: { path: { ref: projectRef } },
signal,
+ parseAs: 'text',
})
if (res.error) throw (res as any).error
diff --git a/studio/data/invoices/project-invoices-query.ts b/studio/data/invoices/project-invoices-query.ts
index fe697397be5..01475bf4aa5 100644
--- a/studio/data/invoices/project-invoices-query.ts
+++ b/studio/data/invoices/project-invoices-query.ts
@@ -5,12 +5,12 @@ import { invoicesKeys } from './keys'
export type ProjectInvoicesVariables = {
projectRef?: string
- offset: number
- limit: number
+ offset?: number
+ limit?: number
}
export async function getProjectInvoices(
- { projectRef, offset, limit }: ProjectInvoicesVariables,
+ { projectRef, offset = 0, limit = 10 }: ProjectInvoicesVariables,
signal?: AbortSignal
) {
if (!projectRef) throw new Error('Project ref is required')
@@ -37,15 +37,12 @@ export const useProjectInvoicesQuery = <TData = ProjectInvoicesData>(
...options
}: UseQueryOptions<ProjectInvoicesData, ProjectInvoicesError, TData> = {}
) =>
+ // [Joshen] Switch to useInfiniteQuery
useQuery<ProjectInvoicesData, ProjectInvoicesError, TData>(
- invoicesKeys.projectInvoices(projectRef),
+ invoicesKeys.projectInvoices(projectRef, offset),
({ signal }) => getProjectInvoices({ projectRef, offset, limit }, signal),
{
- enabled:
- enabled &&
- typeof projectRef !== 'undefined' &&
- typeof limit !== 'undefined' &&
- typeof offset !== 'undefined',
+ enabled: enabled && typeof projectRef !== 'undefined',
...options,
}
)