This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
Sphere/app/components/routes/login.js

178 lines
4.3 KiB
JavaScript
Raw Normal View History

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