diff --git a/studio/components/interfaces/Home/ProjectUsage.tsx b/studio/components/interfaces/Home/ProjectUsage.tsx index a0110d67924..a24898e965b 100644 --- a/studio/components/interfaces/Home/ProjectUsage.tsx +++ b/studio/components/interfaces/Home/ProjectUsage.tsx @@ -16,7 +16,7 @@ import { import Panel from 'components/ui/Panel' import ChartHandler from 'components/to-be-cleaned/Charts/ChartHandler' -import { ProjectUsageMinimal } from 'components/to-be-cleaned/Usage' +import { ProjectUsageMinimal } from 'components/ui/Usage' import { useFlag } from 'hooks' import { get } from 'lib/common/fetch' diff --git a/studio/components/to-be-cleaned/Usage.tsx b/studio/components/ui/Usage.tsx similarity index 69% rename from studio/components/to-be-cleaned/Usage.tsx rename to studio/components/ui/Usage.tsx index ef03f7914ca..64a49e0284a 100644 --- a/studio/components/to-be-cleaned/Usage.tsx +++ b/studio/components/ui/Usage.tsx @@ -1,12 +1,25 @@ -import React, { FC, useEffect, useState } from 'react' +import React, { FC, useEffect } from 'react' import useSWR from 'swr' import { Loading, Typography } from '@supabase/ui' import { useProjectSubscription, useStore } from 'hooks' import { API_URL, PRICING_TIER_PRODUCT_IDS } from 'lib/constants' -import { get, post } from 'lib/common/fetch' +import { get } from 'lib/common/fetch' import SparkBar from 'components/ui/SparkBar' +interface ApiUsageStats { + authUsers: string | null; + bucketSize: string | null; + dbSize: string | null; + dbTables: string | null; +} +interface UsageStats { + authUsers: number; + bucketSize: number; + dbSize: number; + dbTables: number; +} + const GB = 1000000000 const MB = 1000000 @@ -32,13 +45,13 @@ const usageLimits = { title: 'Database space', tiers: { free: { - description: (stats: any) => - `${(((stats?.dbSize || 0) / (500 * MB)) * 100).toFixed(2)} %`, - render: (stats: any) => { - const bytes: any = stats?.dbSize ? new Number(stats?.dbSize) : 0 + description: (stats: UsageStats) => + `${((stats.dbSize / (500 * MB)) * 100).toFixed(2)} %`, + render: (stats: UsageStats) => { + const bytes: number = stats.dbSize; const usage = { - gb: bytes / GB || 0, - mb: bytes / MB || 0, + gb: bytes / GB, + mb: bytes / MB, } return ( ) }, }, pro: { - description: (stats: any) => - `${(((stats?.dbSize || 0) / (8000 * MB)) * 100).toFixed(2)} %`, - render: (stats: any) => { - const bytes: any = stats?.dbSize ? new Number(stats?.dbSize) : 0 + description: (stats: UsageStats) => + `${((stats.dbSize / (8000 * MB)) * 100).toFixed(2)} %`, + render: (stats: UsageStats) => { + const bytes: number = stats.dbSize const usage = { - gb: bytes / GB || 0, - mb: bytes / MB || 0, + gb: bytes / GB, + mb: bytes / MB, } return ( ) @@ -85,29 +98,29 @@ const usageLimits = { title: 'Users', tiers: { free: { - description: (stats: any) => `${(((stats?.authUsers || 0) / 10000) * 100).toFixed(2)}%`, - render: (stats: any) => ( + description: (stats: UsageStats) => `${((stats.authUsers / 10000) * 100).toFixed(2)}%`, + render: (stats: UsageStats) => ( ), }, pro: { - description: (stats: any) => - `${(((stats?.authUsers || 0) / 100000) * 100).toFixed(2)}%`, - render: (stats: any) => ( + description: (stats: UsageStats) => + `${((stats.authUsers / 100000) * 100).toFixed(2)}%`, + render: (stats: UsageStats) => ( ), }, @@ -117,11 +130,11 @@ const usageLimits = { title: 'Auth confirmation emails', tiers: { free: { - description: () => `${new Number(1000).toLocaleString()}/month`, + description: () => `${Number(1000).toLocaleString()}/month`, render: null, }, pro: { - description: () => `${new Number(30000).toLocaleString()}/month`, + description: () => `${Number(30000).toLocaleString()}/month`, render: null, }, }, @@ -136,38 +149,34 @@ const usageLimits = { title: 'Storage space', tiers: { free: { - description: (stats: any) => - `${(((stats?.bucketSize || 0) / (1 * GB)) * 100).toFixed(2)}%`, - render: (stats: any) => ( + description: (stats: UsageStats) => + `${((stats.bucketSize / (1 * GB)) * 100).toFixed(2)}%`, + render: (stats: UsageStats) => ( ), }, pro: { - description: (stats: any) => - `${(((stats?.bucketSize || 0) / (100 * GB)) * 100).toFixed(2)}%`, - render: (stats: any) => ( + description: (stats: UsageStats) => + `${((stats.bucketSize / (100 * GB)) * 100).toFixed(2)}%`, + render: (stats: UsageStats) => ( ), }, @@ -177,11 +186,11 @@ const usageLimits = { title: 'Transfer limits', tiers: { free: { - description: () => `${new Number(2).toLocaleString()} GB`, + description: () => `${Number(2).toLocaleString()} GB`, render: () => {}, }, pro: { - description: () => `${new Number(200).toLocaleString()} GB`, + description: () => `${Number(200).toLocaleString()} GB`, render: () => {}, }, }, @@ -190,7 +199,12 @@ const usageLimits = { }, } -const ProjectUsage: FC = ({ projectRef, subscription_id }) => { +interface ProjectUsageProps { + projectRef?: string; + subscription_id?: string; +} + +const ProjectUsage: FC = ({ projectRef, subscription_id }) => { const { ui } = useStore() const { data: stats, error: usageError } = useSWR(`${API_URL}/projects/${projectRef}/usage`, get) const { subscription, isLoading: loading, error } = useProjectSubscription(projectRef) @@ -268,9 +282,19 @@ const ProjectUsage: FC = ({ projectRef, subscription_id }) => { export default ProjectUsage -export const ProjectUsageMinimal: FC = ({ projectRef, subscription_id, filter }) => { - const { data: stats, error: usageError } = useSWR(`${API_URL}/projects/${projectRef}/usage`, get) +interface ProjectUsageMinimalProps extends ProjectUsageProps { + filter: string; +} + +export const ProjectUsageMinimal: FC = ({ projectRef, subscription_id, filter }) => { + const { data: apiStats, error: usageError } = useSWR(`${API_URL}/projects/${projectRef}/usage`, get) const { subscription, isLoading: loading, error } = useProjectSubscription(projectRef) + const stats: UsageStats = { + authUsers: Number(apiStats?.authUsers), + bucketSize: Number(apiStats?.bucketSize), + dbSize: Number(apiStats?.dbSize), + dbTables: Number(apiStats?.dbTables) + } if (subscription?.tier?.supabase_prod_id === PRICING_TIER_PRODUCT_IDS.PAYG) { return <> diff --git a/studio/pages/project/[ref]/settings/billing/index.tsx b/studio/pages/project/[ref]/settings/billing/index.tsx index 7239867bb1a..dbe40bbb4c6 100644 --- a/studio/pages/project/[ref]/settings/billing/index.tsx +++ b/studio/pages/project/[ref]/settings/billing/index.tsx @@ -9,9 +9,10 @@ import { SettingsLayout } from 'components/layouts' import LoadingUI from 'components/ui/Loading' import { PAYGUsage, Subscription, Invoices } from 'components/interfaces/Billing' -import ProjectUsage from 'components/to-be-cleaned/Usage' +import ProjectUsage from 'components/ui/Usage' import DateRangePicker from 'components/to-be-cleaned/DateRangePicker' import { PaygStats } from 'components/interfaces/Billing/PAYGUsage/PAYGUsage.types' +import { Project } from '../../../../../types' type ProjectBillingProps = {} & any const ProjectBilling: FC = ({ store }) => { @@ -32,7 +33,7 @@ const ProjectBilling: FC = ({ store }) => { export default withAuth(observer(ProjectBilling)) type SettingsProps = { - project: any + project?: Project } const Settings: FC = ({ project }) => { const { ui } = useStore() @@ -108,7 +109,7 @@ const Settings: FC = ({ project }) => { {paygStats && } ) : ( - + )}

Invoices

diff --git a/studio/pages/project/[ref]/settings/database.tsx b/studio/pages/project/[ref]/settings/database.tsx index 41e0f78b40b..808f9aaa6b1 100644 --- a/studio/pages/project/[ref]/settings/database.tsx +++ b/studio/pages/project/[ref]/settings/database.tsx @@ -18,7 +18,7 @@ import { API_URL, DEFAULT_MINIMUM_PASSWORD_STRENGTH, TIME_PERIODS_INFRA } from ' import { SettingsLayout } from 'components/layouts' import PasswordStrengthBar from 'components/ui/PasswordStrengthBar' import Panel from 'components/ui/Panel' -import { ProjectUsageMinimal } from 'components/to-be-cleaned/Usage' +import { ProjectUsageMinimal } from 'components/ui/Usage' import DateRangePicker from 'components/to-be-cleaned/DateRangePicker' import ChartHandler from 'components/to-be-cleaned/Charts/ChartHandler' @@ -50,7 +50,7 @@ export default withAuth(observer(ProjectSettings)) const Usage: FC = ({ project }) => { const [dateRange, setDateRange] = useState(undefined) const router = useRouter() - const { ref } = router.query + const ref = router.query.ref as string; return ( <>