import { Link } from '@tanstack/react-router' import { useFlag, useParams } from 'common' import { ExternalLinkIcon } from 'lucide-react' import { useTheme } from 'next-themes' import { Alert, AlertTitle, 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 { ProjectUpdateDisabledTooltip } from '../ProjectUpdateDisabledTooltip' import { useOrgSettingsPanel } from '../useOrgSettingsPanel' import { SpendCapSidePanel } from './SpendCapSidePanel' import { AlertError } from '@/components/ui/AlertError' import { InlineLink } from '@/components/ui/InlineLink' import { NoPermission } from '@/components/ui/NoPermission' import PartnerIcon from '@/components/ui/PartnerIcon' import { PARTNER_TO_NAME } from '@/components/ui/PartnerManagedResource' import { useOrgSubscriptionQuery } from '@/data/subscriptions/org-subscription-query' import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2' import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization' import { BASE_PATH, DOCS_URL } from '@/lib/constants' import { MANAGED_BY } from '@/lib/constants/infrastructure' export const CostControl = () => { const { slug } = useParams() const { resolvedTheme } = useTheme() const { setPanel } = useOrgSettingsPanel() const { data: selectedOrganization } = useSelectedOrganizationQuery() const projectUpdateDisabled = useFlag('disableProjectCreationAndUpdate') const { isSuccess: isPermissionsLoaded, can: canReadSubscriptions } = useAsyncCheckPermissionsV2( FGA_PERMISSIONS.ORGANIZATION.BILLING_READ ) const { data: subscription, error, isPending: isLoading, isSuccess, isError, } = useOrgSubscriptionQuery({ orgSlug: slug }, { enabled: canReadSubscriptions }) const currentPlan = subscription?.plan const isUsageBillingEnabled = subscription?.usage_billing_enabled ?? false const canChangeTier = !projectUpdateDisabled && !['team', 'enterprise', 'platform'].includes(currentPlan?.id || '') const costControlDisabled = selectedOrganization?.managed_by === MANAGED_BY.AWS_MARKETPLACE return ( <>
Cost Control Allow scaling beyond your plan's{' '} included quota.

More information

Spend cap
{isPermissionsLoaded && !canReadSubscriptions ? ( ) : ( <> {isLoading && (
)} {isError && } {isSuccess && costControlDisabled && ( The Spend Cap is not available for organizations managed by{' '} {PARTNER_TO_NAME[selectedOrganization?.managed_by]}. )} {isSuccess && !costControlDisabled && (
{['team', 'enterprise', 'platform'].includes(currentPlan?.id || '') ? ( <> {currentPlan?.name || ''}{' '} plan requires you to have spend cap off at all times. Your projects will never become unresponsive. Only when your {' '} included usage {' '} is exceeded will you be charged for any additional usage. } /> ) : (

If you need to go beyond the included quota, simply switch off your spend cap to pay for additional usage.

)}

Spend cap is{' '} {isUsageBillingEnabled ? disabled : enabled}

{isUsageBillingEnabled ? ( You will be charged for usage beyond the included quota. ) : ( 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. )}

)} )}
) }