import { SupportCategories } from '@supabase/shared-types/out/constants' import { Link } from '@tanstack/react-router' import { useFlag, useParams } from 'common' import { ExternalLinkIcon } from 'lucide-react' import { Button } from 'ui' import { Admonition } from 'ui-patterns/Admonition' import { PageSection, PageSectionContent, PageSectionDescription, PageSectionMeta, PageSectionSummary, PageSectionTitle, } from 'ui-patterns/PageSection' import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader' import { Restriction } from '../Restriction' import { useOrgSettingsPanel } from '../useOrgSettingsPanel' import { InitiateCancellationFlowButton } from './CancellationFlow' import { PlanUpdateSidePanel } from './PlanUpdateSidePanel' import { SupportLink } from '@/components/interfaces/Support/SupportLink' import { AlertError } from '@/components/ui/AlertError' import { InlineLinkClassName } from '@/components/ui/InlineLink' import { NoPermission } from '@/components/ui/NoPermission' import { useOrgSubscriptionQuery } from '@/data/subscriptions/org-subscription-query' import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2' import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization' import { MANAGED_BY } from '@/lib/constants/infrastructure' const COMPARE_PLANS_URL = 'https://supabase.com/pricing#compare-plans' const AWS_MARKETPLACE_URL = 'https://supabase.com/aws-marketplace' const Subscription = () => { const { slug } = useParams() const { setPanel } = useOrgSettingsPanel() const projectUpdateDisabled = useFlag('disableProjectCreationAndUpdate') const { data: selectedOrganization } = useSelectedOrganizationQuery() const { isSuccess: isPermissionsLoaded, can: canReadSubscriptions } = useAsyncCheckPermissionsV2( FGA_PERMISSIONS.ORGANIZATION.BILLING_READ ) const { data: subscription, error, isPending: isLoading, isError, isSuccess, } = useOrgSubscriptionQuery({ orgSlug: slug }, { enabled: canReadSubscriptions }) const currentPlan = subscription?.plan const planName = currentPlan?.name ?? 'Unknown' const canChangeTier = !projectUpdateDisabled && !['enterprise', 'platform'].includes(currentPlan?.id ?? '') const isDirectlyManaged = selectedOrganization?.managed_by === MANAGED_BY.SUPABASE // Fail closed until subscription succeeds: unresolved plans look like Free and // `billing_via_partner !== true` is true when the field is still undefined. // Also require billing-read: disabled queries can keep a cached isSuccess. const canPurchaseThroughAws = canReadSubscriptions && isSuccess && canChangeTier && isDirectlyManaged && subscription.billing_via_partner === false return ( <>
Subscription Plan Each organization has it's own subscription plan, billing cycle, payment methods and usage quotas.

More information

Compare plans {canPurchaseThroughAws && ( AWS Marketplace )}
{isPermissionsLoaded && !canReadSubscriptions ? ( ) : ( <> {isLoading && (
)} {isError && } {isSuccess && (

{currentPlan?.name ?? Unknown} Plan

{canChangeTier && (
{currentPlan && currentPlan.id !== 'free' && ( Cancel subscription )}
)}
{!canChangeTier && (
{projectUpdateDisabled ? ( ) : ( Contact support } /> )}
)} {!subscription?.usage_billing_enabled && (
Projects may become unresponsive when this organization exceeds its{' '} included usage quota . To scale seamlessly,{' '} {currentPlan?.id === 'free' ? ( upgrade to a paid plan. ) : ( disable Spend Cap under the Cost Control settings. )}
)}
)} )}
) } export default Subscription