The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat: use subacription stats api
phamhieua5059426035b
diff --git a/studio/pages/new/[slug].tsx b/studio/pages/new/[slug].tsxindex dd98cd1a181..3ea5f5d5c1f 100644--- a/studio/pages/new/[slug].tsx+++ b/studio/pages/new/[slug].tsx@@ -10,7 +10,7 @@ import { observer } from 'mobx-react-lite'import { Button, Typography, Listbox, IconUsers, IconAlertCircle } from '@supabase/ui'import { API_URL } from 'lib/constants'-import { post } from 'lib/common/fetch'+import { post, get } from 'lib/common/fetch'import {PROVIDERS,REGIONS,@@ -37,6 +37,13 @@ interface StripeCustomer {error?: any}+interface SubscriptionStats {+ total_paid_projects: number+ total_free_projects: number+ total_pro_projects: number+ total_payg_projects: number+}+async function fetchStripeAccount(stripeCustomerId: string) {try {const customer = await post(`${API_URL}/stripe/customer`, {@@ -49,6 +56,16 @@ async function fetchStripeAccount(stripeCustomerId: string) {}}+async function fetchProfileSubscriptionStats() {+ try {+ const subscriptions = await get(`${API_URL}/profile/subscriptions`)+ if (subscriptions.error) throw subscriptions.error+ return subscriptions+ } catch (error: any) {+ return { error }+ }+}+export const PageLayout = () => {return <Wizard />}@@ -69,12 +86,15 @@ export const Wizard = observer(() => {const [passwordStrengthWarning, setPasswordStrengthWarning] = useState('')const [passwordStrengthScore, setPasswordStrengthScore] = useState(0)const [stripeCustomer, setStripeCustomer] = useState<StripeCustomer | undefined>(undefined)+ const [subscriptionStats, setSubscriptionStats] = useState<SubscriptionStats | undefined>(+ undefined+ )const organizations = values(toJS(app.organizations.list()))const currentOrg = organizations.find((o: any) => o.slug === slug)const stripeCustomerId = currentOrg?.stripe_customer_id- const totalFreeProjects = ui.profile?.total_free_projects ?? 0+ const totalFreeProjects = subscriptionStats?.total_free_projects ?? 0const freeProjectsLimit = ui.profile?.free_project_limit ?? DEFAULT_FREE_PROJECTS_LIMITconst isEmptyOrganizations = organizations.length <= 0@@ -95,11 +115,6 @@ export const Wizard = observer(() => {dbPricingPlan != '' &&(isSelectFreeTier || (!isSelectFreeTier && !isEmptyPaymentMethod))- const passwordErrorMessage =- dbPass != '' && passwordStrengthScore < DEFAULT_MINIMUM_PASSWORD_STRENGTH- ? 'You need a stronger password'- : undefined-const delayedCheckPasswordStrength = useRef(debounce((value) => checkPasswordStrength(value), 300)).current@@ -133,6 +148,17 @@ export const Wizard = observer(() => {}}, [stripeCustomerId])+ useEffect(() => {+ async function loadProfileSubscriptionStatsAsync() {+ const res = await fetchProfileSubscriptionStats()+ if (!res.error) {+ setSubscriptionStats(res)+ }+ }++ loadProfileSubscriptionStatsAsync()+ }, [])+function onProjectNameChange(e: any) {e.target.value = e.target.value.replace(/\./g, '')setProjectName(e.target.value)