Skip to content

Commit

Permalink
Allow specify a custom id to org's fetch method
Browse files Browse the repository at this point in the history
This fixes a weird case where the data of the currently connected
account could be loaded instead of the organization one.

Due to these account state changes, it's better to always specify the
id to the fetch method, but when not specified it will take it from the
state (note that, if the id is not set in the state, you will still
reproduce the aforementioned issue.
  • Loading branch information
elboletaire committed Oct 23, 2023
1 parent 54f7555 commit 31c8406
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ export const useOrganizationProvider = ({ id, organization }: OrganizationProvid
const { state, loading, setOrganization, loadError, updateError } = useOrganizationReducer(organization)

// fetches organization info, and sets it to the state
const fetch = () => {
loading(id)
return client.fetchAccountInfo(id).then(setOrganization).catch(loadError)
const fetch = (id?: string) => {
const identifier = id || state.id
loading(identifier)
return client.fetchAccountInfo(identifier).then(setOrganization).catch(loadError)
}

// updates organization info, and sets the new result to state
Expand All @@ -39,7 +40,7 @@ export const useOrganizationProvider = ({ id, organization }: OrganizationProvid
if (!id || !client || state.loading) return
if (state.loaded && areEqualHexStrings(state.id, id)) return

fetch()
fetch(id)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [state.organization, id, client, state.loading, state.loaded])

Expand Down

0 comments on commit 31c8406

Please sign in to comment.