Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

added project subscription hook

TzeYiing8992cf112704
diff --git a/studio/hooks/misc/useProjectSubscription.tsx b/studio/hooks/misc/useProjectSubscription.tsx
new file mode 100644
index 00000000000..4b9a2a553f4
--- /dev/null
+++ b/studio/hooks/misc/useProjectSubscription.tsx
@@ -0,0 +1,35 @@
+import { get } from 'lib/common/fetch'
+import { API_URL } from 'lib/constants'
+import useSWR from 'swr'
+
+interface Data {
+ tier: {
+ name: string
+ prod_id: string
+ key: 'FREE' | 'PRO' | 'PAYG'
+ unit_amount: number
+ }
+ addons: any[]
+ billing: {
+ billing_cycle_anchor: number
+ current_period_end: number
+ current_period_start: number
+ }
+}
+
+interface Handlers {
+ refresh: () => void
+}
+
+const useProjectSubscription = (projectRef: string): [Data | null, Handlers] => {
+ const { data, error, mutate } = useSWR<Data>(
+ projectRef ? `${API_URL}/projects/${projectRef}/subscription` : null,
+ get
+ )
+ const refresh = () => mutate()
+ if (!data) return [null, { refresh }]
+ if (error) return [null, { refresh }]
+ return [data, { refresh }]
+}
+
+export default useProjectSubscription