Setup start of redux login action
This commit is contained in:
parent
84855e36fd
commit
09e22b6eca
4 changed files with 15 additions and 30 deletions
|
@ -1,4 +1,4 @@
|
|||
import endpoints from './endpoints';
|
||||
import endpoints from '../settings/endpoints';
|
||||
import request from './request';
|
||||
import token from './token';
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@ import React from 'react-native';
|
|||
import GlobalStyles from '../../settings/styles';
|
||||
import TokenHelp from '../login/token-help';
|
||||
import RouteMaster from './RouteMaster';
|
||||
import { checkToken } from '../../api/CircleCI';
|
||||
import token from '../../api/token';
|
||||
import loaderHandler from 'react-native-busy-indicator/LoaderHandler';
|
||||
import { connect } from 'react-redux';
|
||||
import { login }from '../../actions';
|
||||
|
||||
const dismissKeyboard = require('dismissKeyboard');
|
||||
|
||||
|
@ -76,7 +76,7 @@ const styles = StyleSheet.create({
|
|||
}
|
||||
});
|
||||
|
||||
export default class Login extends React.Component {
|
||||
export class Login extends React.Component {
|
||||
constructor() {
|
||||
super();
|
||||
this.state = {
|
||||
|
@ -101,18 +101,12 @@ export default class Login extends React.Component {
|
|||
this.showTokenHelp = this.showTokenHelp.bind(this);
|
||||
this.hideTokenHelp = this.hideTokenHelp.bind(this);
|
||||
this.showAbout = this.showAbout.bind(this);
|
||||
this.proceed = this.proceed.bind(this);
|
||||
}
|
||||
|
||||
textChanged(CIToken) {
|
||||
this.setState({ token: CIToken });
|
||||
}
|
||||
|
||||
proceed() {
|
||||
this.hideTokenHelp();
|
||||
this.props.nav.replace(RouteMaster.get('HOME'));
|
||||
}
|
||||
|
||||
invalidToken() {
|
||||
Alert.alert('Invalid',
|
||||
'Token not accepted!',
|
||||
|
@ -127,17 +121,7 @@ export default class Login extends React.Component {
|
|||
loaderHandler.hideLoader();
|
||||
return;
|
||||
}
|
||||
checkToken(this.state.token).then(function (isValid) {
|
||||
if (isValid) {
|
||||
token.set(this.state.token).then(this.proceed);
|
||||
} else {
|
||||
this.invalidToken();
|
||||
this.setState({
|
||||
token: ''
|
||||
});
|
||||
}
|
||||
loaderHandler.hideLoader();
|
||||
}.bind(this)).catch(console.log);
|
||||
this.props.login(this.state.token);
|
||||
}
|
||||
|
||||
showAbout() {
|
||||
|
@ -163,14 +147,6 @@ export default class Login extends React.Component {
|
|||
|
||||
componentWillMount() {
|
||||
BackAndroid.addEventListener('hardwareBackPress', () => { return true; }); // Disable back button
|
||||
token.get().then(function (CIToken) {
|
||||
if (!CIToken) {
|
||||
return;
|
||||
}
|
||||
checkToken(CIToken).then(function (isValid) {
|
||||
this.proceed();
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
@ -223,3 +199,11 @@ export default class Login extends React.Component {
|
|||
);
|
||||
}
|
||||
};
|
||||
|
||||
function mapStateToProps(state) {
|
||||
return {
|
||||
token: state.user.get('token')
|
||||
};
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, { login }) (Login);
|
||||
|
|
|
@ -4,5 +4,6 @@ export default Map({
|
|||
PROJECT_DATA: {
|
||||
repository: 'https://github.com/RealOrangeOne/Sphere',
|
||||
CI_Badge: 'https://circleci.com/gh/RealOrangeOne/Sphere.svg?style=svg'
|
||||
}
|
||||
},
|
||||
STORAGE_KEY: 'SphereStorageKey'
|
||||
});
|
||||
|
|
Reference in a new issue