Newer
Older
import Spinner from 'react-native-loading-spinner-overlay';
import { Keyboard, Text, TextInput, View, TouchableOpacity, SafeAreaView } from 'react-native';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
// import * as actions from '../actions';
import * as loginActions from '../actions/login';
import KeyboardView from '../presentation/KeyboardView';
Accounts_EmailOrUsernamePlaceholder: PropTypes.string,
login: PropTypes.object,
navigation: PropTypes.object.isRequired
});
constructor(props) {
super(props);
this.state = {
if (username.trim() === '' || password.trim() === '') {
return;
}
this.props.loginSubmit({ username, password, code });
Keyboard.dismiss();
register = () => {
this.props.navigation.navigate('Register');
}
forgotPassword = () => {
this.props.navigation.navigate('ForgotPassword');
}
if (this.props.login.errorMessage && this.props.login.errorMessage.error === 'totp-required') {
return (
<TextInput
ref={ref => this.codeInput = ref}
style={styles.input}
onChangeText={code => this.setState({ code })}
keyboardType='numeric'
autoCorrect={false}
returnKeyType='done'
autoCapitalize='none'
onSubmitEditing={this.submit}
placeholder='Code'
/>
);
}
}
// {this.props.login.isFetching && <Text> LOGANDO</Text>}
<KeyboardView
contentContainerStyle={styles.container}
keyboardVerticalOffset={128}
>
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<SafeAreaView>
<View style={styles.loginView}>
<View style={styles.formContainer}>
<TextInput
style={styles.input_white}
onChangeText={username => this.setState({ username })}
keyboardType='email-address'
autoCorrect={false}
returnKeyType='next'
autoCapitalize='none'
underlineColorAndroid='transparent'
onSubmitEditing={() => { this.password.focus(); }}
placeholder={this.props.Accounts_EmailOrUsernamePlaceholder || 'Email or username'}
/>
<TextInput
ref={(e) => { this.password = e; }}
style={styles.input_white}
onChangeText={password => this.setState({ password })}
secureTextEntry
autoCorrect={false}
returnKeyType='done'
autoCapitalize='none'
underlineColorAndroid='transparent'
onSubmitEditing={this.submit}
placeholder={this.props.Accounts_PasswordPlaceholder || 'Password'}
/>
{this.renderTOTP()}
<TouchableOpacity style={styles.buttonContainer}>
<Text style={styles.button} onPress={this.submit}>LOGIN</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.buttonContainer}>
<Text style={styles.button} onPress={this.register}>REGISTER</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.buttonContainer} onPress={this.forgotPassword}>
<Text style={styles.button}>FORGOT MY PASSWORD</Text>
</TouchableOpacity>
{this.props.login.failure && <Text style={styles.error}>{this.props.login.error.reason}</Text>}
</View>
<Spinner visible={this.props.login.isFetching} textContent='Loading...' textStyle={{ color: '#FFF' }} />
Accounts_EmailOrUsernamePlaceholder: state.settings.Accounts_EmailOrUsernamePlaceholder,
Accounts_PasswordPlaceholder: state.settings.Accounts_PasswordPlaceholder,
login: state.login
};
}
function mapDispatchToProps(dispatch) {
return bindActionCreators(loginActions, dispatch);
}
export default connect(mapStateToProps, mapDispatchToProps)(LoginView);