@@ -22,14 +22,26 @@ import Button from "@material-ui/core/Button";
22
22
import TextField from "@material-ui/core/TextField" ;
23
23
import Grid from "@material-ui/core/Grid" ;
24
24
import Typography from "@material-ui/core/Typography" ;
25
- import { CircularProgress , Paper } from "@material-ui/core" ;
26
- import { createStyles , Theme , withStyles } from "@material-ui/core/styles" ;
25
+ import {
26
+ CircularProgress ,
27
+ LinearProgress ,
28
+ Paper ,
29
+ TextFieldProps ,
30
+ } from "@material-ui/core" ;
31
+ import {
32
+ createStyles ,
33
+ makeStyles ,
34
+ Theme ,
35
+ withStyles ,
36
+ } from "@material-ui/core/styles" ;
27
37
import { SystemState } from "../../types" ;
28
38
import { userLoggedIn } from "../../actions" ;
29
39
import api from "../../common/api" ;
30
40
import { ILoginDetails , loginStrategyType } from "./types" ;
31
41
import { setSession } from "../../common/utils" ;
32
42
import history from "../../history" ;
43
+ import { isBoolean } from "util" ;
44
+ import { OutlinedInputProps } from "@material-ui/core/OutlinedInput" ;
33
45
34
46
const styles = ( theme : Theme ) =>
35
47
createStyles ( {
@@ -121,8 +133,33 @@ const styles = (theme: Theme) =>
121
133
jwtInput : {
122
134
marginTop : 45 ,
123
135
} ,
136
+ linearPredef : {
137
+ height : 10 ,
138
+ } ,
124
139
} ) ;
125
140
141
+ const inputStyles = makeStyles ( ( theme : Theme ) =>
142
+ createStyles ( {
143
+ disabled : {
144
+ "&.MuiInput-underline::before" : {
145
+ borderColor : "#eaeaea" ,
146
+ borderBottomStyle : "solid" ,
147
+ } ,
148
+ } ,
149
+ } )
150
+ ) ;
151
+
152
+ function LoginField ( props : TextFieldProps ) {
153
+ const classes = inputStyles ( ) ;
154
+
155
+ return (
156
+ < TextField
157
+ InputProps = { { classes } as Partial < OutlinedInputProps > }
158
+ { ...props }
159
+ />
160
+ ) ;
161
+ }
162
+
126
163
const mapState = ( state : SystemState ) => ( {
127
164
loggedIn : state . loggedIn ,
128
165
} ) ;
@@ -156,6 +193,7 @@ const Login = ({ classes, userLoggedIn }: ILoginProps) => {
156
193
loginStrategy : loginStrategyType . unknown ,
157
194
redirect : "" ,
158
195
} ) ;
196
+ const [ loginSending , setLoginSending ] = useState < boolean > ( false ) ;
159
197
160
198
const loginStrategyEndpoints : LoginStrategyRoutes = {
161
199
form : "/api/v1/login" ,
@@ -180,6 +218,7 @@ const Login = ({ classes, userLoggedIn }: ILoginProps) => {
180
218
181
219
const formSubmit = ( e : React . FormEvent < HTMLFormElement > ) => {
182
220
e . preventDefault ( ) ;
221
+ setLoginSending ( true ) ;
183
222
request
184
223
. post (
185
224
loginStrategyEndpoints [ loginStrategy . loginStrategy ] || "/api/v1/login"
@@ -191,6 +230,7 @@ const Login = ({ classes, userLoggedIn }: ILoginProps) => {
191
230
// store the jwt token
192
231
setSession ( bodyResponse . sessionId ) ;
193
232
} else if ( bodyResponse . error ) {
233
+ setLoginSending ( false ) ;
194
234
// throw will be moved to catch block once bad login returns 403
195
235
throw bodyResponse . error ;
196
236
}
@@ -201,6 +241,7 @@ const Login = ({ classes, userLoggedIn }: ILoginProps) => {
201
241
history . push ( "/" ) ;
202
242
} )
203
243
. catch ( ( err ) => {
244
+ setLoginSending ( false ) ;
204
245
setError ( err . message ) ;
205
246
} ) ;
206
247
} ;
@@ -225,7 +266,7 @@ const Login = ({ classes, userLoggedIn }: ILoginProps) => {
225
266
< form className = { classes . form } noValidate onSubmit = { formSubmit } >
226
267
< Grid container spacing = { 2 } >
227
268
< Grid item xs = { 12 } >
228
- < TextField
269
+ < LoginField
229
270
fullWidth
230
271
id = "accessKey"
231
272
value = { accessKey }
@@ -235,10 +276,11 @@ const Login = ({ classes, userLoggedIn }: ILoginProps) => {
235
276
label = "Enter Access Key"
236
277
name = "accessKey"
237
278
autoComplete = "username"
279
+ disabled = { loginSending }
238
280
/>
239
281
</ Grid >
240
282
< Grid item xs = { 12 } >
241
- < TextField
283
+ < LoginField
242
284
fullWidth
243
285
value = { secretKey }
244
286
onChange = { ( e : React . ChangeEvent < HTMLInputElement > ) =>
@@ -249,6 +291,7 @@ const Login = ({ classes, userLoggedIn }: ILoginProps) => {
249
291
type = "password"
250
292
id = "secretKey"
251
293
autoComplete = "current-password"
294
+ disabled = { loginSending }
252
295
/>
253
296
</ Grid >
254
297
</ Grid >
@@ -258,11 +301,14 @@ const Login = ({ classes, userLoggedIn }: ILoginProps) => {
258
301
variant = "contained"
259
302
color = "primary"
260
303
className = { classes . submit }
261
- disabled = { secretKey === "" || accessKey === "" }
304
+ disabled = { secretKey === "" || accessKey === "" || loginSending }
262
305
>
263
306
Login
264
307
</ Button >
265
308
</ Grid >
309
+ < Grid item xs = { 12 } className = { classes . linearPredef } >
310
+ { loginSending && < LinearProgress /> }
311
+ </ Grid >
266
312
< Grid item xs = { 12 } className = { classes . disclaimer } >
267
313
< strong > Don't have an access key?</ strong >
268
314
< br />
@@ -314,7 +360,7 @@ const Login = ({ classes, userLoggedIn }: ILoginProps) => {
314
360
< form className = { classes . form } noValidate onSubmit = { formSubmit } >
315
361
< Grid container spacing = { 2 } >
316
362
< Grid item xs = { 12 } className = { classes . jwtInput } >
317
- < TextField
363
+ < LoginField
318
364
required
319
365
fullWidth
320
366
id = "jwt"
@@ -325,6 +371,7 @@ const Login = ({ classes, userLoggedIn }: ILoginProps) => {
325
371
label = "JWT"
326
372
name = "jwt"
327
373
autoComplete = "Service Account JWT Token"
374
+ disabled = { loginSending }
328
375
/>
329
376
</ Grid >
330
377
</ Grid >
@@ -334,11 +381,14 @@ const Login = ({ classes, userLoggedIn }: ILoginProps) => {
334
381
variant = "contained"
335
382
color = "primary"
336
383
className = { classes . submit }
337
- disabled = { jwt === "" }
384
+ disabled = { jwt === "" || loginSending }
338
385
>
339
386
Login
340
387
</ Button >
341
388
</ Grid >
389
+ < Grid item xs = { 12 } className = { classes . linearPredef } >
390
+ { loginSending && < LinearProgress /> }
391
+ </ Grid >
342
392
< Grid item xs = { 12 } className = { classes . disclaimer } >
343
393
< strong > Don't have an access key?</ strong >
344
394
< br />
0 commit comments