The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix: plan upgrade url for org usage pages (#39608)
Alaister Young947d3b2a7304
diff --git a/apps/studio/components/interfaces/Organization/Usage/Usage.utils.ts b/apps/studio/components/interfaces/Organization/Usage/Usage.utils.tsindex 67ad4cc1c1a..ebfba8dfca8 100644--- a/apps/studio/components/interfaces/Organization/Usage/Usage.utils.ts+++ b/apps/studio/components/interfaces/Organization/Usage/Usage.utils.ts@@ -4,6 +4,7 @@ import { groupBy } from 'lodash'import { DataPoint } from 'data/analytics/constants'import type { OrgDailyUsageResponse, PricingMetric } from 'data/analytics/org-daily-stats-query'import type { OrgSubscription } from 'data/subscriptions/types'+import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'// [Joshen] This is just for development to generate some test data for chart renderingexport const generateUsageData = (attribute: string, days: number): DataPoint[] => {@@ -17,7 +18,16 @@ export const generateUsageData = (attribute: string, days: number): DataPoint[]})}-export const getUpgradeUrl = (slug: string, subscription?: OrgSubscription, source?: string) => {+export function useGetUpgradeUrl(slug: string, subscription?: OrgSubscription, source?: string) {+ const { billingAll } = useIsFeatureEnabled(['billing:all'])++ if (!billingAll) {+ const subject = `Enquiry to upgrade plan for organization`+ const message = `Organization Slug: ${slug}\nRequested plan: <Specify which plan to upgrade to: Pro | Team | Enterprise>`++ return `/support/new?orgSlug=${slug}&projectRef=no-project&category=Plan_upgrade&subject=${subject}&message=${encodeURIComponent(message)}`+ }+if (!subscription) {return `/org/${slug}/billing`}diff --git a/apps/studio/components/interfaces/Organization/Usage/UsageSection/AttributeUsage.tsx b/apps/studio/components/interfaces/Organization/Usage/UsageSection/AttributeUsage.tsxindex 49f2d8e761d..eadeb6c1f87 100644--- a/apps/studio/components/interfaces/Organization/Usage/UsageSection/AttributeUsage.tsx+++ b/apps/studio/components/interfaces/Organization/Usage/UsageSection/AttributeUsage.tsx@@ -16,7 +16,7 @@ import { CategoryAttribute } from '../Usage.constants'import {ChartTooltipValueFormatter,ChartYFormatterCompactNumber,- getUpgradeUrl,+ useGetUpgradeUrl,} from '../Usage.utils'import UsageBarChart from '../UsageBarChart'import { ChartMeta } from './UsageSection'@@ -53,7 +53,7 @@ const AttributeUsage = ({isSuccess,currentBillingCycleSelected,}: AttributeUsageProps) => {- const upgradeUrl = getUpgradeUrl(slug ?? '', subscription, attribute.key)+ const upgradeUrl = useGetUpgradeUrl(slug ?? '', subscription, attribute.key)const usageRatio = (usageMeta?.usage ?? 0) / (usageMeta?.pricing_free_units ?? 0)const usageExcess = (usageMeta?.usage ?? 0) - (usageMeta?.pricing_free_units ?? 0)const usageBasedBilling = subscription?.usage_billing_enableddiff --git a/apps/studio/components/interfaces/Support/ProjectAndPlanInfo.tsx b/apps/studio/components/interfaces/Support/ProjectAndPlanInfo.tsxindex dcb593f5bc4..362f9af3d04 100644--- a/apps/studio/components/interfaces/Support/ProjectAndPlanInfo.tsx+++ b/apps/studio/components/interfaces/Support/ProjectAndPlanInfo.tsx@@ -5,6 +5,7 @@ import type { UseFormReturn } from 'react-hook-form'import { toast } from 'sonner'// End of third-party imports+import { useParams } from 'common'import CopyButton from 'components/ui/CopyButton'import InformationBox from 'components/ui/InformationBox'import { OrganizationProjectSelector } from 'components/ui/OrganizationProjectSelector'@@ -66,6 +67,8 @@ interface ProjectSelectorProps {}function ProjectSelector({ form, orgSlug, projectRef }: ProjectSelectorProps) {+ const { projectRef: urlProjectRef } = useParams()+return (<FormField_Shadcn_name="projectRef"@@ -81,7 +84,7 @@ function ProjectSelector({ form, orgSlug, projectRef }: ProjectSelectorProps) {slug={!orgSlug || orgSlug === NO_ORG_MARKER ? undefined : orgSlug}selectedRef={field.value}onInitialLoad={(projects) => {- if (!projectRef || projectRef === NO_PROJECT_MARKER)+ if (!urlProjectRef && (!projectRef || projectRef === NO_PROJECT_MARKER))field.onChange(projects[0]?.ref ?? NO_PROJECT_MARKER)}}onSelect={(project) => field.onChange(project.ref)}diff --git a/apps/studio/components/interfaces/Support/SupportForm.utils.tsx b/apps/studio/components/interfaces/Support/SupportForm.utils.tsxindex e33793c126d..09515b45987 100644--- a/apps/studio/components/interfaces/Support/SupportForm.utils.tsx+++ b/apps/studio/components/interfaces/Support/SupportForm.utils.tsx@@ -141,7 +141,7 @@ export function createSupportFormUrl(initialParams: SupportFormUrlKeys) {* - URL param (if any)* - Fallback*/-export async function selectInitalOrgAndProject({+export async function selectInitialOrgAndProject({projectRef,orgSlug,orgs,diff --git a/apps/studio/components/interfaces/Support/useSupportForm.ts b/apps/studio/components/interfaces/Support/useSupportForm.tsindex d00b5d63ca8..b3aa32e06c3 100644--- a/apps/studio/components/interfaces/Support/useSupportForm.ts+++ b/apps/studio/components/interfaces/Support/useSupportForm.ts@@ -7,11 +7,11 @@ import { useOrganizationsQuery } from 'data/organizations/organizations-query'import { SupportFormSchema, type SupportFormValues } from './SupportForm.schema'import type { SupportFormActions } from './SupportForm.state'import {- loadSupportFormInitialParams,NO_ORG_MARKER,NO_PROJECT_MARKER,type SupportFormUrlKeys,- selectInitalOrgAndProject,+ loadSupportFormInitialParams,+ selectInitialOrgAndProject,} from './SupportForm.utils'const supportFormDefaultValues: DefaultValues<SupportFormValues> = {@@ -88,7 +88,7 @@ export function useSupportForm(dispatch: Dispatch<SupportFormActions>): UseSuppo? urlParamsRef.current.projectRef: null- selectInitalOrgAndProject({+ selectInitialOrgAndProject({projectRef: projectRefFromUrl,orgSlug: orgSlugFromUrl,orgs: organizations ?? [],