@@ -8,6 +8,8 @@ import GenerateLocalLinuxCurl from '../commands/local_linux_curl';
8
8
import CommandDisplay from '../utils/CommandDisplay' ;
9
9
import { Button , Form } from 'react-bootstrap' ;
10
10
import IslandHttpClient , { APIEndpoint } from '../../../IslandHttpClient' ;
11
+ import { useTimer } from 'react-timer-hook' ;
12
+ import { CommandExpirationTimer } from '../utils/CommandExpirationTimer' ;
11
13
12
14
13
15
const LocalManualRunOptions = ( props ) => {
@@ -24,6 +26,12 @@ const getContents = (props) => {
24
26
[ OS_TYPES . LINUX_64 ] : 'Linux 64bit'
25
27
}
26
28
29
+ const {
30
+ seconds,
31
+ minutes,
32
+ restart
33
+ } = useTimer ( { expiryTimestamp : new Date ( ) } ) ;
34
+
27
35
const [ otp , setOtp ] = useState ( '' ) ;
28
36
const [ osType , setOsType ] = useState ( OS_TYPES . WINDOWS_64 ) ;
29
37
const [ selectedIp , setSelectedIp ] = useState ( props . ips [ 0 ] ) ;
@@ -52,8 +60,9 @@ const getContents = (props) => {
52
60
}
53
61
54
62
function getOtp ( ) {
55
- IslandHttpClient . get ( APIEndpoint . agent_otp ) . then ( res => {
63
+ IslandHttpClient . get ( APIEndpoint . agent_otp ) . then ( res => {
56
64
setOtp ( res . body . otp ) ;
65
+ restart ( newExpirationTime ( ) ) ;
57
66
} ) ;
58
67
}
59
68
@@ -66,6 +75,13 @@ const getContents = (props) => {
66
75
}
67
76
}
68
77
78
+ function newExpirationTime ( ) {
79
+ const time = new Date ( ) ;
80
+ time . setSeconds ( time . getSeconds ( ) + 120 ) ;
81
+ console . log ( 'timeout is now: ' + time ) ;
82
+ return time ;
83
+ }
84
+
69
85
return (
70
86
< >
71
87
< DropdownSelect defaultKey = { OS_TYPES . WINDOWS_64 } options = { osTypes } onClick = { setOsType } variant = { 'outline-monkey' } />
@@ -84,7 +100,14 @@ const getContents = (props) => {
84
100
</ div >
85
101
</ div >
86
102
< CommandDisplay commands = { commands } onCopy = { getOtp } />
87
- < Button style = { { 'float' : 'right' } } title = "Copy to Clipboard" onClick = { getOtp } > Re-generate</ Button >
103
+ < div style = { { marginTop : '-0.5em' , marginBottom : '0.5em' } } >
104
+ < CommandExpirationTimer minutes = { minutes } seconds = { seconds } />
105
+ </ div >
106
+ < div style = { { textAlign : 'right' } } >
107
+ < span >
108
+ < Button title = "Copy to Clipboard" onClick = { getOtp } > Re-generate</ Button >
109
+ </ span >
110
+ </ div >
88
111
</ >
89
112
)
90
113
}
0 commit comments