import { useState } from 'react' ; import { useService } from '@cloudbeaver/core-di' ; import { CommonDialogService } from '@cloudbeaver/core-dialogs' ; import { ErrorDetailsDialog } from '@cloudbeaver/core-notifications' ; import { getErrorDetails , IErrorDetails } from '@cloudbeaver/core-sdk' ; interface IErrorDetailsHook { details : IErrorDetails | null ; isOpen : boolean ; open : ( ) => void ; } export function useErrorDetails ( error ) { const service = useService ( CommonDialogService ) ; const [ isOpen , setIsOpen ] = useState ( false ) ; const open = async ( ) => { if ( ! error ) { return ; } try { setIsOpen ( true ) ; await service . open ( ErrorDetailsDialog , error ) ; } finally { setIsOpen ( false ) ; } } ; return { details : error && getErrorDetails ( error ) , isOpen , open , } ; }