The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Add billing breakdown
Joshen Lim8d211846f62d
diff --git a/studio/components/interfaces/Home/ProjectList/ProjectList.tsx b/studio/components/interfaces/Home/ProjectList/ProjectList.tsxindex e4ee9880f3e..1868b9c2689 100644--- a/studio/components/interfaces/Home/ProjectList/ProjectList.tsx+++ b/studio/components/interfaces/Home/ProjectList/ProjectList.tsx@@ -124,14 +124,14 @@ const OrganizationProjects = ({{isErrorPermissions ? (<div className="col-span-3"><AlertError- subject="Unable to retrieve permissions for your account"+ subject="Failed to retrieve permissions for your account"error={permissionsError}/></div>) : isErrorProjects ? (<div className="col-span-3"><AlertError- subject={`Unable to retrieve projects under ${name}`}+ subject={`Failed to retrieve projects under ${name}`}error={projectsError}/></div>diff --git a/studio/components/interfaces/Organization/BillingSettingsV2/BillingAddress/BillingAddress.tsx b/studio/components/interfaces/Organization/BillingSettingsV2/BillingAddress/BillingAddress.tsxindex d1bf4e11422..c5235c0eb1a 100644--- a/studio/components/interfaces/Organization/BillingSettingsV2/BillingAddress/BillingAddress.tsx+++ b/studio/components/interfaces/Organization/BillingSettingsV2/BillingAddress/BillingAddress.tsx@@ -83,7 +83,7 @@ const BillingAddress = () => {{isError && (<AlertError- subject="Unable to retrieve organization customer profile"+ subject="Failed to retrieve organization customer profile"error={error as any}/>)}diff --git a/studio/components/interfaces/Organization/BillingSettingsV2/BillingBreakdown/BillingBreakdown.constants.ts b/studio/components/interfaces/Organization/BillingSettingsV2/BillingBreakdown/BillingBreakdown.constants.tsnew file mode 100644index 00000000000..4080e2dee5d--- /dev/null+++ b/studio/components/interfaces/Organization/BillingSettingsV2/BillingBreakdown/BillingBreakdown.constants.ts@@ -0,0 +1,104 @@+import { PricingMetric } from 'data/analytics/org-daily-stats-query'++export const USAGE_APPROACHING_THRESHOLD = 0.8++export interface Metric {+ key: string+ name: string+ units: string+ anchor: string+ // metric?: string+ category: string+ unitName: string+}++export const BILLING_BREAKDOWN_METRICS: Metric[] = [+ {+ key: PricingMetric.DATABASE_SIZE,+ name: 'Database space',+ units: 'bytes',+ anchor: 'dbSize',+ category: 'Database',+ unitName: 'GB',+ },+ {+ key: PricingMetric.EGRESS,+ name: 'Egress',+ units: 'bytes',+ anchor: 'egress',+ category: 'Database',+ unitName: 'GB',+ },+ {+ key: PricingMetric.MONTHLY_ACTIVE_USERS,+ name: 'Active users',+ units: 'absolute',+ anchor: 'mau',+ // metric: 'MONTHLY_ACTIVE_USERS',+ category: 'Authentication',+ unitName: 'MAU',+ },+ {+ key: PricingMetric.MONTHLY_ACTIVE_SSO_USERS,+ name: 'Active SSO users',+ units: 'absolute',+ anchor: 'mauSso',+ // metric: 'MONTHLY_ACTIVE_SSO_USERS',+ category: 'Authentication',+ unitName: 'MAU',+ },+ {+ key: PricingMetric.STORAGE_SIZE,+ name: 'Storage space',+ units: 'bytes',+ anchor: 'storageSize',+ // metric: 'STORAGE_SIZE',+ category: 'Storage',+ unitName: 'GB',+ },+ {+ key: PricingMetric.STORAGE_IMAGES_TRANSFORMED,+ name: 'Storage Image Transformations',+ units: 'absolute',+ anchor: 'storageImageTransformations',+ // metric: 'STORAGE_IMAGES_TRANSFORMED',+ category: 'Storage',+ unitName: 'image',+ },+ {+ key: PricingMetric.REALTIME_PEAK_CONNECTIONS,+ name: 'Realtime peak connections',+ units: 'absolute',+ anchor: 'realtimePeakConnections',+ // metric: 'REALTIME_PEAK_CONNECTIONS',+ category: 'Realtime',+ unitName: 'connection',+ },+ {+ key: PricingMetric.REALTIME_MESSAGE_COUNT,+ name: 'Realtime messages',+ units: 'absolute',+ anchor: 'realtimeMessageCount',+ // metric: 'REALTIME_MESSAGE_COUNT',+ category: 'Realtime',+ unitName: 'message',+ },+ {+ key: PricingMetric.FUNCTION_INVOCATIONS,+ name: 'Edge Function invocations',+ units: 'absolute',+ anchor: 'funcInvocations',+ // metric: 'FUNCTION_INVOCATIONS',+ category: 'Edge Functions',+ unitName: 'invocation',+ },+ {+ key: PricingMetric.FUNCTION_COUNT,+ name: 'Edge Functions',+ units: 'absolute',+ anchor: 'funcCount',+ // metric: 'FUNCTION_COUNT',+ category: 'Edge Functions',+ unitName: 'function',+ },+]diff --git a/studio/components/interfaces/Organization/BillingSettingsV2/BillingBreakdown/BillingBreakdown.tsx b/studio/components/interfaces/Organization/BillingSettingsV2/BillingBreakdown/BillingBreakdown.tsxnew file mode 100644index 00000000000..5a5cf4eed52--- /dev/null+++ b/studio/components/interfaces/Organization/BillingSettingsV2/BillingBreakdown/BillingBreakdown.tsx@@ -0,0 +1,152 @@+import dayjs from 'dayjs'++import { useParams } from 'common'+import {+ ScaffoldSection,+ ScaffoldSectionContent,+ ScaffoldSectionDetail,+} from 'components/layouts/Scaffold'+import AlertError from 'components/ui/AlertError'+import ShimmeringLoader from 'components/ui/ShimmeringLoader'+import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'+import { useOrgUsageQuery } from 'data/usage/org-usage-query'+import { Alert, Button } from 'ui'+import { BILLING_BREAKDOWN_METRICS } from './BillingBreakdown.constants'+import BillingMetric from './BillingMetric'+import UpcomingInvoice from './UpcomingInvoice'++const BillingBreakdown = () => {+ const { slug: orgSlug } = useParams()+ const {+ data: usage,+ error: usageError,+ isLoading: isLoadingUsage,+ isError: isErrorUsage,+ isSuccess: isSuccessUsage,+ } = useOrgUsageQuery({ orgSlug })+ const {+ data: subscription,+ error: subscriptionError,+ isLoading: isLoadingSubscription,+ isError: isErrorSubscription,+ isSuccess: isSuccessSubscription,+ } = useOrgSubscriptionQuery({ orgSlug })++ const currentPlan = subscription?.plan+ const isUsageBillingEnabled = subscription?.usage_billing_enabled+ const billingCycleStart = dayjs.unix(subscription?.current_period_start ?? 0).utc()+ const billingCycleEnd = dayjs.unix(subscription?.current_period_end ?? 0).utc()++ const hasExceededAnyLimits =+ !isUsageBillingEnabled &&+ usage?.usages+ .map(+ (metric) =>+ !metric.unlimited && !metric.capped && metric.usage > (metric?.pricing_free_units ?? 0)+ )+ .includes(true)++ return (+ <ScaffoldSection>+ <ScaffoldSectionDetail>+ <div className="sticky space-y-6 top-16">+ <p className="text-base">Billing breakdown</p>+ <p className="text-sm text-scale-1000">+ Current billing cycle: {billingCycleStart.format('MMM DD')} -{' '}+ {billingCycleEnd.format('MMM DD')}+ </p>+ </div>+ </ScaffoldSectionDetail>+ <ScaffoldSectionContent>+ {isLoadingSubscription && (+ <div className="space-y-2">+ <ShimmeringLoader />+ <ShimmeringLoader className="w-3/4" />+ <ShimmeringLoader className="w-1/2" />+ </div>+ )}++ {isErrorSubscription && (+ <AlertError subject="Failed to retrieve subscription" error={subscriptionError} />+ )}++ {isSuccessSubscription && (+ <>+ <p className="text-sm">Included usage summary</p>+ {isUsageBillingEnabled ? (+ <p className="text-sm text-scale-1000">+ Your plan includes a limited amount of usage. If the usage on your project exceeds+ these quotas, your subscription will be charged for the overages. It may take up to+ 24 hours for usage stats to update.+ </p>+ ) : (+ <p className="text-sm text-scale-1000">+ Your plan includes a limited amount of usage. If the usage on your project exceeds+ these quotas, you may experience restrictions, as you are currently not billed for+ overages. It may take up to 24 hours for usage stats to update.+ </p>+ )}++ {hasExceededAnyLimits && (+ <Alert+ withIcon+ variant="danger"+ title="Your project's usage has exceeded its included quota"+ actions={[+ <Button key="upgrade-button" type="default" className="ml-8" onClick={() => {}}>+ {currentPlan?.id === 'free' ? 'Upgrade plan' : 'Change spend cap'}+ </Button>,+ ]}+ >+ Your project can become unresponsive or enter read only mode.{' '}+ {currentPlan?.id === 'free'+ ? 'Please upgrade to the Pro plan to ensure that your project remains available.'+ : 'Please disable spend cap to ensure that your project remains available.'}+ </Alert>+ )}++ {isLoadingUsage && (+ <div className="space-y-2">+ <ShimmeringLoader />+ <ShimmeringLoader className="w-3/4" />+ <ShimmeringLoader className="w-1/2" />+ </div>+ )}++ {isErrorUsage && (+ <AlertError subject="Failed to retrieve usage data" error={usageError} />+ )}++ {isSuccessUsage && (+ <div className="grid grid-cols-12">+ {BILLING_BREAKDOWN_METRICS.map((metric, i) => {+ return (+ <BillingMetric+ idx={i}+ key={metric.key}+ slug={orgSlug}+ metric={metric}+ usage={usage}+ subscription={subscription}+ />+ )+ })}+ </div>+ )}++ <p className="!mt-10 text-sm">Upcoming cost for next invoice</p>+ <p className="text-sm text-scale-1000">+ The following table shows your upcoming costs. Depending on your usage, the final+ amount may vary. Next invoice on{' '}+ <span className="text-scale-1100">{billingCycleEnd.format('MMM DD, YYYY')}</span>.+ </p>++ <UpcomingInvoice slug={orgSlug} />+ </>+ )}+ </ScaffoldSectionContent>+ </ScaffoldSection>+ )+}++export default BillingBreakdowndiff --git a/studio/components/interfaces/Organization/BillingSettingsV2/BillingBreakdown/BillingMetric.tsx b/studio/components/interfaces/Organization/BillingSettingsV2/BillingBreakdown/BillingMetric.tsxnew file mode 100644index 00000000000..3d8aa145683--- /dev/null+++ b/studio/components/interfaces/Organization/BillingSettingsV2/BillingBreakdown/BillingMetric.tsx@@ -0,0 +1,193 @@+import clsx from 'clsx'+import Link from 'next/link'+import * as Tooltip from '@radix-ui/react-tooltip'++import { BILLING_BREAKDOWN_METRICS } from 'components/interfaces/BillingV2/Subscription/Subscription.constants'+import { Button, IconAlertTriangle, IconChevronRight, IconInfo } from 'ui'+import { Metric, USAGE_APPROACHING_THRESHOLD } from './BillingBreakdown.constants'+import { OrgSubscription } from 'data/subscriptions/org-subscription-query'+import { OrgUsageResponse } from 'data/usage/org-usage-query'+import { useOrgSettingsPageStateSnapshot } from 'state/organization-settings'+import SparkBar from 'components/ui/SparkBar'++export interface BillingMetricProps {+ idx: number+ slug?: string+ metric: Metric+ usage: OrgUsageResponse+ subscription: OrgSubscription+}++const BillingMetric = ({ idx, slug, metric, usage, subscription }: BillingMetricProps) => {+ const snap = useOrgSettingsPageStateSnapshot()+ const usageMeta = usage.usages.find((x) => x.metric === metric.key)+ const usageRatio =+ typeof usageMeta !== 'number'+ ? (usageMeta?.usage ?? 0) / (usageMeta?.pricing_free_units ?? 0)+ : 0++ const usageFee = subscription?.usage_fees?.find((item) => item.metric === metric.key)+ const isUsageBillingEnabled = subscription?.usage_billing_enabled+ const largeNumberFormatter = new Intl.NumberFormat('en-US', { maximumFractionDigits: 0 })++ const hasLimit = !!usageMeta?.unlimited === false+ const isApproachingLimit = hasLimit && usageRatio >= USAGE_APPROACHING_THRESHOLD+ const isExceededLimit = hasLimit && usageRatio >= 1++ const usageCurrentLabel =+ metric.units === 'bytes' ? `${usageMeta?.usage ?? 0} GB` : usageMeta?.usage?.toLocaleString()+ const usageLimitLabel =+ metric.units === 'bytes'+ ? `${usageMeta?.pricing_free_units ?? 0} GB`+ : usageMeta?.pricing_free_units?.toLocaleString()+ const percentageLabel = `${(usageRatio * 100).toFixed(2)}%`+ const usageLabel = `${usageCurrentLabel} ${hasLimit ? `of ${usageLimitLabel}` : ''}`++ return (+ <div+ className={clsx(+ 'col-span-12 md:col-span-6 space-y-4 py-4 border-scale-400',+ idx % 2 === 0 ? 'md:border-r md:pr-4' : 'md:pl-4',+ idx < BILLING_BREAKDOWN_METRICS.length - 3 && 'border-b'+ )}+ >+ <div className="flex items-center justify-between">+ <Link href={`/org/${slug}/settings/billing/usage#${metric.anchor}`}>+ <a>+ <div className="group flex items-center space-x-2">+ <p className="text-sm text-scale-1100 group-hover:text-scale-1200 transition cursor-pointer">+ {metric.name}+ </p>+ <IconChevronRight+ strokeWidth={1.5}+ size={16}+ className="transition opacity-0 -translate-x-2 group-hover:opacity-100 group-hover:translate-x-0"+ />+ </div>+ </a>+ </Link>++ {isUsageBillingEnabled && usageFee && (+ <Tooltip.Root delayDuration={0}>+ <Tooltip.Trigger>+ <div className="flex items-center">+ <IconInfo size={14} strokeWidth={2} className="hover:text-scale-1000" />+ </div>+ </Tooltip.Trigger>+ <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(' ')}+ >+ <div className="text-xs text-scale-1200">+ {usageFee.pricingStrategy === 'UNIT' ? (+ <div>+ <p>+ {largeNumberFormatter.format(usageFee.pricingOptions.freeUnits)}{' '}+ {metric.unitName} included+ </p>+ <p>+ then ${usageFee.pricingOptions.perUnitPrice} per {metric.unitName}+ </p>+ </div>+ ) : usageFee.pricingStrategy === 'PACKAGE' ? (+ <div>+ <p>+ {largeNumberFormatter.format(usageFee.pricingOptions.freeUnits)} included+ </p>++ <p>+ then ${usageFee.pricingOptions.packagePrice} per{' '}+ {largeNumberFormatter.format(usageFee.pricingOptions.packageSize!)}+ </p>+ </div>+ ) : null}+ </div>+ </div>+ </Tooltip.Content>+ </Tooltip.Portal>+ </Tooltip.Root>+ )}++ {!isUsageBillingEnabled && usageRatio >= USAGE_APPROACHING_THRESHOLD && (+ <Tooltip.Root delayDuration={0}>+ <Tooltip.Trigger asChild>+ {isExceededLimit && !isUsageBillingEnabled ? (+ <div className="flex items-center space-x-2 min-w-[115px] cursor-help">+ <IconAlertTriangle size={14} strokeWidth={2} className="text-red-900" />+ <p className="text-sm text-red-900">Exceeded limit</p>+ </div>+ ) : isApproachingLimit && !isUsageBillingEnabled ? (+ <div className="flex items-center space-x-2 min-w-[115px] cursor-help">+ <IconAlertTriangle size={14} strokeWidth={2} className="text-amber-900" />+ <p className="text-sm text-amber-900">Approaching limit</p>+ </div>+ ) : null}+ </Tooltip.Trigger>++ <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(' ')}+ >+ <p className="text-xs text-scale-1200">+ Exceeding your plans included usage will lead to restrictions to your project.+ </p>+ <p className="text-xs text-scale-1200">+ Upgrade to a usage-based plan or disable the spend cap to avoid restrictions.+ </p>+ </div>+ </Tooltip.Content>+ </Tooltip.Portal>+ </Tooltip.Root>+ )}+ </div>+ {usageMeta?.available_in_plan ? (+ <SparkBar+ type="horizontal"+ max={usageMeta.pricing_free_units || 1}+ value={usageMeta.usage ?? 0}+ barClass={+ !hasLimit && usageMeta.usage > 0+ ? 'bg-scale-1100'+ : isExceededLimit && !isUsageBillingEnabled+ ? 'bg-red-900'+ : isApproachingLimit && !isUsageBillingEnabled+ ? 'bg-amber-900'+ : 'bg-scale-1100'+ }+ bgClass="bg-gray-300 dark:bg-gray-600"+ labelBottom={usageLabel}+ labelBottomClass="!text-scale-1000"+ labelTop={hasLimit ? percentageLabel : undefined}+ labelTopClass={+ !hasLimit+ ? ''+ : isExceededLimit && !isUsageBillingEnabled+ ? '!text-red-900'+ : isApproachingLimit && !isUsageBillingEnabled+ ? '!text-amber-900'+ : ''+ }+ />+ ) : (+ <div className="flex items-center justify-between flex-grow">+ <p className="text-sm text-scale-1000">Unavailable in your plan</p>+ <Button type="default" onClick={() => snap.setPanelKey('subscriptionPlan')}>+ Upgrade+ </Button>+ </div>+ )}+ </div>+ )+}++export default BillingMetricdiff --git a/studio/components/interfaces/Organization/BillingSettingsV2/BillingBreakdown/UpcomingInvoice.tsx b/studio/components/interfaces/Organization/BillingSettingsV2/BillingBreakdown/UpcomingInvoice.tsxnew file mode 100644index 00000000000..bb2e2ffb5f4--- /dev/null+++ b/studio/components/interfaces/Organization/BillingSettingsV2/BillingBreakdown/UpcomingInvoice.tsx@@ -0,0 +1,118 @@+import clsx from 'clsx'+import { partition } from 'lodash'++import AlertError from 'components/ui/AlertError'+import ShimmeringLoader from 'components/ui/ShimmeringLoader'+import { useOrgUpcomingInvoiceQuery } from 'data/invoices/org-invoice-upcoming-query'+import { Button, Collapsible, IconChevronRight } from 'ui'+import { useState } from 'react'++export interface UpcomingInvoiceProps {+ slug?: string+}++const UpcomingInvoice = ({ slug }: UpcomingInvoiceProps) => {+ const {+ data: upcomingInvoice,+ error: error,+ isLoading,+ isError,+ isSuccess,+ } = useOrgUpcomingInvoiceQuery({ orgSlug: slug })++ const [showUsageFees, setShowUsageFees] = useState(false)+ const [usageFees, fixedFees] = partition(upcomingInvoice?.lines ?? [], (item) => item.usage_based)+ const totalUsageFees = Number(usageFees.reduce((a, b) => a + b.amount, 0).toFixed(2))++ return (+ <>+ {isLoading && (+ <div className="space-y-2">+ <ShimmeringLoader />+ <ShimmeringLoader className="w-3/4" />+ <ShimmeringLoader className="w-1/2" />+ </div>+ )}++ {isError && <AlertError subject="Failed to retrieve upcoming invoice" error={error} />}++ {isSuccess && (+ <table className="w-full">+ <thead>+ <tr className="border-b">+ <th className="py-2 font-normal text-left text-sm text-scale-1000 w-1/2">Item</th>+ <th className="py-2 font-normal text-left text-sm text-scale-1000">Count</th>+ <th className="py-2 font-normal text-left text-sm text-scale-1000">Unit price</th>+ <th className="py-2 font-normal text-right text-sm text-scale-1000">Price</th>+ </tr>+ </thead>+ <tbody>+ {fixedFees.map((item) => (+ <tr key={item.description} className="border-b">+ <td className="py-2 text-sm">{item.description ?? 'Unknown'}</td>+ <td className="py-2 text-sm">{item.quantity}</td>+ <td className="py-2 text-sm">+ {item.unit_price === 0 ? 'FREE' : `$${item.unit_price}`}+ </td>+ <td className="py-2 text-sm text-right">${item.amount}</td>+ </tr>+ ))}+ </tbody>++ {usageFees.length > 0 && (+ <Collapsible asChild open={showUsageFees} onOpenChange={setShowUsageFees}>+ <tbody>+ <Collapsible.Trigger asChild>+ <tr className="border-b cursor-pointer" style={{ WebkitAppearance: 'initial' }}>+ <td className="py-2 text-sm flex items-center space-x-2">+ <Button+ type="text"+ className="!px-1"+ icon={+ <IconChevronRight+ className={clsx('transition', showUsageFees && 'rotate-90')}+ />+ }+ />+ <p>Usage items</p>+ </td>+ <td />+ <td />+ <td className="text-sm text-right">+ {!showUsageFees ? `$${totalUsageFees}` : null}+ </td>+ </tr>+ </Collapsible.Trigger>+ <Collapsible.Content asChild>+ <>+ {usageFees.map((fee) => (+ <tr className="border-b" key={fee.description}>+ <td className="py-2 text-sm pl-8">{fee.description}</td>+ <td className="py-2 text-sm"></td>+ <td className="py-2 text-sm">+ {fee.unit_price ? `$${fee.unit_price}` : null}+ </td>+ <td className="py-2 text-sm text-right">${fee.amount ?? 0}</td>+ </tr>+ ))}+ </>+ </Collapsible.Content>+ </tbody>+ </Collapsible>+ )}++ <tbody>+ <tr>+ <td className="py-2 text-sm">Total</td>+ <td className="py-2 text-sm" />+ <td className="py-2 text-sm" />+ <td className="py-2 text-sm text-right">${upcomingInvoice?.amount_total ?? 0}</td>+ </tr>+ </tbody>+ </table>+ )}+ </>+ )+}++export default UpcomingInvoicediff --git a/studio/components/interfaces/Organization/BillingSettingsV2/BillingSettings.tsx b/studio/components/interfaces/Organization/BillingSettingsV2/BillingSettings.tsxindex ec6f077faa4..45bbd30b529 100644--- a/studio/components/interfaces/Organization/BillingSettingsV2/BillingSettings.tsx+++ b/studio/components/interfaces/Organization/BillingSettingsV2/BillingSettings.tsx@@ -6,6 +6,7 @@ import CreditBalance from './CreditBalance'import PaymentMethods from './PaymentMethods/PaymentMethods'import Subscription from './Subscription/Subscription'import TaxID from './TaxID/TaxID'+import BillingBreakdown from './BillingBreakdown/BillingBreakdown'const BillingSettings = () => {return (@@ -49,6 +50,12 @@ const BillingSettings = () => {<ScaffoldContainer><TaxID /></ScaffoldContainer>++ <ScaffoldDivider />++ <ScaffoldContainer>+ <BillingBreakdown />+ </ScaffoldContainer></>)}diff --git a/studio/components/interfaces/Organization/BillingSettingsV2/CreditBalance.tsx b/studio/components/interfaces/Organization/BillingSettingsV2/CreditBalance.tsxindex 4b0b69c3bbb..25e255174a5 100644--- a/studio/components/interfaces/Organization/BillingSettingsV2/CreditBalance.tsx+++ b/studio/components/interfaces/Organization/BillingSettingsV2/CreditBalance.tsx@@ -47,7 +47,7 @@ const CreditBalance = () => {)}{isError && (- <AlertError subject="Unable to retrieve organization customer profile" error={error} />+ <AlertError subject="Failed to retrieve organization customer profile" error={error} />)}{isSuccess && (diff --git a/studio/components/interfaces/Organization/BillingSettingsV2/PaymentMethods/PaymentMethods.tsx b/studio/components/interfaces/Organization/BillingSettingsV2/PaymentMethods/PaymentMethods.tsxindex b7651127a8f..0cdc7c38da4 100644--- a/studio/components/interfaces/Organization/BillingSettingsV2/PaymentMethods/PaymentMethods.tsx+++ b/studio/components/interfaces/Organization/BillingSettingsV2/PaymentMethods/PaymentMethods.tsx@@ -78,7 +78,7 @@ const PaymentMethods = () => {)}{isError && (- <AlertError subject="Unable to retrieve payment methods" error={error as any} />+ <AlertError subject="Failed to retrieve payment methods" error={error as any} />)}{isSuccess && (diff --git a/studio/components/interfaces/Organization/BillingSettingsV2/TaxID/TaxID.tsx b/studio/components/interfaces/Organization/BillingSettingsV2/TaxID/TaxID.tsxindex c0c81f6d1c1..03a4f11088e 100644--- a/studio/components/interfaces/Organization/BillingSettingsV2/TaxID/TaxID.tsx+++ b/studio/components/interfaces/Organization/BillingSettingsV2/TaxID/TaxID.tsx@@ -151,7 +151,7 @@ const TaxID = () => {)}{isError && (- <AlertError error={error} subject="Unable to retrieve organization tax IDs" />+ <AlertError error={error} subject="Failed to retrieve organization tax IDs" />)}{isSuccess && (diff --git a/studio/components/interfaces/Organization/OAuthApps/OAuthApps.tsx b/studio/components/interfaces/Organization/OAuthApps/OAuthApps.tsxindex 79919216744..73505311f17 100644--- a/studio/components/interfaces/Organization/OAuthApps/OAuthApps.tsx+++ b/studio/components/interfaces/Organization/OAuthApps/OAuthApps.tsx@@ -75,7 +75,7 @@ const OAuthApps = () => {)}{isErrorPublishedApps && (- <AlertError className="mt-4" subject="Unable to retrieve published OAuth apps" />+ <AlertError className="mt-4" subject="Failed to retrieve published OAuth apps" />)}{createdApp !== undefined && (@@ -170,7 +170,7 @@ const OAuthApps = () => {</div>)}- {isErrorAuthorizedApps && <AlertError subject="Unable to retrieve authorized apps" />}+ {isErrorAuthorizedApps && <AlertError subject="Failed to retrieve authorized apps" />}{isSuccessAuthorizedApps && (<>diff --git a/studio/components/interfaces/Organization/Usage/Usage.tsx b/studio/components/interfaces/Organization/Usage/Usage.tsxindex e823c33df35..66fc550cd22 100644--- a/studio/components/interfaces/Organization/Usage/Usage.tsx+++ b/studio/components/interfaces/Organization/Usage/Usage.tsx@@ -74,7 +74,7 @@ const Usage = () => {{isErrorSubscription && (<AlertErrorclassName="w-full"- subject="Unable to retrieve usage data"+ subject="Failed to retrieve usage data"error={subscriptionError}/>)}diff --git a/studio/components/interfaces/Organization/Usage/UsageSection/AttributeUsage.tsx b/studio/components/interfaces/Organization/Usage/UsageSection/AttributeUsage.tsxindex e7ed1a006e3..4949823c4df 100644--- a/studio/components/interfaces/Organization/Usage/UsageSection/AttributeUsage.tsx+++ b/studio/components/interfaces/Organization/Usage/UsageSection/AttributeUsage.tsx@@ -86,7 +86,7 @@ const AttributeUsage = ({</div>)}- {isError && <AlertError subject="Unable to retrieve usage" error={error} />}+ {isError && <AlertError subject="Failed to retrieve usage data" error={error} />}{isSuccess && (<>diff --git a/studio/data/invoices/invoice-upcoming-query.ts b/studio/data/invoices/invoice-upcoming-query.tsindex fd3ca8c9b3a..daa5957c59a 100644--- a/studio/data/invoices/invoice-upcoming-query.ts+++ b/studio/data/invoices/invoice-upcoming-query.ts@@ -3,28 +3,12 @@ import { get } from 'lib/common/fetch'import { API_URL } from 'lib/constants'import { useCallback } from 'react'import { invoicesKeys } from './keys'+import { UpcomingInvoiceResponse } from './org-invoice-upcoming-query'export type UpcomingInvoiceVariables = {projectRef?: string}-export type UpcomingInvoiceResponse = {- amount_total: number- currency: string- customer_balance: number- subscription_id: string- billing_cycle_end: string- billing_cycle_start: string- lines: {- amount: number- description: string- period: { start: string; end: string }- quantity: number- unit_price: number- usage_based: boolean- }[]-}-export async function getUpcomingInvoice({ projectRef }: UpcomingInvoiceVariables,signal?: AbortSignaldiff --git a/studio/data/invoices/keys.ts b/studio/data/invoices/keys.tsindex 796874332de..f2ba9be09a5 100644--- a/studio/data/invoices/keys.ts+++ b/studio/data/invoices/keys.ts@@ -2,4 +2,6 @@ export const invoicesKeys = {overdueInvoices: () => ['invoices', 'overdue'] as const,upcomingPreview: (projectRef: string | undefined) =>['invoices', projectRef, 'upcoming-preview'] as const,+ orgUpcomingPreview: (projectRef: string | undefined) =>+ ['invoices', projectRef, 'upcoming-preview'] as const,}diff --git a/studio/data/invoices/org-invoice-upcoming-query.ts b/studio/data/invoices/org-invoice-upcoming-query.tsnew file mode 100644index 00000000000..96dad4c5190--- /dev/null+++ b/studio/data/invoices/org-invoice-upcoming-query.ts@@ -0,0 +1,73 @@+import { useQuery, useQueryClient, UseQueryOptions } from '@tanstack/react-query'+import { get } from 'lib/common/fetch'+import { API_URL } from 'lib/constants'+import { useCallback } from 'react'+import { invoicesKeys } from './keys'+import { ResponseError } from 'types'++// [Joshen] This can eventually superceded and overwrite invoice-upcoming-query once we completely move to org billing++export type UpcomingInvoiceVariables = {+ orgSlug?: string+}++export type UpcomingInvoiceResponse = {+ amount_total: number+ currency: string+ customer_balance: number+ subscription_id: string+ billing_cycle_end: string+ billing_cycle_start: string+ lines: {+ amount: number+ description: string+ period: { start: string; end: string }+ quantity: number+ unit_price: number+ usage_based: boolean+ }[]+}++export async function getUpcomingInvoice(+ { orgSlug }: UpcomingInvoiceVariables,+ signal?: AbortSignal+) {+ if (!orgSlug) throw new Error('orgSlug is required')++ const response = await get(`${API_URL}/organizations/${orgSlug}/billing/invoices/upcoming`, {+ signal,+ })+ if (response.error) throw response.error+ return response as UpcomingInvoiceResponse+}++export type UpcomingInvoiceData = Awaited<ReturnType<typeof getUpcomingInvoice>>+export type UpcomingInvoiceError = ResponseError++export const useOrgUpcomingInvoiceQuery = <TData = UpcomingInvoiceData>(+ { orgSlug }: UpcomingInvoiceVariables,+ {+ enabled = true,+ ...options+ }: UseQueryOptions<UpcomingInvoiceData, UpcomingInvoiceError, TData> = {}+) =>+ useQuery<UpcomingInvoiceData, UpcomingInvoiceError, TData>(+ invoicesKeys.orgUpcomingPreview(orgSlug),+ ({ signal }) => getUpcomingInvoice({ orgSlug }, signal),+ {+ enabled: enabled && typeof orgSlug !== 'undefined',+ ...options,+ }+ )++export const useOrgUpcomingInvoicePrefetch = ({ orgSlug }: UpcomingInvoiceVariables) => {+ const client = useQueryClient()++ return useCallback(() => {+ if (orgSlug) {+ client.prefetchQuery(invoicesKeys.orgUpcomingPreview(orgSlug), ({ signal }) =>+ getUpcomingInvoice({ orgSlug }, signal)+ )+ }+ }, [client, orgSlug])+}diff --git a/studio/pages/projects.tsx b/studio/pages/projects.tsxindex 883da26a021..8fe0df5780d 100644--- a/studio/pages/projects.tsx+++ b/studio/pages/projects.tsx@@ -32,7 +32,7 @@ const ProjectsPage: NextPageWithLayout = () => {{isError && (<div className="py-4 px-5">- <AlertError subject="Unable to retrieve organizations" />+ <AlertError subject="Failed to retrieve organizations" /></div>)}