mirror of
https://github.com/supabase/supabase.git
synced 2026-10-11 12:25:05 +03:00
* Clean up saving and loading org slug local storage logic, was for Nav V2 * fix useProjectByRef for branches --------- Co-authored-by: Alaister Young <a@alaisteryoung.com>
23 lines
757 B
TypeScript
23 lines
757 B
TypeScript
import { useIsLoggedIn, useParams } from 'common'
|
|
import { useOrganizationsQuery } from 'data/organizations/organizations-query'
|
|
import { useMemo } from 'react'
|
|
|
|
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)
|
|
|
|
return useMemo(() => {
|
|
return data?.find((org) => {
|
|
if (slug !== undefined) return org.slug === slug
|
|
if (selectedProject !== undefined) return org.id === selectedProject.organization_id
|
|
return undefined
|
|
})
|
|
}, [data, selectedProject, slug])
|
|
}
|