Skip to content

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

Scaffold new billing tab for org v2

Joshen Lim1a3f73e5c251
diff --git a/studio/components/interfaces/Organization/BillingSettings/BillingSettingsV2.tsx b/studio/components/interfaces/Organization/BillingSettings/BillingSettingsV2.tsx
new file mode 100644
index 00000000000..8a3a736386f
--- /dev/null
+++ b/studio/components/interfaces/Organization/BillingSettings/BillingSettingsV2.tsx
@@ -0,0 +1,19 @@
+import CostControl from './CostControl/CostControl'
+import Subscription from './Subscription/Subscription'
+
+const BillingSettingsV2 = () => {
+ return (
+ <>
+ <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">
+ <Subscription />
+ </div>
+ <div className="border-b" />
+ <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">
+ <CostControl />
+ </div>
+ <div className="border-b" />
+ </>
+ )
+}
+
+export default BillingSettingsV2
diff --git a/studio/components/interfaces/Organization/BillingSettings/CostControl/CostControl.tsx b/studio/components/interfaces/Organization/BillingSettings/CostControl/CostControl.tsx
new file mode 100644
index 00000000000..cc6641c7014
--- /dev/null
+++ b/studio/components/interfaces/Organization/BillingSettings/CostControl/CostControl.tsx
@@ -0,0 +1,151 @@
+import Link from 'next/link'
+
+import { useParams, useTheme } from 'common'
+import ShimmeringLoader from 'components/ui/ShimmeringLoader'
+import { BASE_PATH } from 'lib/constants'
+import { useSubscriptionPageStateSnapshot } from 'state/subscription-page'
+import { Alert, Button, IconExternalLink } from 'ui'
+// import SpendCapSidePanel from './SpendCapSidePanel'
+import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
+import { useFlag } from 'hooks'
+import ProjectUpdateDisabledTooltip from '../ProjectUpdateDisabledTooltip'
+
+export interface CostControlProps {}
+
+const CostControl = ({}: CostControlProps) => {
+ const { slug } = useParams()
+ const snap = useSubscriptionPageStateSnapshot()
+ const projectUpdateDisabled = useFlag('disableProjectCreationAndUpdate')
+ const { isDarkMode } = useTheme()
+
+ const { data: subscription, isLoading } = useOrgSubscriptionQuery({ orgSlug: slug })
+
+ const currentPlan = subscription?.plan
+ const isUsageBillingEnabled = subscription?.usage_billing_enabled ?? false
+
+ const canChangeTier =
+ !projectUpdateDisabled && !['team', 'enterprise'].includes(currentPlan?.id || '')
+
+ return (
+ <>
+ <div className="grid grid-cols-12 gap-6" id="cost-control">
+ <div className="col-span-12 lg:col-span-5">
+ <div className="sticky top-16">
+ <div className="space-y-6">
+ <div>
+ <p className="text-base">Cost Control</p>
+ <p className="text-sm text-scale-1000">
+ Control whether to use beyond your plans included quota
+ </p>
+ </div>
+ <div className="space-y-2">
+ <p className="text-sm text-scale-1100">More information</p>
+ <div>
+ <Link href="https://supabase.com/docs/guides/platform/spend-cap">
+ <a target="_blank" rel="noreferrer">
+ <div className="flex items-center space-x-2 opacity-50 hover:opacity-100 transition">
+ <p className="text-sm">Spend cap</p>
+ <IconExternalLink size={16} strokeWidth={1.5} />
+ </div>
+ </a>
+ </Link>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ {isLoading ? (
+ <div className="col-span-12 lg:col-span-7 space-y-2">
+ <ShimmeringLoader />
+ <ShimmeringLoader className="w-3/4" />
+ <ShimmeringLoader className="w-1/2" />
+ </div>
+ ) : (
+ <div className="col-span-12 lg:col-span-7 space-y-6">
+ {['team', 'enterprise'].includes(currentPlan?.id || '') ? (
+ <Alert
+ withIcon
+ variant="info"
+ title={`You will be charged for any additional usage on the ${
+ currentPlan?.name || ''
+ } plan`}
+ >
+ {currentPlan?.name || ''} plan requires you to have spend cap off at all times. Your
+ projects will never become unresponsive. Only when your{' '}
+ <Link href="#breakdown">
+ <a className="text-sm text-green-900 transition hover:text-green-1000">
+ included usage
+ </a>
+ </Link>{' '}
+ is exceeded will you be charged for any additional usage.
+ </Alert>
+ ) : (
+ <p className="text-sm text-scale-1000">
+ You can control whether your organization is charged for additional usage beyond the{' '}
+ <Link href="#breakdown">
+ <a className="text-sm text-green-900 transition hover:text-green-1000">
+ included quota
+ </a>
+ </Link>{' '}
+ of your subscription plan. If you need to go beyond the included quota, simply
+ switch off your spend cap to pay for additional usage.
+ </p>
+ )}
+
+ <div className="flex space-x-6">
+ <div>
+ <div className="rounded-md bg-scale-100 dark:bg-scale-400 w-[160px] h-[96px] shadow">
+ <img
+ alt="Spend Cap"
+ width={160}
+ height={96}
+ src={
+ isUsageBillingEnabled
+ ? `${BASE_PATH}/img/spend-cap-off${isDarkMode ? '' : '--light'}.png?v=3`
+ : `${BASE_PATH}/img/spend-cap-on${isDarkMode ? '' : '--light'}.png?v=3`
+ }
+ />
+ </div>
+ </div>
+ <div>
+ <p className="mb-1">
+ Spend cap is {isUsageBillingEnabled ? 'disabled' : 'enabled'}
+ </p>
+ <p className="text-sm text-scale-1000">
+ {isUsageBillingEnabled ? (
+ <span>You will be charged for any usage above the included quota.</span>
+ ) : (
+ <span>
+ You won't be charged any extra for usage. However, your projects could become
+ unresponsive or enter read only mode if you exceed the included quota.
+ </span>
+ )}
+ </p>
+ {isUsageBillingEnabled && (
+ <p className="text-sm text-scale-1000 mt-1">
+ Your projects will never become unresponsive. Only when your usage reaches the
+ quota limit will you be charged for any excess usage.
+ </p>
+ )}
+ <ProjectUpdateDisabledTooltip projectUpdateDisabled={projectUpdateDisabled}>
+ <Button
+ type="default"
+ className="mt-4"
+ disabled={!canChangeTier}
+ onClick={() => snap.setPanelKey('costControl')}
+ >
+ Change spend cap
+ </Button>
+ </ProjectUpdateDisabledTooltip>
+ </div>
+ </div>
+ </div>
+ )}
+ </div>
+
+ {/* <SpendCapSidePanel /> */}
+ </>
+ )
+}
+
+export default CostControl
diff --git a/studio/components/interfaces/Organization/BillingSettings/ProjectUpdateDisabledTooltip.tsx b/studio/components/interfaces/Organization/BillingSettings/ProjectUpdateDisabledTooltip.tsx
new file mode 100644
index 00000000000..873a8144f68
--- /dev/null
+++ b/studio/components/interfaces/Organization/BillingSettings/ProjectUpdateDisabledTooltip.tsx
@@ -0,0 +1,36 @@
+import * as Tooltip from '@radix-ui/react-tooltip'
+import { PropsWithChildren } from 'react'
+
+export interface ProjectUpdateDisabledTooltipProps {
+ projectUpdateDisabled: boolean
+}
+
+const ProjectUpdateDisabledTooltip = ({
+ projectUpdateDisabled,
+ children,
+}: PropsWithChildren<ProjectUpdateDisabledTooltipProps>) => {
+ return (
+ <Tooltip.Root delayDuration={0}>
+ <Tooltip.Trigger asChild>{children}</Tooltip.Trigger>
+ {projectUpdateDisabled ? (
+ <Tooltip.Portal>
+ <Tooltip.Content side="bottom">
+ <Tooltip.Arrow className="radix-tooltip-arrow" />
+ <div
+ className={[
+ 'rounded bg-scale-100 py-1 px-2 leading-none shadow',
+ 'border border-scale-200',
+ ].join(' ')}
+ >
+ <span className="text-xs text-scale-1200">
+ Subscription changes are currently disabled. Our engineers are working on a fix.
+ </span>
+ </div>
+ </Tooltip.Content>
+ </Tooltip.Portal>
+ ) : null}
+ </Tooltip.Root>
+ )
+}
+
+export default ProjectUpdateDisabledTooltip
diff --git a/studio/components/interfaces/Organization/BillingSettings/Subscription/README.md b/studio/components/interfaces/Organization/BillingSettings/Subscription/README.md
new file mode 100644
index 00000000000..0ed42b4e4bc
--- /dev/null
+++ b/studio/components/interfaces/Organization/BillingSettings/Subscription/README.md
@@ -0,0 +1,7 @@
+### Disclaimer
+
+[Joshen] Just FYI a lot of these are lifted from `components/interfaces/BillingV2/Subscription` since they are
+more or less the same, in fact after migrating to Org billing completely, we will probably deprecate the BillingV2 folder
+at the project scope.
+
+- Probably also need to update support form to allow selecting an organization, not just project
diff --git a/studio/components/interfaces/Organization/BillingSettings/Subscription/Subscription.tsx b/studio/components/interfaces/Organization/BillingSettings/Subscription/Subscription.tsx
new file mode 100644
index 00000000000..c44cb8fd99f
--- /dev/null
+++ b/studio/components/interfaces/Organization/BillingSettings/Subscription/Subscription.tsx
@@ -0,0 +1,174 @@
+import dayjs from 'dayjs'
+import Link from 'next/link'
+
+import { useParams } from 'common'
+import AlertError from 'components/ui/AlertError'
+import ShimmeringLoader from 'components/ui/ShimmeringLoader'
+import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
+import { useFlag } from 'hooks'
+import { Alert, Button, IconExternalLink } from 'ui'
+import ProjectUpdateDisabledTooltip from '../ProjectUpdateDisabledTooltip'
+import SparkBar from 'components/ui/SparkBar'
+
+const Subscription = () => {
+ const { slug } = useParams()
+ const projectUpdateDisabled = useFlag('disableProjectCreationAndUpdate')
+
+ const {
+ data: subscription,
+ error,
+ isLoading,
+ isError,
+ isSuccess,
+ } = useOrgSubscriptionQuery({ orgSlug: slug })
+
+ const currentPlan = subscription?.plan
+ const planName = currentPlan?.name ?? 'Unknown'
+ const billingCycleStart = dayjs.unix(subscription?.current_period_start ?? 0).utc()
+ const billingCycleEnd = dayjs.unix(subscription?.current_period_end ?? 0).utc()
+ const daysToCycleEnd = billingCycleEnd.diff(dayjs(), 'days')
+ const daysWithinCycle = billingCycleEnd.diff(billingCycleStart, 'days')
+
+ const canChangeTier =
+ !projectUpdateDisabled && !['team', 'enterprise'].includes(currentPlan?.id ?? '')
+
+ console.log({ subscription })
+
+ return (
+ <div id="plan" className="grid grid-cols-12 gap-6">
+ <div className="col-span-12 lg:col-span-5 space-y-6">
+ <div className="sticky space-y-6 top-16">
+ <p className="text-base">Subscription plan</p>
+ <div className="space-y-2">
+ <p className="text-sm text-scale-1100">More information</p>
+ <div>
+ <Link href="https://supabase.com/pricing">
+ <a target="_blank" rel="noreferrer">
+ <div className="flex items-center space-x-2 opacity-50 hover:opacity-100 transition">
+ <p className="text-sm">Pricing</p>
+ <IconExternalLink size={16} strokeWidth={1.5} />
+ </div>
+ </a>
+ </Link>
+ </div>
+ </div>
+ </div>
+ </div>
+ <div className="col-span-12 lg:col-span-7">
+ {isLoading && (
+ <div className="space-y-2">
+ <ShimmeringLoader />
+ <ShimmeringLoader className="w-3/4" />
+ <ShimmeringLoader className="w-1/2" />
+ </div>
+ )}
+
+ {isError && <AlertError subject="Failed to retrieve subscription" error={error} />}
+
+ {isSuccess && (
+ <div className="space-y-6">
+ <div>
+ <p className="text-sm">This organization is currently on the plan:</p>
+ <p className="text-2xl text-brand-900 uppercase">{currentPlan?.name ?? 'Unknown'}</p>
+ </div>
+
+ <div>
+ <ProjectUpdateDisabledTooltip projectUpdateDisabled={projectUpdateDisabled}>
+ <Button
+ type="default"
+ disabled={!canChangeTier}
+ onClick={() => {}} // [JOSHEN TODO: Implement]
+ >
+ Change subscription plan
+ </Button>
+ </ProjectUpdateDisabledTooltip>
+ {!canChangeTier &&
+ (projectUpdateDisabled ? (
+ <Alert withIcon variant="info" title={`Unable to update plan from ${planName}`}>
+ We have temporarily disabled project and subscription changes - our engineers
+ are working on a fix.
+ </Alert>
+ ) : (
+ <Alert
+ withIcon
+ variant="info"
+ title={`Unable to update plan from ${planName}`}
+ actions={[
+ <div key="contact-support">
+ <Link
+ href={`/support/new?category=sales&subject=Change%20plan%20away%20from%20${planName}`}
+ >
+ <a>
+ <Button type="default">Contact support</Button>
+ </a>
+ </Link>
+ </div>,
+ ]}
+ >
+ Please contact us if you'd like to change your plan.
+ </Alert>
+ ))}
+ </div>
+
+ {!subscription?.usage_billing_enabled && (
+ <Alert
+ withIcon
+ variant="info"
+ title="This organization is limited by the included usage"
+ actions={
+ currentPlan?.id === 'free' ? (
+ // [Joshen TODO]: Implement
+ <Button type="default" onClick={() => {}}>
+ Upgrade Plan
+ </Button>
+ ) : (
+ // [Joshen TODO]: Implement
+ <Button type="default" onClick={() => {}}>
+ Adjust Spend Cap
+ </Button>
+ )
+ }
+ >
+ <p className="text-sm text-scale-1000">
+ When this organization exceeds its{' '}
+ <Link href="#breakdown">
+ <a className="text-sm text-green-900 transition hover:text-green-1000">
+ included usage quotas
+ </a>
+ </Link>
+ , its projects may become unresponsive.{' '}
+ {currentPlan?.id === 'free' ? (
+ <p className="pr-4">
+ If you wish to exceed the included usage, you should upgrade to a paid plan.
+ </p>
+ ) : (
+ <p className="pr-4">
+ You currently have Spend Cap enabled - when you exceed your plan's limit, you
+ will experience restrictions. To scale seamlessly and pay for over-usage, you
+ can adjust your Cost Control settings.
+ </p>
+ )}
+ </p>
+ </Alert>
+ )}
+
+ <SparkBar
+ type="horizontal"
+ value={daysWithinCycle - daysToCycleEnd}
+ max={daysWithinCycle}
+ barClass="bg-scale-1200"
+ labelBottom={`Current billing cycle (${billingCycleStart.format(
+ 'MMM DD'
+ )} - ${billingCycleEnd.format('MMM DD')})`}
+ bgClass="bg-gray-300 dark:bg-gray-600"
+ labelBottomClass="!text-scale-1000 pb-1"
+ labelTop={`${daysToCycleEnd} Days left`}
+ />
+ </div>
+ )}
+ </div>
+ </div>
+ )
+}
+
+export default Subscription
diff --git a/studio/components/interfaces/Organization/NewOrg/NewOrgForm.tsx b/studio/components/interfaces/Organization/NewOrg/NewOrgForm.tsx
index a722a301238..184eb20c7d2 100644
--- a/studio/components/interfaces/Organization/NewOrg/NewOrgForm.tsx
+++ b/studio/components/interfaces/Organization/NewOrg/NewOrgForm.tsx
@@ -174,7 +174,6 @@ const NewOrgForm = ({ onPaymentMethodReset }: NewOrgFormProps) => {
<div className="flex items-center space-x-3">
<p className="text-xs text-scale-900">You can rename your organization later</p>
<Button
- block
htmlType="submit"
type="primary"
loading={newOrgLoading}
diff --git a/studio/components/interfaces/Organization/index.ts b/studio/components/interfaces/Organization/index.ts
index 2c02467f0f9..d37a3c1ca1d 100644
--- a/studio/components/interfaces/Organization/index.ts
+++ b/studio/components/interfaces/Organization/index.ts
@@ -1,8 +1,17 @@
import GeneralSettings from './GeneralSettings/GeneralSettings'
import TeamSettings from './TeamSettings/TeamSettings'
import BillingSettings from './BillingSettings/BillingSettings'
+import BillingSettingsV2 from './BillingSettings/BillingSettingsV2'
import InvoicesSettings from './InvoicesSettings/InvoicesSettings'
import NewOrgForm from './NewOrg/NewOrgForm'
import OAuthApps from './OAuthApps/OAuthApps'
-export { GeneralSettings, TeamSettings, BillingSettings, InvoicesSettings, NewOrgForm, OAuthApps }
+export {
+ GeneralSettings,
+ TeamSettings,
+ BillingSettings,
+ BillingSettingsV2,
+ InvoicesSettings,
+ NewOrgForm,
+ OAuthApps,
+}
diff --git a/studio/data/subscriptions/org-subscription-query.ts b/studio/data/subscriptions/org-subscription-query.ts
index 3429664c4ae..8b3d6c9ccb8 100644
--- a/studio/data/subscriptions/org-subscription-query.ts
+++ b/studio/data/subscriptions/org-subscription-query.ts
@@ -3,6 +3,7 @@ import { get } from 'lib/common/fetch'
import { API_URL } from 'lib/constants'
import { useCallback } from 'react'
import { subscriptionKeys } from './keys'
+import { ResponseError } from 'types'
export type OrgSubscriptionVariables = {
orgSlug?: string
@@ -59,7 +60,7 @@ export async function getOrgSubscription(
}
export type OrgSubscriptionData = Awaited<ReturnType<typeof getOrgSubscription>>
-export type OrgSubscriptionError = unknown
+export type OrgSubscriptionError = ResponseError
export const useOrgSubscriptionQuery = <TData = OrgSubscriptionData>(
{ orgSlug }: OrgSubscriptionVariables,
diff --git a/studio/pages/org/[slug]/billing.tsx b/studio/pages/org/[slug]/billing.tsx
index d32cfa72bc1..c91ad14096b 100644
--- a/studio/pages/org/[slug]/billing.tsx
+++ b/studio/pages/org/[slug]/billing.tsx
@@ -1,7 +1,7 @@
import { useRouter } from 'next/router'
import { useParams } from 'common/hooks'
-import { BillingSettings } from 'components/interfaces/Organization'
+import { BillingSettings, BillingSettingsV2 } from 'components/interfaces/Organization'
import { OrganizationLayout } from 'components/layouts'
import Loading from 'components/ui/Loading'
import { usePermissionsQuery } from 'data/permissions/permissions-query'
@@ -10,20 +10,25 @@ import { NextPageWithLayout } from 'types'
import { Tabs } from 'ui'
const OrgBillingSettings: NextPageWithLayout = () => {
- const { data: permissions } = usePermissionsQuery()
- const selectedOrganization = useSelectedOrganization()
const { slug } = useParams()
const router = useRouter()
+
+ const selectedOrganization = useSelectedOrganization()
+ const { isLoading: isLoadingPermissions } = usePermissionsQuery()
+
const showOAuthApps = useFlag('oauthApps')
+ const orgCreationV2 = useFlag('orgcreationv2')
+
+ const isOrgBilling = !!selectedOrganization?.subscription_id
return (
<>
- {selectedOrganization === undefined && (permissions ?? []).length === 0 ? (
+ {selectedOrganization === undefined && isLoadingPermissions ? (
<Loading />
) : (
- <div className="p-4 pt-0">
- <div className="space-y-3">
- <section className="mt-4">
+ <div>
+ <div className="space-y-3.5">
+ <section className="mt-4 px-4">
<h1 className="text-3xl">{selectedOrganization?.name ?? 'Organization'} settings</h1>
</section>
<nav>
@@ -37,7 +42,8 @@ const OrgBillingSettings: NextPageWithLayout = () => {
>
<Tabs.Panel id="general" label="General" />
<Tabs.Panel id="team" label="Team" />
- <Tabs.Panel id="billing" label="Billing" />
+ <Tabs.Panel id="billing" label="Billing" className="!m-0" />
+ {orgCreationV2 && <Tabs.Panel id="usage" label="Usage" />}
<Tabs.Panel id="invoices" label="Invoices" />
{showOAuthApps && <Tabs.Panel id="apps" label="OAuth Apps" />}
</Tabs>
@@ -45,7 +51,13 @@ const OrgBillingSettings: NextPageWithLayout = () => {
</div>
<div className="mb-8">
- <BillingSettings />
+ {isOrgBilling ? (
+ <BillingSettingsV2 />
+ ) : (
+ <div className="px-4">
+ <BillingSettings />
+ </div>
+ )}
</div>
</div>
)}
diff --git a/studio/pages/org/[slug]/usage.tsx b/studio/pages/org/[slug]/usage.tsx
new file mode 100644
index 00000000000..4106cd88926
--- /dev/null
+++ b/studio/pages/org/[slug]/usage.tsx
@@ -0,0 +1,58 @@
+import { useRouter } from 'next/router'
+
+import { useParams } from 'common/hooks'
+import { OrganizationLayout } from 'components/layouts'
+import Loading from 'components/ui/Loading'
+import { usePermissionsQuery } from 'data/permissions/permissions-query'
+import { useFlag, useSelectedOrganization } from 'hooks'
+import { NextPageWithLayout } from 'types'
+import { Tabs } from 'ui'
+
+const OrgUsage: NextPageWithLayout = () => {
+ const { data: permissions } = usePermissionsQuery()
+ const selectedOrganization = useSelectedOrganization()
+ const { slug } = useParams()
+ const router = useRouter()
+ const showOAuthApps = useFlag('oauthApps')
+
+ return (
+ <>
+ {selectedOrganization === undefined && (permissions ?? []).length === 0 ? (
+ <Loading />
+ ) : (
+ <div className="p-4 pt-0">
+ <div className="space-y-3">
+ <section className="mt-4">
+ <h1 className="text-3xl">{selectedOrganization?.name ?? 'Organization'} settings</h1>
+ </section>
+ <nav>
+ <Tabs
+ size="small"
+ type="underlined"
+ activeId="usage"
+ onChange={(id: any) => {
+ if (id !== 'usage') router.push(`/org/${slug}/${id}`)
+ }}
+ >
+ <Tabs.Panel id="general" label="General" />
+ <Tabs.Panel id="team" label="Team" />
+ <Tabs.Panel id="billing" label="Billing" />
+ <Tabs.Panel id="usage" label="Usage" />
+ <Tabs.Panel id="invoices" label="Invoices" />
+ {showOAuthApps && <Tabs.Panel id="apps" label="OAuth Apps" />}
+ </Tabs>
+ </nav>
+ </div>
+
+ <div className="mb-8">
+ <p>Billing V2</p>
+ </div>
+ </div>
+ )}
+ </>
+ )
+}
+
+OrgUsage.getLayout = (page) => <OrganizationLayout>{page}</OrganizationLayout>
+
+export default OrgUsage