177 lines
4.3 KiB
JavaScript
177 lines
4.3 KiB
JavaScript
import React from 'react-native';
|
|
import GlobalStyles from '../../settings/styles';
|
|
import TokenHelp from '../login/token-help';
|
|
|
|
const dismissKeyboard = require('dismissKeyboard');
|
|
|
|
const {
|
|
StyleSheet,
|
|
Text,
|
|
View,
|
|
TextInput,
|
|
TouchableHighlight,
|
|
ScrollView,
|
|
BackAndroid,
|
|
TouchableWithoutFeedback
|
|
} = React;
|
|
|
|
const styles = StyleSheet.create({
|
|
container: {
|
|
flex: 1,
|
|
backgroundColor: GlobalStyles.get('CIRCLE_GREY_DARK'),
|
|
},
|
|
contentWrapper: {
|
|
flex: 0.85,
|
|
justifyContent: 'flex-start',
|
|
alignItems: 'center'
|
|
},
|
|
input: {
|
|
marginHorizontal: 15,
|
|
fontSize: 15,
|
|
textAlign: 'center'
|
|
},
|
|
loginButton: {
|
|
flex: 0.9,
|
|
backgroundColor: GlobalStyles.get('CIRCLE_GREEN'),
|
|
borderColor: GlobalStyles.get('CIRCLE_GREEN'),
|
|
},
|
|
infoButton: {
|
|
flex: 0.15,
|
|
backgroundColor: GlobalStyles.get('CIRCLE_GREY'),
|
|
borderColor: GlobalStyles.get('CIRCLE_GREY'),
|
|
},
|
|
button: {
|
|
justifyContent: 'center',
|
|
alignItems: 'center',
|
|
padding: 10,
|
|
borderWidth: 2,
|
|
borderRadius: 12,
|
|
margin: 5
|
|
},
|
|
buttonText: {
|
|
fontSize: 18,
|
|
color: 'white',
|
|
},
|
|
buttonContainer: {
|
|
flexDirection: 'row',
|
|
justifyContent: 'center',
|
|
margin: 5
|
|
},
|
|
title: {
|
|
fontSize: 30,
|
|
margin: 13
|
|
},
|
|
heading: {
|
|
fontSize: 18,
|
|
margin: 8,
|
|
marginVertical: 20
|
|
},
|
|
helpText: {
|
|
fontSize: 11,
|
|
fontStyle: 'italic',
|
|
padding: 5,
|
|
},
|
|
text: {
|
|
color: 'white'
|
|
}
|
|
});
|
|
|
|
export default class Login extends React.Component {
|
|
constructor() {
|
|
super();
|
|
this.state = {
|
|
token: '',
|
|
showTokenHelp: false
|
|
};
|
|
this.validate = this.validate.bind(this);
|
|
this.textChanged = this.textChanged.bind(this);
|
|
this.showTokenHelp = this.showTokenHelp.bind(this);
|
|
this.hideTokenHelp = this.hideTokenHelp.bind(this);
|
|
this.showAbout = this.showAbout.bind(this);
|
|
}
|
|
|
|
textChanged(token) {
|
|
this.setState({ token });
|
|
}
|
|
|
|
validate() {
|
|
dismissKeyboard();
|
|
}
|
|
|
|
showAbout() {
|
|
|
|
}
|
|
|
|
showTokenHelp() {
|
|
dismissKeyboard();
|
|
this.setState({
|
|
showTokenHelp: true
|
|
});
|
|
}
|
|
|
|
hideTokenHelp() {
|
|
this.setState({
|
|
showTokenHelp: false
|
|
});
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
BackAndroid.removeEventListener('hardwareBackPress', () => { return true; }); // Re-enable back button
|
|
}
|
|
|
|
componentWillMount() {
|
|
BackAndroid.addEventListener('hardwareBackPress', () => { return true; }); // Disable back button
|
|
}
|
|
|
|
render() {
|
|
return (
|
|
<View style={styles.container}>
|
|
<View style={styles.buttonContainer}>
|
|
<Text style={[styles.title, styles.text]}>
|
|
Sphere
|
|
</Text>
|
|
</View>
|
|
<ScrollView keyboardShouldPersistTaps={false} contentContainerStyle={styles.container}>
|
|
<View style={styles.contentWrapper}>
|
|
<Text style={[styles.heading, styles.text]}>
|
|
Please enter your CircleCI token
|
|
</Text>
|
|
<TextInput
|
|
style={[styles.input, styles.text]}
|
|
onChangeText={this.textChanged}
|
|
value={this.state.token}
|
|
onSubmitEditing={this.validate}
|
|
placeholder="CircleCI Token"
|
|
placeholderTextColor="#A7A7A7"
|
|
autoCorrect={false}
|
|
/>
|
|
<TouchableWithoutFeedback onPress={this.showTokenHelp}>
|
|
<Text style={[styles.helpText, styles.text]}>
|
|
What's this?
|
|
</Text>
|
|
</TouchableWithoutFeedback>
|
|
</View>
|
|
</ScrollView>
|
|
<View style={styles.buttonContainer}>
|
|
<TouchableHighlight
|
|
style={[styles.button, styles.loginButton]}
|
|
onPress={this.validate}
|
|
underlayColor={GlobalStyles.get('CIRCLE_GREY_DARK')}>
|
|
<Text style={[styles.buttonText, styles.text]}>
|
|
Authenticate
|
|
</Text>
|
|
</TouchableHighlight>
|
|
<TouchableHighlight
|
|
style={[styles.button, styles.infoButton]}
|
|
onPress={this.showAbout}
|
|
underlayColor={GlobalStyles.get('CIRCLE_GREY_DARK')}>
|
|
<Text style={[styles.buttonText, styles.text]}>
|
|
About
|
|
</Text>
|
|
</TouchableHighlight>
|
|
</View>
|
|
<TokenHelp open={this.state.showTokenHelp} onClose={this.hideTokenHelp} />
|
|
</View>
|
|
);
|
|
}
|
|
};
|