Skip to content

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

First iteration

Joshen Lima061b22b4f58
diff --git a/studio/components/interfaces/Home/OveragesBanner.tsx b/studio/components/interfaces/Home/OveragesBanner.tsx
new file mode 100644
index 00000000000..6eaf13113ef
--- /dev/null
+++ b/studio/components/interfaces/Home/OveragesBanner.tsx
@@ -0,0 +1,83 @@
+import Link from 'next/link'
+import { FC } from 'react'
+import { Alert } from '@supabase/ui'
+
+import { useStore } from 'hooks'
+import { PRICING_TIER_PRODUCT_IDS } from 'lib/constants'
+
+interface Props {
+ tier: string
+ usageStatus: any
+}
+
+const OveragesBanner: FC<Props> = ({ tier, usageStatus }) => {
+ const { ui } = useStore()
+ const ref = ui.selectedProject?.ref
+
+ // [Joshen TODO] After API is ready, to do up proper logic here
+ // Left off here - to do the banner on the billing page etc as well
+ const isApproachingUsageLimits = false
+ const isOverUsageLimits = false
+
+ if (tier === PRICING_TIER_PRODUCT_IDS.ENTERPRISE) return <></>
+
+ const tierName =
+ tier === PRICING_TIER_PRODUCT_IDS.FREE
+ ? 'free'
+ : tier === PRICING_TIER_PRODUCT_IDS.PRO
+ ? 'pro'
+ : tier === PRICING_TIER_PRODUCT_IDS.PAYG
+ ? 'pro'
+ : ''
+
+ // [Joshen TODO] Rors mentioned to keep the language here positive if possible
+ const description =
+ tier === PRICING_TIER_PRODUCT_IDS.FREE ? (
+ <>
+ You can check your project's usage details or upgrade to the pro tier{' '}
+ <Link href={`/project/${ref}/settings/billing`}>
+ <a>
+ <span className="cursor-pointer underline">here</span>
+ </a>
+ </Link>{' '}
+ to support the growth of your project.
+ </>
+ ) : tier === PRICING_TIER_PRODUCT_IDS.PRO ? (
+ <>
+ You can check your project's usage details or consider disabling spend cap{' '}
+ <Link href={`/project/${ref}/settings/billing`}>
+ <a>
+ <span className="cursor-pointer underline">here</span>
+ </a>
+ </Link>{' '}
+ to support the growth of your project.
+ </>
+ ) : tier === PRICING_TIER_PRODUCT_IDS.PAYG ? (
+ <>
+ As you have disabled spend cap, additional resources will be charged on a per-usage basis.
+ You can check your project's usage details{' '}
+ <Link href={`/project/${ref}/settings/billing`}>
+ <a>
+ <span className="cursor-pointer underline">here</span>
+ </a>
+ </Link>{' '}
+ for more information.
+ </>
+ ) : (
+ ''
+ )
+
+ return (
+ <div className="max-w-7xl mx-6">
+ <Alert
+ withIcon
+ variant={tier === PRICING_TIER_PRODUCT_IDS.PAYG ? 'neutral' : 'warning'}
+ title={`Your project is approaching it's usage limits for the ${tierName} tier.`}
+ >
+ {description}
+ </Alert>
+ </div>
+ )
+}
+
+export default OveragesBanner
diff --git a/studio/components/interfaces/Home/index.ts b/studio/components/interfaces/Home/index.ts
index e62885bb727..d4ea93b957c 100644
--- a/studio/components/interfaces/Home/index.ts
+++ b/studio/components/interfaces/Home/index.ts
@@ -2,5 +2,6 @@ import ClientLibrary from './ClientLibrary'
import ExampleProject from './ExampleProject'
import ProjectUsage from './ProjectUsage'
import NewProjectPanel from './NewProjectPanel/NewProjectPanel'
+import OveragesBanner from './OveragesBanner'
-export { ClientLibrary, ExampleProject, ProjectUsage, NewProjectPanel }
+export { ClientLibrary, ExampleProject, ProjectUsage, NewProjectPanel, OveragesBanner }
diff --git a/studio/hooks/queries/index.ts b/studio/hooks/queries/index.ts
index d4a6f35db2f..538ce64e6fb 100644
--- a/studio/hooks/queries/index.ts
+++ b/studio/hooks/queries/index.ts
@@ -8,3 +8,4 @@ export * from './useProjectPaygStatistics'
export * from './useProjectSettings'
export * from './useProjectSubscription'
export * from './useSubscriptionStats'
+export * from './useProjectUsageStatus'
diff --git a/studio/hooks/queries/useProjectUsageStatus.ts b/studio/hooks/queries/useProjectUsageStatus.ts
index 1d235271b86..13a902e41fd 100644
--- a/studio/hooks/queries/useProjectUsageStatus.ts
+++ b/studio/hooks/queries/useProjectUsageStatus.ts
@@ -2,13 +2,13 @@ import useSWR from 'swr'
import { get } from 'lib/common/fetch'
import { API_URL } from 'lib/constants'
-export function useProjectUsageStatus(ref: string) {
+export function useProjectUsageStatus(ref?: string) {
const url = `${API_URL}/projects/${ref}/usage-status`
- const { data, error } = useSWR<any>(url, get)
+ const { data, error } = useSWR<any>(ref ? url : null, get)
const anyError = data?.error || error
return {
- config: anyError ? undefined : data,
+ usageStatus: anyError ? undefined : data,
error: anyError,
isLoading: !anyError && !data,
isError: !!anyError,
diff --git a/studio/pages/project/[ref]/index.tsx b/studio/pages/project/[ref]/index.tsx
index b62411ce8c8..d996ff6bf87 100644
--- a/studio/pages/project/[ref]/index.tsx
+++ b/studio/pages/project/[ref]/index.tsx
@@ -1,7 +1,7 @@
import { observer } from 'mobx-react-lite'
import { Typography } from '@supabase/ui'
-import { useStore } from 'hooks'
+import { useStore, useProjectUsageStatus } from 'hooks'
import { NextPageWithLayout } from 'types'
import { IS_PLATFORM, PROJECT_STATUS } from 'lib/constants'
import { ProjectLayoutWithAuth } from 'components/layouts'
@@ -9,10 +9,14 @@ import { ExampleProject, ClientLibrary } from 'components/interfaces/Home'
import { CLIENT_LIBRARIES, EXAMPLE_PROJECTS } from 'components/interfaces/Home/Home.constants'
import ProjectUsageSection from 'components/interfaces/Home/ProjectUsageSection'
import ProjectPausedState from 'components/layouts/ProjectLayout/ProjectPausedState'
+import { OveragesBanner } from '../../../components/interfaces/Home'
const Home: NextPageWithLayout = () => {
const { ui } = useStore()
+
const project = ui.selectedProject
+ const projectTier = ui.selectedProject?.subscription_tier
+ const { usageStatus } = useProjectUsageStatus(project?.ref)
const projectName =
project?.ref !== 'default' && project?.name !== undefined
@@ -25,6 +29,11 @@ const Home: NextPageWithLayout = () => {
<h1 className="text-3xl">{projectName}</h1>
</div>
+ {/* [Joshen TODO] pass projectTier into tier and just keep one */}
+ {projectTier !== undefined && <OveragesBanner tier={'tier_free'} usageStatus={usageStatus} />}
+ {projectTier !== undefined && <OveragesBanner tier={'tier_pro'} usageStatus={usageStatus} />}
+ {projectTier !== undefined && <OveragesBanner tier={'tier_payg'} usageStatus={usageStatus} />}
+
{project?.status === PROJECT_STATUS.INACTIVE && <ProjectPausedState project={project} />}
{IS_PLATFORM && project?.status !== PROJECT_STATUS.INACTIVE && <ProjectUsageSection />}