The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
chore: prevent deploying new replicas with outstanding invoices (#29682)
Joshen Limb5daa7e0e647
diff --git a/apps/studio/components/interfaces/Home/ProjectList/ProjectList.tsx b/apps/studio/components/interfaces/Home/ProjectList/ProjectList.tsxindex a04c9c95c41..46002fece18 100644--- a/apps/studio/components/interfaces/Home/ProjectList/ProjectList.tsx+++ b/apps/studio/components/interfaces/Home/ProjectList/ProjectList.tsx@@ -50,7 +50,7 @@ const ProjectList = ({error: permissionsError,} = usePermissionsQuery()const { data: resourceWarnings } = useResourceWarningsQuery()- const { data: allOverdueInvoices } = useOverdueInvoicesQuery({ enabled: IS_PLATFORM })+ const { data: allOverdueInvoices } = useOverdueInvoicesQuery()const projectsByOrg = groupBy(allProjects, 'organization_id')const isLoadingPermissions = IS_PLATFORM ? _isLoadingPermissions : falsediff --git a/apps/studio/components/interfaces/Organization/NewProject/FreeProjectLimitWarning.tsx b/apps/studio/components/interfaces/Organization/NewProject/FreeProjectLimitWarning.tsxindex b1ed5fb61f2..0c4923d91fe 100644--- a/apps/studio/components/interfaces/Organization/NewProject/FreeProjectLimitWarning.tsx+++ b/apps/studio/components/interfaces/Organization/NewProject/FreeProjectLimitWarning.tsx@@ -37,7 +37,7 @@ const FreeProjectLimitWarning = ({</p><div>- <Button asChild type="secondary">+ <Button asChild type="default"><Link href={`/org/${orgSlug}/billing?panel=subscriptionPlan`}>Upgrade plan</Link></Button></div>diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DeployNewReplicaPanel.tsx b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DeployNewReplicaPanel.tsxindex d82834adf99..8eddf4eaa81 100644--- a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DeployNewReplicaPanel.tsx+++ b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DeployNewReplicaPanel.tsx@@ -5,12 +5,16 @@ import { toast } from 'sonner'import { useParams } from 'common'import {- DISK_LIMITS,DISK_PRICING,DiskType,} from 'components/interfaces/DiskManagement/DiskManagement.constants'+import {+ calculateIOPSPrice,+ calculateThroughputPrice,+} from 'components/interfaces/DiskManagement/DiskManagement.utils'import { useDiskAttributesQuery } from 'data/config/disk-attributes-query'import { useEnablePhysicalBackupsMutation } from 'data/database/enable-physical-backups-mutation'+import { useOverdueInvoicesQuery } from 'data/invoices/invoices-overdue-query'import { useProjectDetailQuery } from 'data/projects/project-detail-query'import { Region, useReadReplicaSetUpMutation } from 'data/read-replicas/replica-setup-mutation'import {@@ -24,6 +28,7 @@ import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'import { useSelectedProject } from 'hooks/misc/useSelectedProject'import { useFlag } from 'hooks/ui/useFlag'import { AWS_REGIONS_DEFAULT, BASE_PATH } from 'lib/constants'+import { formatCurrency } from 'lib/helpers'import type { AWS_REGIONS_KEYS } from 'shared-data'import { AWS_REGIONS } from 'shared-data'import {@@ -46,11 +51,6 @@ import {cn,} from 'ui'import { AVAILABLE_REPLICA_REGIONS } from './InstanceConfiguration.constants'-import {- calculateIOPSPrice,- calculateThroughputPrice,-} from 'components/interfaces/DiskManagement/DiskManagement.utils'-import { formatCurrency } from 'lib/helpers'// [Joshen] FYI this is purely for AWS only, need to update to support Fly eventually@@ -77,6 +77,15 @@ const DeployNewReplicaPanel = ({const { data: subscription } = useOrgSubscriptionQuery({ orgSlug: org?.slug })const { data: diskConfiguration } = useDiskAttributesQuery({ projectRef })+ const { data: allOverdueInvoices } = useOverdueInvoicesQuery({+ enabled:+ subscription !== undefined && !['team', 'enterprise'].includes(subscription?.plan.id ?? ''),+ })+ const overdueInvoices = (allOverdueInvoices ?? []).filter(+ (x) => x.organization_id === project?.organization_id+ )+ const hasOverdueInvoices = overdueInvoices.length > 0+// Opting for useState temporarily as Listbox doesn't seem to work with react-hook-form yetconst [defaultRegion] = Object.entries(AWS_REGIONS).find(([_, name]) => name === AWS_REGIONS_DEFAULT@@ -172,7 +181,8 @@ const DeployNewReplicaPanel = ({isAWSProvider &&!isFreePlan &&isWalgEnabled &&- currentComputeAddon !== undefined+ currentComputeAddon !== undefined &&+ !hasOverdueInvoicesconst computeAddons =addons?.available_addons.find((addon) => addon.type === 'compute_instance')?.variants ?? []@@ -216,7 +226,22 @@ const DeployNewReplicaPanel = ({confirmText="Deploy replica"><SidePanel.Content className="flex flex-col py-4 gap-y-4">- {!isAWSProvider ? (+ {hasOverdueInvoices ? (+ <Alert_Shadcn_>+ <WarningIcon />+ <AlertTitle_Shadcn_>Your organization has overdue invoices</AlertTitle_Shadcn_>+ <AlertDescription_Shadcn_>+ <span>+ Please resolve all outstanding invoices first before deploying a new read replica+ </span>+ <div className="mt-3">+ <Button asChild type="default">+ <Link href={`/org/${org?.slug}/invoices`}>View invoices</Link>+ </Button>+ </div>+ </AlertDescription_Shadcn_>+ </Alert_Shadcn_>+ ) : !isAWSProvider ? (<Alert_Shadcn_><WarningIcon /><AlertTitle_Shadcn_>diff --git a/apps/studio/components/ui/PartnerManagedResource.tsx b/apps/studio/components/ui/PartnerManagedResource.tsxindex 22981caceea..7ea52342825 100644--- a/apps/studio/components/ui/PartnerManagedResource.tsx+++ b/apps/studio/components/ui/PartnerManagedResource.tsx@@ -42,7 +42,7 @@ function PartnerManagedResource({ partner, resource, cta }: PartnerManagedResour</AlertTitle_Shadcn_>{ctaEnabled && (- <Button asChild iconRight={<ExternalLink />} disabled={isLoading || isError}>+ <Button asChild type="default" iconRight={<ExternalLink />} disabled={isLoading || isError}><a href={ctaUrl} target="_blank" rel="noopener noreferrer">{cta.message || `View ${resource} on ${PARTNER_TO_NAME[partner]}`}</a>diff --git a/apps/studio/data/invoices/invoices-overdue-query.ts b/apps/studio/data/invoices/invoices-overdue-query.tsindex df541684173..0df8250d9bc 100644--- a/apps/studio/data/invoices/invoices-overdue-query.ts+++ b/apps/studio/data/invoices/invoices-overdue-query.ts@@ -2,6 +2,7 @@ import { useQuery, UseQueryOptions } from '@tanstack/react-query'import type { components } from 'data/api'import { get, handleError } from 'data/fetchers'import { invoicesKeys } from './keys'+import { IS_PLATFORM } from 'lib/constants'export type OverdueInvoicesResponse = components['schemas']['OverdueInvoiceCount']@@ -24,5 +25,5 @@ export const useOverdueInvoicesQuery = <TData = OverdueInvoicesData>({useQuery<OverdueInvoicesData, OverdueInvoicesError, TData>(invoicesKeys.overdueInvoices(),({ signal }) => getOverdueInvoices(signal),- { enabled, ...options }+ { enabled: enabled && IS_PLATFORM, ...options })diff --git a/apps/studio/pages/new/[slug].tsx b/apps/studio/pages/new/[slug].tsxindex 434d49e5bd4..7399098ecf5 100644--- a/apps/studio/pages/new/[slug].tsx+++ b/apps/studio/pages/new/[slug].tsx@@ -79,6 +79,7 @@ import { Admonition } from 'ui-patterns/admonition'import { Input } from 'ui-patterns/DataInputs/Input'import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'import { InfoTooltip } from 'ui-patterns/info-tooltip'+import { useOverdueInvoicesQuery } from 'data/invoices/invoices-overdue-query'type DesiredInstanceSize = components['schemas']['DesiredInstanceSize']@@ -203,16 +204,24 @@ const Wizard: NextPageWithLayout = () => {const { data: organizations, isSuccess: isOrganizationsSuccess } = useOrganizationsQuery()const currentOrg = organizations?.find((o: any) => o.slug === slug)+ const { data: orgSubscription } = useOrgSubscriptionQuery({ orgSlug: slug })++ const { data: allOverdueInvoices } = useOverdueInvoicesQuery({+ enabled:+ orgSubscription !== undefined &&+ !['team', 'enterprise'].includes(orgSubscription?.plan.id ?? ''),+ })+ const overdueInvoices = (allOverdueInvoices ?? []).filter(+ (x) => x.organization_id === currentOrg?.id+ )+ const hasOutstandingInvoices = overdueInvoices.length > 0+const { data: allProjects } = useProjectsQuery({})const organizationProjects =allProjects?.filter((project) =>project.organization_id === currentOrg?.id && project.status !== PROJECT_STATUS.INACTIVE) ?? []-- const { data: orgSubscription } = useOrgSubscriptionQuery({- orgSlug: slug,- })const { data: defaultRegion, error: defaultRegionError } = useDefaultRegionQuery({cloudProvider: PROVIDERS[DEFAULT_PROVIDER].id,@@ -246,7 +255,8 @@ const Wizard: NextPageWithLayout = () => {const isManagedByVercel = currentOrg?.managed_by === 'vercel-marketplace'- const canCreateProject = isAdmin && !freePlanWithExceedingLimits && !isManagedByVercel+ const canCreateProject =+ isAdmin && !freePlanWithExceedingLimits && !isManagedByVercel && !hasOutstandingInvoicesconst delayedCheckPasswordStrength = useRef(debounce((value) => checkPasswordStrength(value), 300)@@ -462,7 +472,7 @@ const Wizard: NextPageWithLayout = () => {<ButtonhtmlType="submit"loading={isCreatingNewProject || isSuccessNewProject}- disabled={isCreatingNewProject || isSuccessNewProject || isManagedByVercel}+ disabled={!canCreateProject || isCreatingNewProject || isSuccessNewProject}>Create new project</Button>@@ -1044,16 +1054,17 @@ const Wizard: NextPageWithLayout = () => {</>)}- {isAdmin && freePlanWithExceedingLimits && slug && (- <Panel.Content>- <FreeProjectLimitWarning- membersExceededLimit={membersExceededLimit || []}- orgSlug={slug}- />- </Panel.Content>- )}-- {!freePlanWithExceedingLimits && isManagedByVercel && (+ {freePlanWithExceedingLimits ? (+ isAdmin &&+ slug && (+ <Panel.Content>+ <FreeProjectLimitWarning+ membersExceededLimit={membersExceededLimit || []}+ orgSlug={slug}+ />+ </Panel.Content>+ )+ ) : isManagedByVercel ? (<Panel.Content><PartnerManagedResourcepartner="vercel-marketplace"@@ -1064,7 +1075,28 @@ const Wizard: NextPageWithLayout = () => {}}/></Panel.Content>- )}+ ) : hasOutstandingInvoices ? (+ <Panel.Content>+ <Admonition+ type="default"+ title="Your organization has overdue invoices"+ description={+ <div className="space-y-3">+ <p className="text-sm leading-normal">+ Please resolve all outstanding invoices first before creating a new+ project+ </p>++ <div>+ <Button asChild type="default">+ <Link href={`/org/${slug}/invoices`}>View invoices</Link>+ </Button>+ </div>+ </div>+ }+ />+ </Panel.Content>+ ) : null}</div>)}</>