Skip to content
Prev Previous commit
Next Next commit
Use selector to get the organization Id
  • Loading branch information
BrunoQuaresma committed May 26, 2022
commit b42f3e9ea868fe4857b0bc8749b40d56c83a664a
6 changes: 3 additions & 3 deletions site/src/hooks/useOrganizationId.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useActor } from "@xstate/react"
import { useSelector } from "@xstate/react"
import { useContext } from "react"
import { selectOrgId } from "../xServices/auth/authSelectors"
import { XServiceContext } from "../xServices/StateContext"

export const useOrganizationId = (): string => {
const xServices = useContext(XServiceContext)
const [authState] = useActor(xServices.authXService)
const organizationId = authState.context.me?.organization_ids[0]
const organizationId = useSelector(xServices.authXService, selectOrgId)

if (!organizationId) {
throw new Error("No organization ID found")
Expand Down