Files
supabase/apps/www/data/organizations.ts
Alaister Young bee86a9c63 feat: upgrade via pricing page (#28942)
* feat: upgrade via pricing page

* reinstall cmdk

* fix button size

* improve search & autoclose

* Update apps/www/lib/fetchWrapper.ts

Co-authored-by: Kevin Grüneberg <k.grueneberg1994@gmail.com>

* Update apps/www/lib/fetchWrapper.ts

Co-authored-by: Kevin Grüneberg <k.grueneberg1994@gmail.com>

* update telemetry events

---------

Co-authored-by: Kevin Grüneberg <k.grueneberg1994@gmail.com>
2024-08-28 21:43:00 +00:00

48 lines
1.0 KiB
TypeScript

import { components } from 'api-types'
import { useEffect, useState } from 'react'
import { API_URL } from '~/lib/constants'
import { get } from '~/lib/fetchWrapper'
export type Organization = components['schemas']['OrganizationResponse']
export function useOrganizations() {
const [organizations, setOrganizations] = useState<Organization[]>([])
const [isLoading, setIsLoading] = useState(true)
useEffect(() => {
let isMounted = true
const controller = new AbortController()
get(`${API_URL}/organizations`, { signal: controller.signal })
.then((res) => {
if (!res.ok) {
throw res
}
return res
})
.then((res) => res.json())
.then((data) => {
if (isMounted) {
setOrganizations(data)
setIsLoading(false)
}
})
.catch(() => {
// eat all errors
setIsLoading(false)
})
return () => {
isMounted = false
controller.abort()
}
}, [])
return {
organizations,
isLoading,
} as const
}