Skip to content

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

chore: improve redirects for org-level-billing

Kevin Grüneberge3ee24a937ae
diff --git a/studio/components/interfaces/BillingV2/Subscription/Subscription.tsx b/studio/components/interfaces/BillingV2/Subscription/Subscription.tsx
index b228c80fcee..d0c42f0c4ab 100644
--- a/studio/components/interfaces/BillingV2/Subscription/Subscription.tsx
+++ b/studio/components/interfaces/BillingV2/Subscription/Subscription.tsx
@@ -5,7 +5,6 @@ import CostControl from './CostControl/CostControl'
import SubscriptionTier from './Tier/SubscriptionTier'
import { SUBSCRIPTION_PANEL_KEYS, useSubscriptionPageStateSnapshot } from 'state/subscription-page'
import { useSelectedOrganization } from 'hooks'
-import { useEffect } from 'react'
export interface SubscriptionProps {}
@@ -24,41 +23,13 @@ const Subscription = ({}: SubscriptionProps) => {
const panel = router.query.panel
const isOrgBilling = !!organization?.subscription_id
- useEffect(() => {
- if (isOrgBilling) {
- const { ref, panel } = router.query
- let redirectUri = `/org/${organization.slug}/billing`
- switch (panel) {
- case 'subscriptionPlan':
- redirectUri = `/org/${organization.slug}/billing?panel=subscriptionPlan`
- break
- case 'costControl':
- redirectUri = `/org/${organization.slug}/billing?panel=costControl`
- break
- case 'computeInstance':
- redirectUri = `/project/${ref}/settings/addons?panel=computeInstance`
- break
- case 'pitr':
- redirectUri = `/project/${ref}/settings/addons?panel=pitr`
- break
- case 'customDomain':
- redirectUri = `/project/${ref}/settings/addons?panel=customDomain`
- break
- }
-
- router.push(redirectUri)
- }
- }, [router, organization?.slug, isOrgBilling])
-
- useEffect(() => {
- if (panel && typeof panel === 'string' && allowedValues.includes(panel)) {
- snap.setPanelKey(panel as SUBSCRIPTION_PANEL_KEYS)
- }
- }, [panel])
-
// No need to bother rendering, we'll redirect anyway
if (isOrgBilling) return null
+ if (panel && typeof panel === 'string' && allowedValues.includes(panel)) {
+ snap.setPanelKey(panel as SUBSCRIPTION_PANEL_KEYS)
+ }
+
return (
<>
<div className="border-b">
diff --git a/studio/components/interfaces/Database/Backups/BackupsList.tsx b/studio/components/interfaces/Database/Backups/BackupsList.tsx
index fd379d00293..4bf28b80dee 100644
--- a/studio/components/interfaces/Database/Backups/BackupsList.tsx
+++ b/studio/components/interfaces/Database/Backups/BackupsList.tsx
@@ -36,6 +36,7 @@ const BackupsList = () => {
primaryText="Free Plan does not include project backups."
projectRef={projectRef}
secondaryText="Upgrade to the Pro plan for up to 7 days of scheduled backups."
+ addon="pitr"
/>
)
}
diff --git a/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainConfig.tsx b/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainConfig.tsx
index abb91c8a96e..d2e68280594 100644
--- a/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainConfig.tsx
+++ b/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainConfig.tsx
@@ -69,6 +69,7 @@ const CustomDomainConfig = () => {
? 'To configure a custom domain for your project, please upgrade to the Pro plan with the custom domains add-on selected'
: 'To configure a custom domain for your project, please enable the add-on'
}
+ addon="customDomain"
/>
) : (
<Panel>
diff --git a/studio/components/ui/UpgradeToPro.tsx b/studio/components/ui/UpgradeToPro.tsx
index 9c36fb4b2cf..3436f9cc8a2 100644
--- a/studio/components/ui/UpgradeToPro.tsx
+++ b/studio/components/ui/UpgradeToPro.tsx
@@ -12,9 +12,10 @@ interface Props {
primaryText: string
projectRef: string
secondaryText: string
+ addon?: 'pitr' | 'customDomain' | 'computeInstance'
}
-const UpgradeToPro: FC<Props> = ({ icon, primaryText, projectRef, secondaryText }) => {
+const UpgradeToPro: FC<Props> = ({ icon, primaryText, projectRef, secondaryText, addon }) => {
const { data: subscription } = useProjectSubscriptionV2Query({ projectRef })
const plan = subscription?.plan?.id
@@ -45,8 +46,8 @@ const UpgradeToPro: FC<Props> = ({ icon, primaryText, projectRef, secondaryText
<Tooltip.Trigger>
<Button type="primary" disabled={!canUpdateSubscription || projectUpdateDisabled}>
<Link
- href={`/project/${projectRef}/settings/billing/subscription${
- plan === 'free' ? '?panel=subscriptionPlan' : ''
+ href={`/project/${projectRef}/settings/billing/subscription?panel=${
+ plan === 'free' ? 'subscriptionPlan' : addon || 'subscriptionPlan'
}`}
>
<a>{plan === 'free' ? 'Upgrade to Pro' : 'Enable Addon'}</a>
diff --git a/studio/pages/project/[ref]/database/backups/pitr.tsx b/studio/pages/project/[ref]/database/backups/pitr.tsx
index 7b6a865f9d1..10021383c5e 100644
--- a/studio/pages/project/[ref]/database/backups/pitr.tsx
+++ b/studio/pages/project/[ref]/database/backups/pitr.tsx
@@ -83,6 +83,7 @@ const PITR = observer(() => {
? 'Upgrade to the Pro plan with the PITR add-on selected to enable point in time recovery for your project.'
: 'Please enable the add-on to enable point in time recovery for your project.'
}
+ addon="pitr"
/>
)
}
diff --git a/studio/pages/project/[ref]/settings/billing/invoices.tsx b/studio/pages/project/[ref]/settings/billing/invoices.tsx
index 7b50f1e3c0f..e44997f57bc 100644
--- a/studio/pages/project/[ref]/settings/billing/invoices.tsx
+++ b/studio/pages/project/[ref]/settings/billing/invoices.tsx
@@ -5,29 +5,21 @@ import { SettingsLayout } from 'components/layouts'
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import { useSelectedOrganization } from 'hooks'
import { NextPageWithLayout } from 'types'
-import { Alert } from 'ui'
+import { useRouter } from 'next/router'
+import { useEffect } from 'react'
const ProjectBilling: NextPageWithLayout = () => {
const organization = useSelectedOrganization()
const isOrgBilling = !!organization?.subscription_id
+ const router = useRouter()
- 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"
- >
- You might be looking for the{' '}
- <Link href={`/org/${organization?.slug}/invoices`}>
- <a className="text-brand-900">organization's invoices</a>
- </Link>{' '}
- page instead.
- </Alert>
- </div>
- )
- }
+ useEffect(() => {
+ if (isOrgBilling) {
+ router.push(`/org/${organization.slug}/invoices`)
+ }
+ }, [router, organization?.slug, isOrgBilling])
+
+ if (isOrgBilling) return null
return (
<div className="w-full h-full overflow-y-auto content">
diff --git a/studio/pages/project/[ref]/settings/billing/subscription.tsx b/studio/pages/project/[ref]/settings/billing/subscription.tsx
index d787c003404..b1c2a7a5f2c 100644
--- a/studio/pages/project/[ref]/settings/billing/subscription.tsx
+++ b/studio/pages/project/[ref]/settings/billing/subscription.tsx
@@ -1,31 +1,44 @@
-import Link from 'next/link'
-
import SubscriptionV2 from 'components/interfaces/BillingV2/Subscription/Subscription'
import { SettingsLayout } from 'components/layouts'
import { useSelectedOrganization } from 'hooks'
import { NextPageWithLayout } from 'types'
-import { Alert } from 'ui'
+import { useRouter } from 'next/router'
+import { useEffect } from 'react'
const ProjectBilling: NextPageWithLayout = () => {
const organization = useSelectedOrganization()
const isOrgBilling = !!organization?.subscription_id
+ const router = useRouter()
+
+ useEffect(() => {
+ if (isOrgBilling) {
+ const { ref, panel } = router.query
+ let redirectUri = `/org/${organization.slug}/billing`
+ switch (panel) {
+ case 'subscriptionPlan':
+ redirectUri = `/org/${organization.slug}/billing?panel=subscriptionPlan`
+ break
+ case 'costControl':
+ redirectUri = `/org/${organization.slug}/billing?panel=costControl`
+ break
+ case 'computeInstance':
+ redirectUri = `/project/${ref}/settings/addons?panel=computeInstance`
+ break
+ case 'pitr':
+ redirectUri = `/project/${ref}/settings/addons?panel=pitr`
+ break
+ case 'customDomain':
+ redirectUri = `/project/${ref}/settings/addons?panel=customDomain`
+ break
+ }
+
+ router.push(redirectUri)
+ }
+ }, [router, organization?.slug, isOrgBilling])
+ // No need to bother rendering, we'll redirect anyway
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"
- >
- Subscription management can be found on the{' '}
- <Link href={`/org/${organization?.slug}/billing`}>
- <a className="text-brand-900">organization's billing</a>
- </Link>{' '}
- page instead.
- </Alert>
- </div>
- )
+ return null
}
return <SubscriptionV2 />