import { useState , useEffect } from 'react' ; import TeleportContext from 'teleport/teleportContext' ; import useAttempt from 'shared/hooks/useAttemptNext' ; export default function useAddNode ( ctx ) { const { attempt , run } = useAttempt ( 'processing' ) ; const canCreateToken = ctx . storeUser . getTokenAccess ( ) . create ; const version = ctx . storeUser . state . cluster . authVersion ; const user = ctx . storeUser . state . username ; const isAuthTypeLocal = ! ctx . storeUser . isSso ( ) ; const isEnterprise = ctx . isEnterprise ; const [ automatic , setAutomatic ] = useState ( isEnterprise ) ; const [ script , setScript ] = useState ( '' ) ; const [ expiry , setExpiry ] = useState ( '' ) ; useEffect ( ( ) => { createJoinToken ( ) ; } , [ ] ) ; function createJoinToken ( ) { return run ( ( ) => ctx . nodeService . createNodeBashCommand ( ) . then ( cmd => { setExpiry ( cmd . expires ) ; setScript ( cmd . text ) ; } ) ) ; } return { canCreateToken , createJoinToken , automatic , setAutomatic , script , expiry , attempt , version , user , isEnterprise , isAuthTypeLocal , } ; } export type State = ReturnType < typeof useAddNode > ;