import { useEffect , useState } from 'react' ; import { useKibana } from '../utils/kibana_react' ; import { casesFeatureId } from '../../common' ; export interface UseGetUserCasesPermissions { crud : boolean ; read : boolean ; } export function useGetUserCasesPermissions ( ) { const [ casesPermissions , setCasesPermissions ] = useState < UseGetUserCasesPermissions | null > ( null ) ; const uiCapabilities = useKibana ( ) . services . application . capabilities ; useEffect ( ( ) => { const capabilitiesCanUserCRUD = typeof uiCapabilities [ casesFeatureId ] ?. crud_cases === 'boolean' ? ( uiCapabilities [ casesFeatureId ] . crud_cases as boolean ) : false ; const capabilitiesCanUserRead = typeof uiCapabilities [ casesFeatureId ] ?. read_cases === 'boolean' ? ( uiCapabilities [ casesFeatureId ] . read_cases as boolean ) : false ; setCasesPermissions ( { crud : capabilitiesCanUserCRUD , read : capabilitiesCanUserRead , } ) ; } , [ uiCapabilities ] ) ; return casesPermissions ; }