Skip to content

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

move useProjectSubscription to react-query

Alaister Young3ec6225a9316
diff --git a/studio/__mocks__/data/subscriptions/project-subscription-query.js b/studio/__mocks__/data/subscriptions/project-subscription-query.js
new file mode 100644
index 00000000000..8f95fdbac4e
--- /dev/null
+++ b/studio/__mocks__/data/subscriptions/project-subscription-query.js
@@ -0,0 +1,7 @@
+export const useProjectSubscriptionQuery = jest.fn().mockReturnValue({
+ data: {
+ tier: {
+ supabase_prod_id: 'tier_free',
+ },
+ },
+})
diff --git a/studio/__mocks__/hooks.js b/studio/__mocks__/hooks.js
index e6d89720b13..77e269ed6c9 100644
--- a/studio/__mocks__/hooks.js
+++ b/studio/__mocks__/hooks.js
@@ -1,20 +1,15 @@
export const useFlag = jest.fn().mockReturnValue(true)
export const checkPermissions = jest.fn().mockReturnValue(true)
-export const useProjectSubscription = jest.fn().mockReturnValue({
- subscription: {
- tier: {
- supabase_prod_id: 'tier_free',
- },
- },
-})
const { useStore, StoreProvider } = jest.requireActual('hooks')
export const useStore = useStore
+export const useParams = jest.fn().mockImplementation(() => ({ ref: '123' }))
+
// mocks browser event listener adding/removing
window.matchMedia = jest.fn().mockReturnValue({
removeEventListener: jest.fn(),
})
export const StoreProvider = StoreProvider
-export const withAuth = jest.fn()
\ No newline at end of file
+export const withAuth = jest.fn()
diff --git a/studio/components/interfaces/Billing/Subscription/Subscription.types.ts b/studio/components/interfaces/Billing/Subscription/Subscription.types.ts
index edc54c9b96a..2b5a572a932 100644
--- a/studio/components/interfaces/Billing/Subscription/Subscription.types.ts
+++ b/studio/components/interfaces/Billing/Subscription/Subscription.types.ts
@@ -14,5 +14,5 @@ export interface StripeProduct {
price_id?: string
unit_amount: number
supabase_prod_id: string
- key: string
+ key: 'FREE' | 'PRO' | 'ENTERPRISE'
}
diff --git a/studio/components/interfaces/Database/Backups/PITR/PITRNotice.tsx b/studio/components/interfaces/Database/Backups/PITR/PITRNotice.tsx
index 3f990ba5d75..cd43b19d452 100644
--- a/studio/components/interfaces/Database/Backups/PITR/PITRNotice.tsx
+++ b/studio/components/interfaces/Database/Backups/PITR/PITRNotice.tsx
@@ -1,12 +1,13 @@
import Link from 'next/link'
import { Button, IconCalendar } from 'ui'
import { FormPanel } from 'components/ui/Forms'
-import { useParams, useProjectSubscription } from 'hooks'
+import { useParams } from 'hooks'
+import { useProjectSubscriptionQuery } from 'data/subscriptions/project-subscription-query'
import { getPITRRetentionDuration } from './PITR.utils'
const PITRNotice = ({}) => {
- const { ref } = useParams()
- const { subscription } = useProjectSubscription(ref)
+ const { ref: projectRef } = useParams()
+ const { data: subscription } = useProjectSubscriptionQuery({ projectRef })
const retentionPeriod = getPITRRetentionDuration(subscription?.addons ?? [])
return (
@@ -14,10 +15,10 @@ const PITRNotice = ({}) => {
disabled={true}
footer={
<div className="flex items-center justify-between p-6">
- <span className="text-scale-1000 text-sm">
+ <span className="text-sm text-scale-1000">
You can also increase your recovery retention period updating your PITR add-on
</span>
- <Link href={`/project/${ref}/settings/billing/update/pro`}>
+ <Link href={`/project/${projectRef}/settings/billing/update/pro`}>
<a>
<Button as="span" type="default">
Increase retention period
@@ -27,8 +28,8 @@ const PITRNotice = ({}) => {
</div>
}
>
- <div className="p-6 flex space-x-6">
- <div className="h-10 w-10 rounded flex items-center justify-center bg-scale-700">
+ <div className="flex p-6 space-x-6">
+ <div className="flex items-center justify-center w-10 h-10 rounded bg-scale-700">
<IconCalendar strokeWidth={2} />
</div>
<div className="space-y-2">
diff --git a/studio/components/interfaces/Organization/BillingSettings/ProjectsSummary.tsx b/studio/components/interfaces/Organization/BillingSettings/ProjectsSummary.tsx
index 6c9ca17208d..29cc0b734c8 100644
--- a/studio/components/interfaces/Organization/BillingSettings/ProjectsSummary.tsx
+++ b/studio/components/interfaces/Organization/BillingSettings/ProjectsSummary.tsx
@@ -3,7 +3,8 @@ import dayjs from 'dayjs'
import { FC, useEffect } from 'react'
import { IconChevronRight, IconLoader } from 'ui'
-import { useProjectSubscription, useStore } from 'hooks'
+import { useStore } from 'hooks'
+import { useProjectSubscriptionQuery } from 'data/subscriptions/project-subscription-query'
import Panel from 'components/ui/Panel'
interface ProjectSummaryProps {
@@ -12,7 +13,11 @@ interface ProjectSummaryProps {
const ProjectSummary: FC<ProjectSummaryProps> = ({ project }) => {
const { ui } = useStore()
- const { subscription, isLoading: loading, error } = useProjectSubscription(project.ref)
+ const {
+ data: subscription,
+ isLoading: loading,
+ error,
+ } = useProjectSubscriptionQuery({ projectRef: project.ref })
const currentPeriodStart = subscription?.billing?.current_period_start ?? 0
const currentPeriodEnd = subscription?.billing?.current_period_end ?? 0
@@ -21,13 +26,13 @@ const ProjectSummary: FC<ProjectSummaryProps> = ({ project }) => {
if (error) {
ui.setNotification({
category: 'error',
- message: `Failed to get project subscription: ${error?.message ?? 'unknown'}`,
+ message: `Failed to get project subscription: ${(error as any)?.message ?? 'unknown'}`,
})
}
}, [error])
return (
- <div className="flex w-full items-center px-6 py-3">
+ <div className="flex items-center w-full px-6 py-3">
<div className="w-[25%]">
<p className="text-sm">{project.name}</p>
</div>
@@ -47,8 +52,8 @@ const ProjectSummary: FC<ProjectSummaryProps> = ({ project }) => {
</div>
<div className="flex w-[15%] items-center justify-end">
<Link href={`/project/${project.ref}/settings/billing/subscription`}>
- <a className="group flex items-center space-x-2">
- <p className="text-sm opacity-0 transition group-hover:opacity-100">View details</p>
+ <a className="flex items-center space-x-2 group">
+ <p className="text-sm transition opacity-0 group-hover:opacity-100">View details</p>
<IconChevronRight />
</a>
</Link>
@@ -69,7 +74,7 @@ const ProjectsSummary: FC<ProjectsSummaryProps> = ({ projects }) => {
<h4>Projects at a glance</h4>
<Panel
title={
- <div className="flex w-full items-center">
+ <div className="flex items-center w-full">
<div className="w-[25%]">
<p className="text-sm opacity-50">Name</p>
</div>
diff --git a/studio/components/interfaces/Settings/Logs/LogsPreviewer.tsx b/studio/components/interfaces/Settings/Logs/LogsPreviewer.tsx
index 0eac58199bf..825c7999281 100644
--- a/studio/components/interfaces/Settings/Logs/LogsPreviewer.tsx
+++ b/studio/components/interfaces/Settings/Logs/LogsPreviewer.tsx
@@ -20,10 +20,10 @@ import PreviewFilterPanel from 'components/interfaces/Settings/Logs/PreviewFilte
import { LOGS_TABLES } from './Logs.constants'
import ShimmerLine from 'components/ui/ShimmerLine'
import LoadingOpacity from 'components/ui/LoadingOpacity'
-import { useProjectSubscription } from 'hooks'
import { useUpgradePrompt } from 'hooks/misc/useUpgradePrompt'
-import { StripeProduct } from 'components/interfaces/Billing'
import UpgradePrompt from './UpgradePrompt'
+import { useParams } from 'hooks'
+import { useProjectSubscriptionQuery } from 'data/subscriptions/project-subscription-query'
/**
* Acts as a container component for the entire log display
@@ -50,9 +50,9 @@ export const LogsPreviewer: React.FC<Props> = ({
tableName,
}) => {
const router = useRouter()
- const { s, ite, its, ref } = router.query
+ const { s, ite, its } = useParams()
const [showChart, setShowChart] = useState(true)
- const { subscription } = useProjectSubscription(ref as string)
+ const { data: subscription } = useProjectSubscriptionQuery({ projectRef })
const tier = subscription?.tier
const table = !tableName ? LOGS_TABLES[queryType] : tableName
@@ -152,7 +152,7 @@ export const LogsPreviewer: React.FC<Props> = ({
}
return (
- <div className="flex h-full flex-grow flex-col">
+ <div className="flex flex-col flex-grow h-full">
<PreviewFilterPanel
csvData={logData}
isLoading={isLoading}
@@ -205,7 +205,7 @@ export const LogsPreviewer: React.FC<Props> = ({
)}
</div>
</div>
- <div className="relative flex flex-grow flex-col pt-4">
+ <div className="relative flex flex-col flex-grow pt-4">
<ShimmerLine active={isLoading} />
<LoadingOpacity active={isLoading}>
<LogTable
@@ -224,7 +224,7 @@ export const LogsPreviewer: React.FC<Props> = ({
<Button onClick={loadOlder} icon={<IconRewind />} type="default">
Load older
</Button>
- <div className="mt-2 flex flex-row justify-end">
+ <div className="flex flex-row justify-end mt-2">
<UpgradePrompt show={showUpgradePrompt} setShowUpgradePrompt={setShowUpgradePrompt} />
</div>
</div>
diff --git a/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageMinimal.tsx b/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageMinimal.tsx
index c05a464cf8c..f4f3485e089 100644
--- a/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageMinimal.tsx
+++ b/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageMinimal.tsx
@@ -1,12 +1,12 @@
import { FC } from 'react'
import { Loading } from 'ui'
-import { useProjectSubscription } from 'hooks'
+import { ProjectUsageResponse, useProjectUsageQuery } from 'data/usage/project-usage-query'
+import { useProjectSubscriptionQuery } from 'data/subscriptions/project-subscription-query'
import { formatBytes } from 'lib/helpers'
import { PRICING_TIER_PRODUCT_IDS, USAGE_APPROACHING_THRESHOLD } from 'lib/constants'
import SparkBar from 'components/ui/SparkBar'
import { USAGE_BASED_PRODUCTS } from 'components/interfaces/Billing/Billing.constants'
-import { ProjectUsageResponse, useProjectUsageQuery } from 'data/usage/project-usage-query'
interface ProjectUsageMinimalProps {
projectRef?: string
@@ -17,7 +17,9 @@ interface ProjectUsageMinimalProps {
const ProjectUsageMinimal: FC<ProjectUsageMinimalProps> = ({ projectRef, filter }) => {
const { data: usage, error: usageError, isLoading } = useProjectUsageQuery({ projectRef })
- const { subscription, error: subscriptionError } = useProjectSubscription(projectRef)
+ const { data: subscription, error: subscriptionError } = useProjectSubscriptionQuery({
+ projectRef,
+ })
if (
subscription?.tier?.supabase_prod_id === PRICING_TIER_PRODUCT_IDS.PAYG ||
diff --git a/studio/data/subscriptions/keys.ts b/studio/data/subscriptions/keys.ts
new file mode 100644
index 00000000000..2b695295cc7
--- /dev/null
+++ b/studio/data/subscriptions/keys.ts
@@ -0,0 +1,4 @@
+export const subscriptionKeys = {
+ subscription: (projectRef: string | undefined) =>
+ ['projects', projectRef, 'subscription'] as const,
+}
diff --git a/studio/data/subscriptions/project-subscription-query.ts b/studio/data/subscriptions/project-subscription-query.ts
new file mode 100644
index 00000000000..8a3365dc9f9
--- /dev/null
+++ b/studio/data/subscriptions/project-subscription-query.ts
@@ -0,0 +1,61 @@
+import { useQuery, useQueryClient, UseQueryOptions } from '@tanstack/react-query'
+import { StripeSubscription } from 'components/interfaces/Billing'
+import { get } from 'lib/common/fetch'
+import { API_URL } from 'lib/constants'
+import { useCallback } from 'react'
+import { subscriptionKeys } from './keys'
+
+export type ProjectSubscriptionVariables = {
+ projectRef?: string
+}
+
+export type ProjectSubscriptionResponse = StripeSubscription
+
+export async function getProjectSubscription(
+ { projectRef }: ProjectSubscriptionVariables,
+ signal?: AbortSignal
+) {
+ if (!projectRef) {
+ throw new Error('projectRef is required')
+ }
+
+ const response = await get(`${API_URL}/projects/${projectRef}/subscription`, {
+ signal,
+ })
+ if (response.error) {
+ throw response.error
+ }
+
+ return response as ProjectSubscriptionResponse
+}
+
+export type ProjectSubscriptionData = Awaited<ReturnType<typeof getProjectSubscription>>
+export type ProjectSubscriptionError = unknown
+
+export const useProjectSubscriptionQuery = <TData = ProjectSubscriptionData>(
+ { projectRef }: ProjectSubscriptionVariables,
+ {
+ enabled = true,
+ ...options
+ }: UseQueryOptions<ProjectSubscriptionData, ProjectSubscriptionError, TData> = {}
+) =>
+ useQuery<ProjectSubscriptionData, ProjectSubscriptionError, TData>(
+ subscriptionKeys.subscription(projectRef),
+ ({ signal }) => getProjectSubscription({ projectRef }, signal),
+ {
+ enabled: enabled && typeof projectRef !== 'undefined',
+ ...options,
+ }
+ )
+
+export const useProjectSubscriptionPrefetch = ({ projectRef }: ProjectSubscriptionVariables) => {
+ const client = useQueryClient()
+
+ return useCallback(() => {
+ if (projectRef) {
+ client.prefetchQuery(subscriptionKeys.subscription(projectRef), ({ signal }) =>
+ getProjectSubscription({ projectRef }, signal)
+ )
+ }
+ }, [projectRef])
+}
diff --git a/studio/hooks/index.ts b/studio/hooks/index.ts
index 315397b39e5..9171556da97 100644
--- a/studio/hooks/index.ts
+++ b/studio/hooks/index.ts
@@ -6,5 +6,4 @@ export * from './misc/usePlatformStatus'
export * from './misc/useParams'
export * from './misc/useCheckPermissions'
export * from './deprecated'
-export * from './queries'
export * from './ui'
diff --git a/studio/hooks/misc/useProjectSubscription.tsx b/studio/hooks/misc/useProjectSubscription.tsx
deleted file mode 100644
index beb32f9ab71..00000000000
--- a/studio/hooks/misc/useProjectSubscription.tsx
+++ /dev/null
@@ -1,36 +0,0 @@
-import { get } from 'lib/common/fetch'
-import { API_URL } from 'lib/constants'
-import useSWR from 'swr'
-
-export interface Tier {
- name: string
- prod_id: string
- key: 'FREE' | 'PRO' | 'PAYG'
- unit_amount: number
-}
-interface Data {
- tier: Tier
- addons: any[]
- billing: {
- billing_cycle_anchor: number
- current_period_end: number
- current_period_start: number
- }
-}
-
-interface Handlers {
- refresh: () => void
-}
-
-const useProjectSubscription = (projectRef: string): [Data | null, Handlers] => {
- const { data, error, mutate } = useSWR<Data>(
- projectRef ? `${API_URL}/projects/${projectRef}/subscription` : null,
- get
- )
- const refresh = () => mutate()
- if (!data) return [null, { refresh }]
- if (error) return [null, { refresh }]
- return [data, { refresh }]
-}
-
-export default useProjectSubscription
diff --git a/studio/hooks/misc/useUpgradePrompt.tsx b/studio/hooks/misc/useUpgradePrompt.tsx
index 71aa956ca23..f19f090c302 100644
--- a/studio/hooks/misc/useUpgradePrompt.tsx
+++ b/studio/hooks/misc/useUpgradePrompt.tsx
@@ -1,13 +1,11 @@
import { useEffect, useState } from 'react'
-import { useProjectSubscription } from 'hooks'
-import { useRouter } from 'next/router'
+import { useParams } from 'hooks'
import { maybeShowUpgradePrompt } from 'components/interfaces/Settings/Logs'
-import { StripeProduct } from 'components/interfaces/Billing'
+import { useProjectSubscriptionQuery } from 'data/subscriptions/project-subscription-query'
export const useUpgradePrompt = (from: string) => {
- const router = useRouter()
- const { ref } = router.query
- const { subscription } = useProjectSubscription(ref as string)
+ const { ref: projectRef } = useParams()
+ const { data: subscription } = useProjectSubscriptionQuery({ projectRef })
const tier = subscription?.tier
const [showUpgradePrompt, setShowUpgradePrompt] = useState(false)
diff --git a/studio/hooks/queries/index.ts b/studio/hooks/queries/index.ts
deleted file mode 100644
index a81712a02cf..00000000000
--- a/studio/hooks/queries/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from './useProjectSubscription'
diff --git a/studio/hooks/queries/useProjectSubscription.ts b/studio/hooks/queries/useProjectSubscription.ts
deleted file mode 100644
index 48fcb2368a4..00000000000
--- a/studio/hooks/queries/useProjectSubscription.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-import useSWR from 'swr'
-import { get } from 'lib/common/fetch'
-import { API_URL } from 'lib/constants'
-import { StripeSubscription } from 'components/interfaces/Billing'
-
-/**
- * Get project payg statistics
- *
- * todo: this looks like a duplicate
- * of /studio/hooks/misc/useProjectSubscription.tsx
- *
- * @param ref project reference
- */
-export function useProjectSubscription(ref: string | undefined) {
- const url = `${API_URL}/projects/${ref}/subscription`
- const { data, error } = useSWR<StripeSubscription & { error?: string }>(url, get)
- const anyError = data?.error || error
-
- return {
- subscription: anyError ? null : (data as StripeSubscription),
- error: anyError,
- isLoading: !anyError && !data,
- isError: !!anyError,
- }
-}
diff --git a/studio/pages/project/[ref]/logs/explorer/index.tsx b/studio/pages/project/[ref]/logs/explorer/index.tsx
index f166123a6f8..16bb227432c 100644
--- a/studio/pages/project/[ref]/logs/explorer/index.tsx
+++ b/studio/pages/project/[ref]/logs/explorer/index.tsx
@@ -5,8 +5,9 @@ import { useRouter } from 'next/router'
import { observer } from 'mobx-react-lite'
import { Input, Modal, Form, Button } from 'ui'
-import { useProjectSubscription, useStore } from 'hooks'
+import { useParams, useStore } from 'hooks'
import useLogsQuery from 'hooks/analytics/useLogsQuery'
+import { useProjectSubscriptionQuery } from 'data/subscriptions/project-subscription-query'
import { NextPageWithLayout, UserContent } from 'types'
import { uuidv4 } from 'lib/helpers'
import { LogsLayout } from 'components/layouts'
@@ -30,17 +31,17 @@ import LogsExplorerHeader from 'components/ui/Logs/LogsExplorerHeader'
export const LogsExplorerPage: NextPageWithLayout = () => {
const router = useRouter()
- const { ref, q, ite, its } = router.query
+ const { ref: projectRef, q, ite, its } = useParams()
const [editorId, setEditorId] = useState<string>(uuidv4())
const [editorValue, setEditorValue] = useState<string>('')
const [saveModalOpen, setSaveModalOpen] = useState<boolean>(false)
const [warnings, setWarnings] = useState<LogsWarning[]>([])
const { content } = useStore()
- const { subscription } = useProjectSubscription(ref as string)
+ const { data: subscription } = useProjectSubscriptionQuery({ projectRef })
const tier = subscription?.tier
const [{ params, logData, error, isLoading }, { changeQuery, runQuery, setParams }] =
- useLogsQuery(ref as string, {
+ useLogsQuery(projectRef as string, {
iso_timestamp_start: its ? (its as string) : undefined,
iso_timestamp_end: ite ? (ite as string) : undefined,
})
@@ -147,11 +148,11 @@ export const LogsExplorerPage: NextPageWithLayout = () => {
}
return (
- <div className="mx-auto w-full px-5 py-6 h-full">
+ <div className="w-full h-full px-5 py-6 mx-auto">
<LogsExplorerHeader />
- <div className="flex h-full flex-grow flex-col gap-4">
- <div className="rounded border">
+ <div className="flex flex-col flex-grow h-full gap-4">
+ <div className="border rounded">
<LogsQueryPanel
defaultFrom={params.iso_timestamp_start || ''}
defaultTo={params.iso_timestamp_end || ''}
@@ -177,13 +178,18 @@ export const LogsExplorerPage: NextPageWithLayout = () => {
/>
</div>
</div>
- <div className="relative flex flex-grow flex-col">
+ <div className="relative flex flex-col flex-grow">
<LoadingOpacity active={isLoading}>
- <div className="flex h-full flex-grow">
- <LogTable params={params} data={logData} error={error} projectRef={ref as string} />
+ <div className="flex flex-grow h-full">
+ <LogTable
+ params={params}
+ data={logData}
+ error={error}
+ projectRef={projectRef as string}
+ />
</div>
</LoadingOpacity>
- <div className="mt-2 flex flex-row justify-end">
+ <div className="flex flex-row justify-end mt-2">
<UpgradePrompt show={showUpgradePrompt} setShowUpgradePrompt={setShowUpgradePrompt} />
</div>
</div>
@@ -248,7 +254,7 @@ export const LogsExplorerPage: NextPageWithLayout = () => {
</div>
</Modal.Content>
</div>
- <div className="border-t bg-scale-300 py-3">
+ <div className="py-3 border-t bg-scale-300">
<Modal.Content>
<div className="flex items-center justify-end gap-2">
<Button
diff --git a/studio/pages/project/[ref]/settings/billing/invoices.tsx b/studio/pages/project/[ref]/settings/billing/invoices.tsx
index 45481e4ff1b..dde1131615c 100644
--- a/studio/pages/project/[ref]/settings/billing/invoices.tsx
+++ b/studio/pages/project/[ref]/settings/billing/invoices.tsx
@@ -4,7 +4,8 @@ import { FC, useEffect } from 'react'
import { SettingsLayout } from 'components/layouts'
import LoadingUI from 'components/ui/Loading'
import OveragesBanner from 'components/ui/OveragesBanner/OveragesBanner'
-import { useProjectSubscription, useStore } from 'hooks'
+import { useStore } from 'hooks'
+import { useProjectSubscriptionQuery } from 'data/subscriptions/project-subscription-query'
import { NextPageWithLayout, Project } from 'types'
import { Invoices } from 'components/interfaces/Billing'
@@ -14,8 +15,8 @@ const ProjectBilling: NextPageWithLayout = () => {
const project = ui.selectedProject
return (
- <div className="content h-full w-full overflow-y-auto">
- <div className="mx-auto w-full">
+ <div className="w-full h-full overflow-y-auto content">
+ <div className="w-full mx-auto">
<Settings project={project} />
</div>
</div>
@@ -36,17 +37,15 @@ const Settings: FC<SettingsProps> = ({ project }) => {
const { ui } = useStore()
const projectTier = ui.selectedProject?.subscription_tier
- const {
- subscription,
- isLoading: loading,
- error,
- } = useProjectSubscription(ui.selectedProject?.ref)
+ const { data: subscription, error } = useProjectSubscriptionQuery({
+ projectRef: ui.selectedProject?.ref,
+ })
useEffect(() => {
if (error) {
ui.setNotification({
category: 'error',
- message: `Failed to get project subscription: ${error?.message ?? 'unknown'}`,
+ message: `Failed to get project subscription: ${(error as any)?.message ?? 'unknown'}`,
})
}
}, [error])
@@ -56,7 +55,7 @@ const Settings: FC<SettingsProps> = ({ project }) => {
}
return (
- <div className="container max-w-4xl space-y-8 p-4">
+ <div className="container max-w-4xl p-4 space-y-8">
{/* [Joshen TODO] Temporarily hidden until usage endpoint is sorted out */}
{/* {projectTier !== undefined && <OveragesBanner tier={projectTier} />} */}
diff --git a/studio/pages/project/[ref]/settings/billing/subscription.tsx b/studio/pages/project/[ref]/settings/billing/subscription.tsx
index 9744f34e911..750af452736 100644
--- a/studio/pages/project/[ref]/settings/billing/subscription.tsx
+++ b/studio/pages/project/[ref]/settings/billing/subscription.tsx
@@ -5,7 +5,8 @@ import { Loading } from 'ui'
import { SettingsLayout } from 'components/layouts'
import LoadingUI from 'components/ui/Loading'
import OveragesBanner from 'components/ui/OveragesBanner/OveragesBanner'
-import { useProjectSubscription, useStore } from 'hooks'
+import { useStore } from 'hooks'
+import { useProjectSubscriptionQuery } from 'data/subscriptions/project-subscription-query'
import { NextPageWithLayout, Project } from 'types'
import { Subscription } from 'components/interfaces/Billing'
@@ -15,8 +16,8 @@ const ProjectBilling: NextPageWithLayout = () => {
const project = ui.selectedProject
return (
- <div className="content h-full w-full overflow-y-auto">
- <div className="mx-auto w-full">
+ <div className="w-full h-full overflow-y-auto content">
+ <div className="w-full mx-auto">
<Settings project={project} />
</div>
</div>
@@ -38,16 +39,16 @@ const Settings: FC<SettingsProps> = ({ project }) => {
const projectTier = ui.selectedProject?.subscription_tier
const {
- subscription,
+ data: subscription,
isLoading: loading,
error,
- } = useProjectSubscription(ui.selectedProject?.ref)
+ } = useProjectSubscriptionQuery({ projectRef: ui.selectedProject?.ref })
useEffect(() => {
if (error) {
ui.setNotification({
category: 'error',
- message: `Failed to get project subscription: ${error?.message ?? 'unknown'}`,
+ message: `Failed to get project subscription: ${(error as any)?.message ?? 'unknown'}`,
})
}
}, [error])
@@ -57,7 +58,7 @@ const Settings: FC<SettingsProps> = ({ project }) => {
}
return (
- <div className="container max-w-4xl space-y-8 p-4">
+ <div className="container max-w-4xl p-4 space-y-8">
{/* [Joshen TODO] Temporarily hidden until usage endpoint is sorted out */}
{/* {projectTier !== undefined && <OveragesBanner tier={projectTier} />} */}
<Subscription
@@ -69,8 +70,8 @@ const Settings: FC<SettingsProps> = ({ project }) => {
/>
{loading ? (
<Loading active={loading}>
- <div className="mb-8 w-full overflow-hidden rounded border border-panel-border-light dark:border-panel-border-dark">
- <div className="flex items-center justify-center bg-panel-body-light px-6 py-6 dark:bg-panel-body-dark">
+ <div className="w-full mb-8 overflow-hidden border rounded border-panel-border-light dark:border-panel-border-dark">
+ <div className="flex items-center justify-center px-6 py-6 bg-panel-body-light dark:bg-panel-body-dark">
<p>Loading usage breakdown</p>
</div>
</div>
diff --git a/studio/pages/project/[ref]/settings/billing/usage.tsx b/studio/pages/project/[ref]/settings/billing/usage.tsx
index a2b434ca228..676a784d041 100644
--- a/studio/pages/project/[ref]/settings/billing/usage.tsx
+++ b/studio/pages/project/[ref]/settings/billing/usage.tsx
@@ -4,7 +4,8 @@ import { FC, useEffect, useState } from 'react'
import { IconArrowRight, Loading } from 'ui'
import { Project, NextPageWithLayout } from 'types'
-import { useProjectSubscription, useStore } from 'hooks'
+import { useStore } from 'hooks'
+import { useProjectSubscriptionQuery } from 'data/subscriptions/project-subscription-query'
import { STRIPE_PRODUCT_IDS, TIME_PERIODS_REPORTS, TIME_PERIODS_BILLING } from 'lib/constants'
import { SettingsLayout } from 'components/layouts'
import LoadingUI from 'components/ui/Loading'
@@ -17,8 +18,8 @@ const ProjectBillingUsage: NextPageWithLayout = () => {
const project = ui.selectedProject
return (
- <div className="content h-full w-full overflow-y-auto">
- <div className="mx-auto w-full">
+ <div className="w-full h-full overflow-y-auto content">
+ <div className="w-full mx-auto">
<Settings project={project} />
</div>
</div>
@@ -39,10 +40,10 @@ const Settings: FC<SettingsProps> = ({ project }) => {
const { ui } = useStore()
const {
- subscription,
+ data: subscription,
isLoading: loading,
error,
- } = useProjectSubscription(ui.selectedProject?.ref)
+ } = useProjectSubscriptionQuery({ projectRef: ui.selectedProject?.ref })
const [dateRange, setDateRange] = useState<any>()
const isPayg = subscription?.tier?.prod_id === STRIPE_PRODUCT_IDS.PAYG
@@ -51,7 +52,7 @@ const Settings: FC<SettingsProps> = ({ project }) => {
if (error) {
ui.setNotification({
category: 'error',
- message: `Failed to get project subscription: ${error?.message ?? 'unknown'}`,
+ message: `Failed to get project subscription: ${(error as any)?.message ?? 'unknown'}`,
})
}
}, [error])
@@ -61,18 +62,18 @@ const Settings: FC<SettingsProps> = ({ project }) => {
}
return (
- <div className="container max-w-4xl space-y-8 p-4">
+ <div className="container max-w-4xl p-4 space-y-8">
{loading ? (
<Loading active={loading}>
- <div className="mb-8 w-full overflow-hidden rounded border border-panel-border-light dark:border-panel-border-dark">
- <div className="flex items-center justify-center bg-panel-body-light px-6 py-6 dark:bg-panel-body-dark">
+ <div className="w-full mb-8 overflow-hidden border rounded border-panel-border-light dark:border-panel-border-dark">
+ <div className="flex items-center justify-center px-6 py-6 bg-panel-body-light dark:bg-panel-body-dark">
<p>Loading usage breakdown</p>
</div>
</div>
</Loading>
) : isPayg ? (
<div>
- <div className="mb-4 flex items-center space-x-3">
+ <div className="flex items-center mb-4 space-x-3">
<DateRangePicker
onChange={setDateRange}
value={TIME_PERIODS_BILLING[0].key}
diff --git a/studio/tests/components/Home/ProjectUsage.test.js b/studio/tests/components/Home/ProjectUsage.test.js
index fd522e145df..fe283b983c9 100644
--- a/studio/tests/components/Home/ProjectUsage.test.js
+++ b/studio/tests/components/Home/ProjectUsage.test.js
@@ -28,10 +28,12 @@ jest.mock('components/ui/Flag/Flag')
import Flag from 'components/ui/Flag/Flag'
Flag.mockImplementation(({ children }) => <>{children}</>)
jest.mock('hooks')
-import { useFlag, useProjectSubscription } from 'hooks'
+import { useFlag } from 'hooks'
+jest.mock('data/subscriptions/project-subscription-query')
+import { useProjectSubscriptionQuery } from 'data/subscriptions/project-subscription-query'
useFlag.mockReturnValue(true)
-useProjectSubscription.mockReturnValue({
- subscription: undefined,
+useProjectSubscriptionQuery.mockReturnValue({
+ data: undefined,
})
beforeEach(() => {
diff --git a/studio/tests/pages/projects/LogsPreviewer.test.js b/studio/tests/pages/projects/LogsPreviewer.test.js
index 0b8420e9c14..c382c14a241 100644
--- a/studio/tests/pages/projects/LogsPreviewer.test.js
+++ b/studio/tests/pages/projects/LogsPreviewer.test.js
@@ -16,7 +16,7 @@ const defaultRouterMock = () => {
useRouter.mockReturnValue(defaultRouterMock())
import LogsPreviewer from 'components/interfaces/Settings/Logs/LogsPreviewer'
-import { useProjectSubscription } from 'hooks'
+import { useProjectSubscriptionQuery } from 'data/subscriptions/project-subscription-query'
import { fireEvent, waitFor, screen, act } from '@testing-library/react'
import { render } from '../../helpers'
import userEvent from '@testing-library/user-event'
@@ -423,8 +423,8 @@ test('filters accept filterOverride', async () => {
describe.each(['FREE', 'PRO', 'ENTERPRISE'])('upgrade modal for %s', (key) => {
beforeEach(() => {
- useProjectSubscription.mockReturnValue({
- subscription: {
+ useProjectSubscriptionQuery.mockReturnValue({
+ data: {
tier: {
supabase_prod_id: `tier_${key.toLocaleLowerCase()}`,
key,
diff --git a/studio/tests/pages/projects/logs-query.test.js b/studio/tests/pages/projects/logs-query.test.js
index 3ae3b637d34..fc3cb203ab7 100644
--- a/studio/tests/pages/projects/logs-query.test.js
+++ b/studio/tests/pages/projects/logs-query.test.js
@@ -7,7 +7,7 @@ import userEvent from '@testing-library/user-event'
import { logDataFixture } from '../../fixtures'
import { clickDropdown } from 'tests/helpers'
import dayjs from 'dayjs'
-import { useProjectSubscription } from 'hooks'
+import { useProjectSubscriptionQuery } from 'data/subscriptions/project-subscription-query'
const defaultRouterMock = () => {
const router = jest.fn()
@@ -153,8 +153,8 @@ test('query warnings', async () => {
describe.each(['FREE', 'PRO', 'ENTERPRISE'])('upgrade modal for %s', (key) => {
beforeEach(() => {
- useProjectSubscription.mockReturnValue({
- subscription: {
+ useProjectSubscriptionQuery.mockReturnValue({
+ data: {
tier: {
supabase_prod_id: `tier_${key.toLocaleLowerCase()}`,
key,