import { Organization } from '@proton/shared/lib/interfaces' ; import useCache from './useCache' ; import { useUser } from './useUser' ; import { useGetOrganizationKeyRaw } from './useGetOrganizationKeyRaw' ; import usePromiseResult from './usePromiseResult' ; import { cachedPromise } from './helpers/cachedPromise' ; const useOrganizationKey = ( organization ? ) => { const cache = useCache ( ) ; const getOrganizationKeyRaw = useGetOrganizationKeyRaw ( ) ; const [ user ] = useUser ( ) ; return usePromiseResult ( async ( ) => { if ( ! user . isAdmin || ! organization ) { return ; } return cachedPromise ( cache , 'ORGANIZATION_KEY' , async ( ) => { return getOrganizationKeyRaw ( ) ; } , organization ) ; } , [ user , organization ] ) ; } ; export default useOrganizationKey ;