ENEI2019-Public/App/app/screens/Home.js

119 lines
2.5 KiB
JavaScript
Raw Normal View History

2019-01-08 19:09:50 +00:00
import React, { Component } from 'react';
2019-01-31 00:46:49 +00:00
import { Button, View, Text , TouchableOpacity, FlatList, ActivityIndicator} from 'react-native';
import {bindActionCreators} from 'redux';
import { connect } from 'react-redux';
2019-01-08 19:09:50 +00:00
2019-01-31 00:46:49 +00:00
import * as Actions from '../actions'; //Import your actionss
2019-01-30 14:32:25 +00:00
2019-01-31 00:46:49 +00:00
class Home extends Component {
2019-01-30 14:32:25 +00:00
2019-01-31 00:46:49 +00:00
constructor(props) {
super(props);
2019-01-30 14:32:25 +00:00
2019-01-31 00:46:49 +00:00
this.state = {
token:false,
tokenData:'',
loggedIn:false,
onHold:true,
user:{}
};
2019-01-30 14:32:25 +00:00
}
2019-01-31 00:46:49 +00:00
componentDidMount() {
2019-01-30 14:32:25 +00:00
2019-01-31 00:46:49 +00:00
//this.props.logoutUser();
this.props.getUserInfo();
2019-01-30 14:32:25 +00:00
2019-01-31 00:46:49 +00:00
console.log('logged:'+this.props.loggedIn);
2019-01-31 00:46:49 +00:00
console.log('there we go')
2019-01-08 19:09:50 +00:00
2019-01-31 00:46:49 +00:00
console.log(this.props.user)
}
2019-01-08 19:09:50 +00:00
2019-01-31 00:46:49 +00:00
bClick(){
2019-01-31 00:46:49 +00:00
//this.props.logoutUser();
//var navigate = this.props.navigation.navigate
}
_logout = () => {
console.log("asdasd");
// this.props.navigation.navigate('scan');
this.props.getUserInfo();
// this.props.logout();
this.props.logoutUser();
}
2019-01-08 19:09:50 +00:00
render() {
2019-01-31 00:46:49 +00:00
const { navigate } = this.props.navigation;
if(this.props.token){
console.log(this.props.user)
return (
<View >
<Button onPress={this._logout} title="LOGOUT"/>
<Text></Text>
<Text>Nome: {this.props.user.Email}</Text>
<Text>city: {this.props.user.City}</Text>
<Text>phone: {this.props.user.Mobile}</Text>
</View>
);
}
else{
return (
<View >
<Text>sem permissões para aceder aqui</Text>
</View>
);
}
2019-01-30 14:32:25 +00:00
2019-01-31 00:46:49 +00:00
}
renderItem({item, index}) {
2019-01-08 19:09:50 +00:00
return (
2019-01-31 00:46:49 +00:00
<View>
<Text >
{(parseInt(index) + 1)}{". "}{item.title}
</Text>
<Text >
{item.description}
</Text>
</View>
)
2019-01-08 19:09:50 +00:00
}
2019-01-31 00:46:49 +00:00
}
function mapStateToProps(state, props) {
return {
token: state.apiReducer.token,
user: state.apiReducer.user
}
}
function mapDispatchToProps(dispatch) {
return bindActionCreators(Actions, dispatch);
}
export default connect(mapStateToProps, mapDispatchToProps)(Home);