Skip to content

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

chore: automatically redirect org usage

Kevin Grüneberg7e389e1cca4d
diff --git a/studio/pages/project/[ref]/settings/billing/usage.tsx b/studio/pages/project/[ref]/settings/billing/usage.tsx
index 2332a1f371f..89302b719cc 100644
--- a/studio/pages/project/[ref]/settings/billing/usage.tsx
+++ b/studio/pages/project/[ref]/settings/billing/usage.tsx
@@ -1,33 +1,34 @@
-import Link from 'next/link'
-
import Usage from 'components/interfaces/BillingV2/Usage/Usage'
import { SettingsLayout } from 'components/layouts'
import { useSelectedOrganization } from 'hooks'
import { NextPageWithLayout } from 'types'
-import { Alert } from 'ui'
import { useParams } from 'common'
+import { useEffect } from 'react'
+import { useRouter } from 'next/router'
const ProjectBillingUsage: NextPageWithLayout = () => {
const { ref } = useParams()
const organization = useSelectedOrganization()
const isOrgBilling = !!organization?.subscription_id
+ const router = useRouter()
+ const hash = router.asPath.split('#')[1]
+
+ useEffect(() => {
+ if (ref && isOrgBilling && organization) {
+ let redirectUri = `/org/${organization.slug}/usage?projectRef=${ref}`
+
+ if (['cpu', 'ram', 'disk_io'].includes(hash)) {
+ redirectUri = `/project/${ref}/settings/infrastructure#${hash}`
+ } else if (hash && hash.length > 0) {
+ redirectUri = redirectUri + `#${hash}`
+ }
+
+ router.push(redirectUri)
+ }
+ }, [organization, isOrgBilling, ref, hash])
if (isOrgBilling) {
- return (
- <div className="p-4">
- <Alert
- withIcon
- variant="info"
- title="This page is only available for projects which are on their own subscription"
- >
- Project usage statistics have been shifted to the{' '}
- <Link href={`/org/${organization?.slug}/usage?projectRef=${ref}`}>
- <a className="text-brand-900">organization's usage</a>
- </Link>{' '}
- page instead.
- </Alert>
- </div>
- )
+ return null
}
return <Usage />