Newer
Older
import Spinner from 'react-native-loading-spinner-overlay';
import { Keyboard, Text, TextInput, View, Image, TouchableOpacity } 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';
server: PropTypes.string.isRequired,
Accounts_EmailOrUsernamePlaceholder: PropTypes.string,
Accounts_PasswordPlaceholder: PropTypes.string,
login: PropTypes.object
});
constructor(props) {
super(props);
this.state = {
}
componentWillReceiveProps() {
const { navigator } = this.props;
navigator.setTitle({
navigator.setSubTitle({
subtitle: this.props.server
});
navigator.setButtons({
rightButtons: [{
id: 'close',
title: 'Cancel'
}]
this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this));
}
onNavigatorEvent = (event) => {
if (event.type === 'NavBarButtonPress') {
if (event.id === 'close') {
this.props.navigator.resetTo({
screen: 'ListServer',
animated: false
});
}
}
this.props.loginSubmit({ username, password, code });
Keyboard.dismiss();
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 style={styles.view} keyboardVerticalOffset={64}>
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
125
126
127
128
129
130
<View style={styles.logoContainer}>
<Image style={styles.logo} source={require('../images/logo.png')} />
</View>
<View style={styles.formContainer}>
<TextInput
placeholderTextColor={'rgba(255,255,255,.2)'}
style={styles.input}
onChangeText={username => this.setState({ username })}
keyboardType='email-address'
autoCorrect={false}
returnKeyType='done'
autoCapitalize='none'
autoFocus
underlineColorAndroid='transparent'
onSubmitEditing={this.submit}
placeholder={this.props.Accounts_EmailOrUsernamePlaceholder || 'Email or username'}
/>
<TextInput
placeholderTextColor={'rgba(255,255,255,.2)'}
style={styles.input}
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>
{this.props.login.error && <Text style={styles.error}>{this.props.login.error}</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);