1- import { Button , ButtonGroup , Card , Icon } from '@blueprintjs/core'
1+ import { Button , ButtonGroup , Card , Icon , NonIdealState , Spinner } from '@blueprintjs/core'
22import { IconNames } from '@blueprintjs/icons'
33import * as React from 'react'
44import { NavLink } from 'react-router-dom'
55
6- type LoginProps = DispatchProps
6+ type LoginProps = DispatchProps & OwnProps
77
88export type DispatchProps = {
9+ handleFetchAuth : ( ivleToken : string ) => void
910 handleLogin : ( ) => void
1011}
1112
13+ export type OwnProps = {
14+ ivleToken ?: string
15+ }
16+
17+ const Login : React . SFC < LoginProps > = props => {
18+ if ( props . ivleToken ) {
19+ startFetchAuth ( props . ivleToken , props . handleFetchAuth )
20+ return (
21+ < div className = "Login pt-dark" >
22+ < Card className = "login-card pt-elevation-4" >
23+ < div className = "login-body" >
24+ < NonIdealState description = "Logging In..." visual = { < Spinner large = { true } /> } />
25+ </ div >
26+ </ Card >
27+ </ div >
28+ )
29+ } else {
30+ return (
31+ < div className = "Login pt-dark" >
32+ < Card className = "login-card pt-elevation-4" >
33+ < div className = "login-header" >
34+ < h4 >
35+ < Icon icon = { IconNames . LOCK } /> LOGIN
36+ </ h4 >
37+ </ div >
38+ < div className = "login-body" >
39+ < ButtonGroup fill = { true } vertical = { true } >
40+ { loginButton ( props . handleLogin ) }
41+ { playgroundButton }
42+ </ ButtonGroup >
43+ </ div >
44+ </ Card >
45+ </ div >
46+ )
47+ }
48+ }
49+
50+ const startFetchAuth = ( ivleToken : string , handleFetchAuth : DispatchProps [ 'handleFetchAuth' ] ) =>
51+ handleFetchAuth ( ivleToken )
52+
1253const loginButton = ( handleClick : ( ) => void ) => (
1354 < Button className = "pt-large" rightIcon = "log-in" onClick = { handleClick } >
1455 Log in with IVLE
@@ -23,22 +64,4 @@ const playgroundButton = (
2364 </ NavLink >
2465)
2566
26- const Login : React . SFC < LoginProps > = props => (
27- < div className = "Login pt-dark" >
28- < Card className = "login-card pt-elevation-4" >
29- < div className = "login-header" >
30- < h4 >
31- < Icon icon = { IconNames . LOCK } /> LOGIN
32- </ h4 >
33- </ div >
34- < div className = "login-body" >
35- < ButtonGroup fill = { true } vertical = { true } >
36- { loginButton ( ( ) => props . handleLogin ( ) ) }
37- { playgroundButton }
38- </ ButtonGroup >
39- </ div >
40- </ Card >
41- </ div >
42- )
43-
4467export default Login
0 commit comments