Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
prv-proton committed Jan 8, 2025
1 parent f876f05 commit cf243cb
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions frontend/src/hooks/useOrganization.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { apiRoutes } from '@/constants/routes'
import { useApiService } from '@/services/useApiService'
import { useQuery } from '@tanstack/react-query'
import { useCurrentUser } from './useCurrentUser'
import { roles } from '@/constants/roles'

export const useOrganization = (orgID, options) => {
const client = useApiService()
Expand Down Expand Up @@ -29,14 +30,24 @@ export const useOrganizationUser = (orgID, userID, options) => {

export const useOrganizationBalance = (orgID, options) => {
const client = useApiService()
const { hasRoles } = useCurrentUser()
const hasAccess = hasRoles(roles.government)

return useQuery({
queryKey: ['organization-balance', orgID],
queryFn: async () =>
orgID ? (await client.get(`/organizations/balances/${orgID}`)).data : {},
queryFn: async () => {
if (!hasAccess) {
return null
}
return orgID
? (await client.get(`/organizations/balances/${orgID}`)).data
: {}
},
enabled: hasAccess && !!orgID,
...options
})
}

export const useCurrentOrgBalance = (options) => {
const client = useApiService()

Expand Down

0 comments on commit cf243cb

Please sign in to comment.