@@ -9,32 +9,34 @@ import {
99 validateLoginCredentials ,
1010 setLoginCredentials ,
1111 type SettingsState ,
12+ type LoginStateType ,
1213} from '../../../flux/parts/settings'
1314import { connect } from 'react-redux'
1415import noop from 'lodash/noop'
1516
16- type CredentialsSectionPropsType = {
17- username : string ,
18- password : string ,
19- loggedIn : boolean ,
20- message : ?string ,
17+ type Props = {
18+ initialUsername : string ,
19+ initialPassword : string ,
20+ state : LoginStateType ,
2121
2222 logIn : ( username : string , password : string ) => any ,
2323 logOut : ( ) => any ,
2424 validateCredentials : ( username : string , password : string ) => any ,
2525 setCredentials : ( username : string , password : string ) => any ,
2626}
2727
28- class CredentialsLoginSection extends React . Component {
29- props : CredentialsSectionPropsType
28+ type State = {
29+ username : string ,
30+ password : string ,
31+ }
3032
33+ class CredentialsLoginSection extends React . PureComponent < void , Props , State > {
3134 _usernameInput : any
3235 _passwordInput : any
3336
3437 state = {
35- loading : false ,
36- username : this . props . username ,
37- password : this . props . password ,
38+ username : this . props . initialUsername ,
39+ password : this . props . initialPassword ,
3840 }
3941
4042 focusUsername = ( ) => this . _usernameInput . focus ( )
@@ -57,8 +59,16 @@ class CredentialsLoginSection extends React.Component {
5759 onChangePassword = ( text = '' ) => this . setState ( ( ) => ( { password : text } ) )
5860
5961 render ( ) {
60- let { loggedIn, message} = this . props
61- let { loading, username, password} = this . state
62+ const { loginState} = this . props
63+ const { username, password} = this . state
64+
65+ const loading = loginState === 'checking'
66+ const loggedIn = loginState === 'logged-in'
67+
68+ let message
69+ if ( loginState === 'invalid' ) {
70+ message = 'Login failed'
71+ }
6272
6373 return (
6474 < Section
@@ -89,7 +99,7 @@ class CredentialsLoginSection extends React.Component {
8999 value = { password }
90100 />
91101
92- { message ? < Cell title = { ' ⚠️ ' + message } /> : null }
102+ { message ? < Cell title = { ` ⚠️ ${ message } ` } /> : null }
93103
94104 < LoginButton
95105 loggedIn = { loggedIn }
0 commit comments