import { useState } from 'react' ; import TeleportContext from 'teleport/teleportContext' ; import useAttempt from 'shared/hooks/useAttemptNext' ; export default function useAddApp ( ctx ) { const { attempt , run } = useAttempt ( '' ) ; const canCreateToken = ctx . storeUser . getTokenAccess ( ) . create ; const user = ctx . storeUser . state . username ; const version = ctx . storeUser . state . cluster . authVersion ; const isAuthTypeLocal = ! ctx . storeUser . isSso ( ) ; const isEnterprise = ctx . isEnterprise ; const [ automatic , setAutomatic ] = useState ( isEnterprise ) ; const [ cmd , setCmd ] = useState ( '' ) ; const [ expires , setExpires ] = useState ( '' ) ; function createToken ( appName = '' , appUri = '' ) { return run ( ( ) => ctx . nodeService . createAppBashCommand ( appName , appUri ) . then ( result => { setCmd ( result . text ) ; setExpires ( result . expires ) ; } ) ) ; } return { user , canCreateToken , version , createToken , cmd , expires , attempt , automatic , setAutomatic , isAuthTypeLocal , isEnterprise , } ; } export type State = ReturnType < typeof useAddApp > ;