From cf243cba130a758f782a1a09ec9b46bfe10a0b40 Mon Sep 17 00:00:00 2001 From: prv-proton Date: Tue, 7 Jan 2025 18:35:07 -0800 Subject: [PATCH] . --- frontend/src/hooks/useOrganization.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/frontend/src/hooks/useOrganization.js b/frontend/src/hooks/useOrganization.js index 2e095dfd6..b8a4c85b5 100644 --- a/frontend/src/hooks/useOrganization.js +++ b/frontend/src/hooks/useOrganization.js @@ -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() @@ -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()