mirror of
https://github.com/supabase/supabase.git
synced 2026-07-07 07:30:21 +08:00
* Move all studio files from /studio to /apps/studio. * Move studio specific prettier ignores. * Fix the ui references from studio. * Fix the css imports. * Fix all package.json issues. * Fix the prettier setup for the studio app. * Add .turbo folder to prettierignore. * Fix the github workflows.
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { useIsLoggedIn, useParams } from 'common'
|
|
import { useOrganizationsQuery } from 'data/organizations/organizations-query'
|
|
import { useMemo } from 'react'
|
|
|
|
import { LOCAL_STORAGE_KEYS } from 'lib/constants'
|
|
import { useProjectByRef } from './useSelectedProject'
|
|
|
|
export function useSelectedOrganization({ enabled = true } = {}) {
|
|
const isLoggedIn = useIsLoggedIn()
|
|
|
|
const { ref, slug } = useParams()
|
|
const { data } = useOrganizationsQuery({ enabled: isLoggedIn && enabled })
|
|
|
|
const selectedProject = useProjectByRef(ref)
|
|
|
|
const localStorageSlug = useMemo(() => {
|
|
return typeof window !== 'undefined'
|
|
? localStorage.getItem(LOCAL_STORAGE_KEYS.RECENTLY_VISITED_ORGANIZATION)
|
|
: null
|
|
}, [])
|
|
|
|
return useMemo(() => {
|
|
return data?.find((org) => {
|
|
if (slug !== undefined) return org.slug === slug
|
|
if (selectedProject !== undefined) return org.id === selectedProject.organization_id
|
|
if (localStorageSlug !== undefined) return org.slug === localStorageSlug
|
|
return undefined
|
|
})
|
|
}, [data, selectedProject, slug, localStorageSlug])
|
|
}
|