The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Remove FE logic for calculating PAYG costs and refactor/simplify PAYG usage stats
Joshen Limf965e796a111
diff --git a/studio/components/interfaces/Billing/Billing.constants.ts b/studio/components/interfaces/Billing/Billing.constants.tsdeleted file mode 100644index 3e16e7b2138..00000000000--- a/studio/components/interfaces/Billing/Billing.constants.ts+++ /dev/null@@ -1,16 +0,0 @@-export const CANCELLATION_REASONS = [- 'Pricing',- "My project isn't getting traction",- 'Poor customer service',- 'Missing feature',- "I didn't see the value",- "Supabase didn't meet my needs",- 'Dashboard is too complicated',- 'Postgres is too complicated',- 'Problem not solved',- 'Bug issues',- 'I decided to use something else',- 'My work has finished/discontinued',- 'I’m migrating to/starting a new project',- 'None of the above',-]diff --git a/studio/components/interfaces/Billing/Billing.constants.tsx b/studio/components/interfaces/Billing/Billing.constants.tsxnew file mode 100644index 00000000000..e246a093ddd--- /dev/null+++ b/studio/components/interfaces/Billing/Billing.constants.tsx@@ -0,0 +1,74 @@+import { IconArchive, IconDatabase, IconKey } from 'ui'++export const CANCELLATION_REASONS = [+ 'Pricing',+ "My project isn't getting traction",+ 'Poor customer service',+ 'Missing feature',+ "I didn't see the value",+ "Supabase didn't meet my needs",+ 'Dashboard is too complicated',+ 'Postgres is too complicated',+ 'Problem not solved',+ 'Bug issues',+ 'I decided to use something else',+ 'My work has finished/discontinued',+ 'I’m migrating to/starting a new project',+ 'None of the above',+]++export const USAGE_BASED_PRODUCTS = [+ {+ title: 'Database',+ icon: <IconDatabase className="dark:text-scale-100" size={16} strokeWidth={2} />,+ features: [+ {+ key: 'db_size',+ attribute: 'total_db_size_bytes',+ title: 'Database space',+ units: 'bytes',+ costPerUnit: 0.125,+ },+ {+ key: 'db_egress',+ attribute: 'total_egress_modified',+ title: 'Database egress',+ units: 'bytes',+ costPerUnit: 0.09,+ },+ ],+ },+ {+ title: 'Auth',+ icon: <IconKey className="dark:text-scale-100" size={16} strokeWidth={2} />,+ features: [+ {+ key: 'monthly_active_users',+ attribute: 'total_auth_billing_period_mau',+ title: 'Monthly Active Users',+ units: 'absolute',+ costPerUnit: 0.00325,+ },+ ],+ },+ {+ title: 'Storage',+ icon: <IconArchive className="dark:text-scale-100" size={16} strokeWidth={2} />,+ features: [+ {+ key: 'storage_size',+ attribute: 'total_storage_size_bytes',+ title: 'Storage space',+ units: 'bytes',+ costPerUnit: 0.021,+ },+ {+ key: 'storage_egress',+ attribute: 'total_storage_egress',+ title: 'Storage egress',+ units: 'bytes',+ costPerUnit: 0.09,+ },+ ],+ },+]diff --git a/studio/components/interfaces/Billing/PAYGUsage/PAYGUsage.constants.ts b/studio/components/interfaces/Billing/PAYGUsage/PAYGUsage.constants.tsdeleted file mode 100644index 8bc29fce204..00000000000--- a/studio/components/interfaces/Billing/PAYGUsage/PAYGUsage.constants.ts+++ /dev/null@@ -1,48 +0,0 @@-import { ChargeableProduct } from './PAYGUsage.types'--export const chargeableProducts: ChargeableProduct[] = [- {- title: 'Database',- iconUrl: '/img/database.svg',- features: [- {- title: 'Database Size',- attribute: 'total_db_size_bytes',- costPerUnit: 0.125,- unitQuantity: 1000000000, // 1GB- pricingModel: 'max',- freeQuota: 8000000000, // 8GB- },- {- title: 'Database Egress',- attribute: 'total_egress_modified',- costPerUnit: 0.09,- unitQuantity: 1000000000, // 1GB- pricingModel: 'sum',- freeQuota: 50000000000, // 50GB- },- ],- },- {- title: 'Storage',- iconUrl: '/img/archive.svg',- features: [- {- title: 'Storage Size',- attribute: 'total_storage_size_bytes',- costPerUnit: 0.021,- unitQuantity: 1000000000, // 1GB- pricingModel: 'max',- freeQuota: 100000000000, // 100GB- },- {- title: 'Storage Egress',- attribute: 'total_storage_egress',- costPerUnit: 0.09,- unitQuantity: 1000000000, // 1GB- pricingModel: 'sum',- freeQuota: 200000000000, // 200GB- },- ],- },-]diff --git a/studio/components/interfaces/Billing/PAYGUsage/PAYGUsage.tsx b/studio/components/interfaces/Billing/PAYGUsage/PAYGUsage.tsxindex 2793853de46..7f8dc189b95 100644--- a/studio/components/interfaces/Billing/PAYGUsage/PAYGUsage.tsx+++ b/studio/components/interfaces/Billing/PAYGUsage/PAYGUsage.tsx@@ -1,14 +1,11 @@-import React, { FC } from 'react'+import { FC } from 'react'import dayjs from 'dayjs'import ChartHandler from 'components/to-be-cleaned/Charts/ChartHandler'-import { ChargeableProduct, PaygStats, ProductFeature } from './PAYGUsage.types'-import { deriveProductCost } from './PAYGUsage.utils'-import { chargeableProducts } from './PAYGUsage.constants'import { DATE_FORMAT } from 'lib/constants'+import { USAGE_BASED_PRODUCTS } from '../Billing.constants'interface Props {- paygStats: PaygStatsdateRange: {period_start: { date: string; time_period: string }period_end: { date: string; time_period: string }@@ -16,16 +13,14 @@ interface Props {}}-const PAYGUsage: FC<Props> = ({ paygStats, dateRange }) => {+const PAYGUsage: FC<Props> = ({ dateRange }) => {const startDate =dateRange.period_start.date ?? dayjs().utc().startOf('month').format(DATE_FORMAT)const endDate = dateRange.period_end.date ?? dayjs().utc().endOf('month').format(DATE_FORMAT)return (<div className="flex flex-col">- {chargeableProducts.map((product: ChargeableProduct) => {- const productCost = deriveProductCost(paygStats, product)-+ {USAGE_BASED_PRODUCTS.map((product) => {return (<divkey={product.title}@@ -36,21 +31,15 @@ const PAYGUsage: FC<Props> = ({ paygStats, dateRange }) => {<div className="flex items-center justify-between overflow-hidden rounded px-6 py-3"><div className="flex items-center space-x-3"><div className="flex h-8 w-8 items-center justify-center rounded bg-white">- <img width={'16'} src={product.iconUrl} />+ {product.icon}</div><h5 className="mb-0 font-medium">{product.title}</h5></div>- {product.title !== 'Authentication' && (- <div className="flex items-center space-x-1">- <p className="text-scale-1000">$</p>- <h4 className="text-lg m-0 font-medium">{productCost.toFixed(3)}</h4>- </div>- )}</div></div><div className="flex flex-col">- {product.features.map((feature: ProductFeature) => (+ {product.features.map((feature) => (<divkey={feature.title}className="border-panel-border-light dark:border-panel-border-dark relative border-t px-6 py-3"diff --git a/studio/components/interfaces/Billing/PAYGUsage/PAYGUsage.types.ts b/studio/components/interfaces/Billing/PAYGUsage/PAYGUsage.types.tsdeleted file mode 100644index 5f5c5159ea4..00000000000--- a/studio/components/interfaces/Billing/PAYGUsage/PAYGUsage.types.ts+++ /dev/null@@ -1,18 +0,0 @@-export interface ChargeableProduct {- title: string- iconUrl: string- features: ProductFeature[]-}--export interface ProductFeature {- title: string- attribute: string- costPerUnit: number- unitQuantity: number- pricingModel: PricingModel- freeQuota?: number-}--export type PaygStats = { [key: string]: { sum: number; max: number } }--export type PricingModel = 'sum' | 'max'diff --git a/studio/components/interfaces/Billing/PAYGUsage/PAYGUsage.utils.ts b/studio/components/interfaces/Billing/PAYGUsage/PAYGUsage.utils.tsdeleted file mode 100644index 3f12047e3b7..00000000000--- a/studio/components/interfaces/Billing/PAYGUsage/PAYGUsage.utils.ts+++ /dev/null@@ -1,39 +0,0 @@-import { get, maxBy, sum } from 'lodash'-import { ChargeableProduct, PaygStats, ProductFeature } from './PAYGUsage.types'--/**- *- * Derives the most appropriate cost- * depending on what kind of product feature we are displaying cost for.- *- * @param paygStats- * @param feature- *- * @returns number- */-export const deriveFeatureCost = (paygStats: PaygStats | undefined, feature: ProductFeature) => {- let rawUsage = paygStats?.[feature.attribute]?.[feature.pricingModel]-- /**- * Some features have a free quota- *- * Check there is included free quota,- * and remove free quota amount from the raw usage derived from paygStats- *- * if the number is negative, then Math.max should return 0- *- * todo: move this logic to backend @mildtomato- */- if (rawUsage && feature.freeQuota) {- rawUsage = Math.max(0, rawUsage - feature.freeQuota)- }-- const maximumValueOfTheMonth = rawUsage ?? 0-- return (maximumValueOfTheMonth / feature.unitQuantity) * feature.costPerUnit-}--export const deriveProductCost = (paygStats: any, product: ChargeableProduct) => {- const costs = product.features.map((feature) => deriveFeatureCost(paygStats, feature))- return sum(costs)-}diff --git a/studio/components/interfaces/Billing/Subscription/CostBreakdownRow.tsx b/studio/components/interfaces/Billing/Subscription/CostBreakdownRow.tsxindex 3cda875fd80..7e653328ced 100644--- a/studio/components/interfaces/Billing/Subscription/CostBreakdownRow.tsx+++ b/studio/components/interfaces/Billing/Subscription/CostBreakdownRow.tsx@@ -6,17 +6,17 @@ interface Props {amount: number | stringunitPrice: number | stringprice: number | string- freeQuota?: number+ note?: string}-const CostBreakdownRow: FC<Props> = ({ item, amount, unitPrice, price, freeQuota }) => {+const CostBreakdownRow: FC<Props> = ({ item, amount, unitPrice, price, note }) => {return (<div className="relative flex items-center border-t border-panel-border-light px-6 py-3 dark:border-panel-border-dark"><div className="flex w-[40%] items-center gap-3"><span className="text-sm">{item}</span>- {freeQuota && (+ {note && (<Badge color="scale">- <span className="text-xs text-scale-900">{`${freeQuota / 1000000000}GB included`}</span>+ <span className="text-xs text-scale-900">{note}</span></Badge>)}</div>diff --git a/studio/components/interfaces/Billing/Subscription/Subscription.tsx b/studio/components/interfaces/Billing/Subscription/Subscription.tsxindex 238ff63a606..fa33fe69405 100644--- a/studio/components/interfaces/Billing/Subscription/Subscription.tsx+++ b/studio/components/interfaces/Billing/Subscription/Subscription.tsx@@ -1,27 +1,23 @@import dayjs from 'dayjs'import { FC } from 'react'-import { sum } from 'lodash'import { useRouter } from 'next/router'import { Button, Loading } from 'ui'import * as Tooltip from '@radix-ui/react-tooltip'import { PermissionAction } from '@supabase/shared-types/out/constants'-import { checkPermissions, useStore, useFlag } from 'hooks'+import { checkPermissions, useStore, useFlag, useProjectUsage } from 'hooks'import { STRIPE_PRODUCT_IDS } from 'lib/constants'import { formatBytes } from 'lib/helpers'import { PRICING_TIER_PRODUCT_IDS } from 'lib/constants'-import { chargeableProducts } from '../PAYGUsage/PAYGUsage.constants'-import { PaygStats, ProductFeature } from '../PAYGUsage/PAYGUsage.types'-import { deriveFeatureCost, deriveProductCost } from '../PAYGUsage/PAYGUsage.utils'import CostBreakdownRow from './CostBreakdownRow'import { StripeSubscription } from './Subscription.types'import NoPermission from 'components/ui/NoPermission'+import { USAGE_BASED_PRODUCTS } from 'components/interfaces/Billing/Billing.constants'interface Props {project: anysubscription: StripeSubscription- paygStats: PaygStats | undefinedloading?: booleanshowProjectName?: booleancurrentPeriodStart: number@@ -31,7 +27,6 @@ interface Props {const Subscription: FC<Props> = ({project,subscription,- paygStats,loading = false,showProjectName = false,currentPeriodStart,@@ -40,6 +35,7 @@ const Subscription: FC<Props> = ({const { ui } = useStore()const router = useRouter()+ const { ref } = router.queryconst enablePermissions = useFlag('enablePermissions')const projectUpdateDisabled = useFlag('disableProjectCreationAndUpdate')@@ -48,6 +44,8 @@ const Subscription: FC<Props> = ({? checkPermissions(PermissionAction.BILLING_WRITE, 'stripe.subscriptions'): ui.selectedOrganization?.is_owner+ const { usage, isLoading: loadingUsage } = useProjectUsage(ref as string)+const isPayg = subscription?.tier.prod_id === STRIPE_PRODUCT_IDS.PAYGconst isEnterprise = subscription.tier.supabase_prod_id === PRICING_TIER_PRODUCT_IDS.ENTERPRISE@@ -56,15 +54,24 @@ const Subscription: FC<Props> = ({const basePlanCost = subscription?.tier.unit_amount / 100const deriveTotalCost = (): number => {- const totalAddOnCost = sum(addOns.map((addOn) => addOn.unit_amount / 100))- const totalUsageCost = isPayg- ? Number(sum(chargeableProducts.map((product) => deriveProductCost(paygStats, product))))- : 0+ const totalAddOnCost = addOns+ .map((addOn) => addOn.unit_amount / 100)+ .reduce((prev, current) => prev + current, 0)++ const totalUsageCost =+ usage === undefined+ ? 0+ : Object.keys(usage)+ .map((productKey) => {+ return usage[productKey].cost+ })+ .reduce((prev, current) => prev + current, 0)+return basePlanCost + totalAddOnCost + totalUsageCost}return (- <Loading active={loading}>+ <Loading active={loading || loadingUsage}><div className="mb-8 w-full overflow-hidden rounded border border-panel-border-light dark:border-panel-border-dark"><div className="bg-panel-body-light dark:bg-panel-body-dark"><div className="flex items-center justify-between px-6 pt-4">@@ -164,8 +171,8 @@ const Subscription: FC<Props> = ({<CostBreakdownRowitem="Base Plan"amount={1}- unitPrice={basePlanCost}- price={basePlanCost}+ unitPrice={basePlanCost.toFixed(2)}+ price={basePlanCost.toFixed(2)}/>{addOns.map((addOn) => (<CostBreakdownRow@@ -177,25 +184,40 @@ const Subscription: FC<Props> = ({/>))}{isPayg &&- chargeableProducts.map((product) =>- product.features.map((feature: ProductFeature) => {- const derivedCost = deriveFeatureCost(paygStats, feature)- const cost = derivedCost.toFixed(2)+ USAGE_BASED_PRODUCTS.map((product) => {+ return product.features.map((feature) => {+ const amount = usage?.[feature.key]?.usage ?? 0+ const limit = usage?.[feature.key]?.limit ?? 0+ const cost = (usage?.[feature.key]?.cost ?? 0).toFixed(2)+return (<CostBreakdownRow- key={feature.attribute}+ key={feature.key}item={feature.title}- freeQuota={feature.freeQuota}- amount={formatBytes(- paygStats?.[feature.attribute]?.[feature.pricingModel] ?? 0- )}- unitPrice={`${feature.costPerUnit}/GB`}+ amount={+ feature.units === 'bytes' ? formatBytes(amount) : amount.toLocaleString()+ }+ unitPrice={+ feature.units === 'bytes'+ ? `${feature.costPerUnit}/GB`+ : feature.costPerUnit+ }price={cost}+ note={+ feature.units === 'bytes'+ ? `${formatBytes(limit)} included`+ : `${limit.toLocaleString()} included`+ }/>)})- )}- <div className="relative flex items-center border-t border-panel-border-light px-6 py-3 dark:border-panel-border-dark">+ })}+ <div+ className={[+ 'relative flex items-center border-t px-6 py-3',+ 'border-panel-border-light dark:border-panel-border-dark',+ ].join(' ')}+ ><div className="w-[80%]"><p className="text-sm text-scale-1100">Estimated cost for {dayjs.unix(currentPeriodStart).utc().format('MMM D, YYYY')}{' '}diff --git a/studio/components/interfaces/Billing/index.ts b/studio/components/interfaces/Billing/index.tsindex 7dd9806e708..908cd2a7314 100644--- a/studio/components/interfaces/Billing/index.ts+++ b/studio/components/interfaces/Billing/index.ts@@ -12,7 +12,6 @@ import UpdateSuccess from './UpdateSuccess'import Invoices from './Invoices'export * from './Subscription/Subscription.types'-export * from './PAYGUsage/PAYGUsage.constants'export {PAYGUsage,Subscription,diff --git a/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.constants.tsx b/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.constants.tsxdeleted file mode 100644index c705721fab6..00000000000--- a/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.constants.tsx+++ /dev/null@@ -1,25 +0,0 @@-import { IconArchive, IconDatabase, IconKey } from 'ui'--export const usageBasedItems = [- {- title: 'Database',- icon: <IconDatabase className="dark:text-scale-100" size={16} strokeWidth={2} />,- features: [- { key: 'db_size', title: 'Database space', units: 'bytes' },- { key: 'db_egress', title: 'Database egress', units: 'bytes' },- ],- },- {- title: 'Auth',- icon: <IconKey className="dark:text-scale-100" size={16} strokeWidth={2} />,- features: [{ key: 'monthly_active_users', title: 'Monthly Active Users', units: 'absolute' }],- },- {- title: 'Storage',- icon: <IconArchive className="dark:text-scale-100" size={16} strokeWidth={2} />,- features: [- { key: 'storage_size', title: 'Storage space', units: 'bytes' },- { key: 'storage_egress', title: 'Storage egress', units: 'bytes' },- ],- },-]diff --git a/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.tsx b/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.tsxindex 6970d676909..531f40a9a40 100644--- a/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.tsx+++ b/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.tsx@@ -6,8 +6,8 @@ import { formatBytes } from 'lib/helpers'import { PRICING_TIER_PRODUCT_IDS, USAGE_APPROACHING_THRESHOLD } from 'lib/constants'import SparkBar from 'components/ui/SparkBar'import ShimmeringLoader from 'components/ui/ShimmeringLoader'-import { usageBasedItems } from './ProjectUsageBars.constants'import InformationBox from 'components/ui/InformationBox'+import { USAGE_BASED_PRODUCTS } from 'components/interfaces/Billing/Billing.constants'interface Props {projectRef?: string@@ -48,7 +48,7 @@ const ProjectUsage: FC<Props> = ({ projectRef }) => {<Loading active={isLoading}>{usage && (<div>- {usageBasedItems.map((product) => {+ {USAGE_BASED_PRODUCTS.map((product) => {const isExceededUsage =showUsageExceedMessage &&product.featuresdiff --git a/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.types.ts b/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.types.tsindex 7b419d8f0da..542264ebca6 100644--- a/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.types.ts+++ b/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.types.ts@@ -1,6 +1,7 @@export interface ResourceUsage {usage: numberlimit: number+ cost: number}export interface UsageStats {diff --git a/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageMinimal.tsx b/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageMinimal.tsxindex 94c38d4acc6..88859e5206b 100644--- a/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageMinimal.tsx+++ b/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageMinimal.tsx@@ -5,7 +5,7 @@ import { useProjectSubscription, useProjectUsage } from 'hooks'import { formatBytes } from 'lib/helpers'import { PRICING_TIER_PRODUCT_IDS, USAGE_APPROACHING_THRESHOLD } from 'lib/constants'import SparkBar from 'components/ui/SparkBar'-import { usageBasedItems } from './ProjectUsageBars.constants'+import { USAGE_BASED_PRODUCTS } from 'components/interfaces/Billing/Billing.constants'interface ProjectUsageMinimalProps {projectRef?: string@@ -23,7 +23,7 @@ const ProjectUsageMinimal: FC<ProjectUsageMinimalProps> = ({ projectRef, filterreturn <></>}- const product = usageBasedItems.find((item) => item.title === filter)+ const product = USAGE_BASED_PRODUCTS.find((item) => item.title === filter)if (!product) return <></>if (usageError || subscriptionError) {diff --git a/studio/hooks/queries/index.ts b/studio/hooks/queries/index.tsindex 53c6ca96435..b93e9618493 100644--- a/studio/hooks/queries/index.ts+++ b/studio/hooks/queries/index.ts@@ -5,7 +5,6 @@ export * from './useFreeProjectLimitCheck'export * from './usePermissions'export * from './useProfile'export * from './useProjectAuthConfig'-export * from './useProjectPaygStatistics'export * from './useProjectSettings'export * from './useProjectSubscription'export * from './useSubscriptionStats'diff --git a/studio/hooks/queries/useProjectPaygStatistics.ts b/studio/hooks/queries/useProjectPaygStatistics.tsdeleted file mode 100644index 3af268448ac..00000000000--- a/studio/hooks/queries/useProjectPaygStatistics.ts+++ /dev/null@@ -1,82 +0,0 @@-import dayjs from 'dayjs'-import useSWR from 'swr'-import { get as _get, maxBy } from 'lodash'-import { get } from 'lib/common/fetch'-import { API_URL, DATE_FORMAT, PRICING_TIER_PRODUCT_IDS } from 'lib/constants'-import { chargeableProducts } from 'components/interfaces/Billing'-import { PaygStats } from 'components/interfaces/Billing/PAYGUsage/PAYGUsage.types'--/**- * Get project payg statistics- *- * @param ref project reference- * @param tierProdId tier product supabase_prod_id- */-export function useProjectPaygStatistics(ref?: string, tierProdId?: string) {- const startDate = dayjs().utc().startOf('month').format(DATE_FORMAT)- const endDate = dayjs().utc().endOf('month').format(DATE_FORMAT)- const attributes =- 'total_egress,total_db_size_bytes,total_db_egress_bytes,total_storage_size_bytes,total_storage_egress'- const url = `${API_URL}/projects/${ref}/daily-stats?attribute=${attributes}&startDate=${encodeURIComponent(- startDate- )}&endDate=${encodeURIComponent(endDate)}&interval='1d'`- /**- * data is a dictionary- * {- * data: array,- * totalAverage: number,- * total: number,- * maximum: number,- * format: string,- * }- */- const { data, error } = useSWR<any>(- ref && tierProdId === PRICING_TIER_PRODUCT_IDS.PAYG ? url : null,- get- )- const anyError = data?.error || error-- return {- paygStats: anyError ? undefined : getPaygStats(data?.data),- error: anyError,- isLoading: !anyError && !data,- isError: !!anyError,- }-}--function getPaygStats(data: any): PaygStats {- const paygStats: any = {}- if (!data) return paygStats-- let dataModified: any = []- data.map((x: any) => {- dataModified.push({- ...x,- total_egress_modified:- (x.total_egress == undefined ? 0 : x.total_egress) -- (x.total_storage_egress == undefined ? 0 : x.total_storage_egress),- })- })-- chargeableProducts.forEach((product) => {- product.features.forEach((feature) => {- // calculate max- const max = _get(maxBy(dataModified, feature.attribute), feature.attribute) ?? 0-- // calculate sum- let sum = 0- dataModified.map((x: any) => {- const featureAttribute = x[feature.attribute] == undefined ? 0 : x[feature.attribute]- sum = sum + featureAttribute- })-- // set sum and max under attribute name- paygStats[feature.attribute] = {- sum,- max,- }- })- })-- return paygStats-}diff --git a/studio/pages/project/[ref]/settings/billing/index.tsx b/studio/pages/project/[ref]/settings/billing/index.tsxindex f1db9798a2a..116e2dedbab 100644--- a/studio/pages/project/[ref]/settings/billing/index.tsx+++ b/studio/pages/project/[ref]/settings/billing/index.tsx@@ -4,14 +4,13 @@ import { observer } from 'mobx-react-lite'import { Loading, IconArrowRight } from 'ui'import { Project, NextPageWithLayout } from 'types'-import { useProjectPaygStatistics, useProjectSubscription, useStore } from 'hooks'+import { useProjectSubscription, useStore } from 'hooks'import { STRIPE_PRODUCT_IDS, TIME_PERIODS_REPORTS, TIME_PERIODS_BILLING } from 'lib/constants'import { SettingsLayout } from 'components/layouts'import LoadingUI from 'components/ui/Loading'import OveragesBanner from 'components/ui/OveragesBanner/OveragesBanner'import DateRangePicker from 'components/to-be-cleaned/DateRangePicker'import { PAYGUsage, Subscription, Invoices } from 'components/interfaces/Billing'-import { PaygStats } from 'components/interfaces/Billing/PAYGUsage/PAYGUsage.types'import ProjectUsage from 'components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars'const ProjectBilling: NextPageWithLayout = () => {@@ -39,9 +38,6 @@ interface SettingsProps {const Settings: FC<SettingsProps> = ({ project }) => {const { ui } = useStore()- const projectTier = ui.selectedProject?.subscription_tier-- const [dateRange, setDateRange] = useState<any>()const {subscription,@@ -49,10 +45,9 @@ const Settings: FC<SettingsProps> = ({ project }) => {error,} = useProjectSubscription(ui.selectedProject?.ref)- const { paygStats }: { paygStats: PaygStats | undefined } = useProjectPaygStatistics(- ui.selectedProject?.ref,- subscription?.tier?.supabase_prod_id- )+ const [dateRange, setDateRange] = useState<any>()+ const projectTier = ui.selectedProject?.subscription_tier+ const isPayg = subscription?.tier?.prod_id === STRIPE_PRODUCT_IDS.PAYGuseEffect(() => {if (error) {@@ -74,7 +69,6 @@ const Settings: FC<SettingsProps> = ({ project }) => {loading={loading}project={project}subscription={subscription}- paygStats={paygStats}currentPeriodStart={subscription?.billing.current_period_start}currentPeriodEnd={subscription?.billing.current_period_end}/>@@ -86,7 +80,7 @@ const Settings: FC<SettingsProps> = ({ project }) => {</div></div></Loading>- ) : subscription?.tier?.prod_id === STRIPE_PRODUCT_IDS.PAYG ? (+ ) : isPayg ? (<div><div className="mb-4 flex items-center space-x-3"><DateRangePicker@@ -110,7 +104,7 @@ const Settings: FC<SettingsProps> = ({ project }) => {</div>)}</div>- {paygStats && dateRange && <PAYGUsage paygStats={paygStats} dateRange={dateRange} />}+ {dateRange && <PAYGUsage dateRange={dateRange} />}</div>) : (<ProjectUsage projectRef={project?.ref} />