-
Notifications
You must be signed in to change notification settings - Fork 18
/
useMemberTenantHoldings.js
25 lines (18 loc) · 1.13 KB
/
useMemberTenantHoldings.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { useMemo } from 'react';
import { useInstanceHoldingsQuery } from '../../providers';
import useConsortiumHoldings from '../useConsortiumHoldings';
import { hasMemberTenantPermission } from '../../utils';
const useMemberTenantHoldings = (instance, tenantId, userTenantPermissions) => {
const canViewHoldings = hasMemberTenantPermission('inventory-storage.holdings.collection.get', tenantId, userTenantPermissions);
const { holdingsRecords: expandedHoldings, isLoading: isExpandedHoldingsLoading } = useInstanceHoldingsQuery(instance?.id, { tenantId, enabled: canViewHoldings });
const { holdings: limitedHoldings, isLoading: isLimitedHoldingsLoading } = useConsortiumHoldings(instance?.id, tenantId, { enabled: !canViewHoldings });
const holdings = useMemo(() => expandedHoldings || limitedHoldings || [],
[expandedHoldings, limitedHoldings, isExpandedHoldingsLoading, isLimitedHoldingsLoading]);
const isLoading = useMemo(() => isExpandedHoldingsLoading || isLimitedHoldingsLoading,
[isExpandedHoldingsLoading, isLimitedHoldingsLoading]);
return {
holdings,
isLoading,
};
};
export default useMemberTenantHoldings;