Skip to content

Instantly share code, notes, and snippets.

@daviddsp
Created July 6, 2018 03:13
Show Gist options
  • Select an option

  • Save daviddsp/be0d1044fffbb5e93a2b46f42af44f62 to your computer and use it in GitHub Desktop.

Select an option

Save daviddsp/be0d1044fffbb5e93a2b46f42af44f62 to your computer and use it in GitHub Desktop.
dashboard
import React, { Component } from 'react';
import { Icon } from 'react-native-elements'
import { Text, View, StyleSheet, Image,Button,TextInput,TouchableHighlight, Alert,
Keyboard,ScrollView, AsyncStorage} from 'react-native';
const token='';
export default class Dashboard extends Component {
constructor(props) {
super(props);
this.state = {
photoProfile: '',
nameProfile:'',
dataDashboard: [],
token: null
}
}
componentDidMount(){
this.GetDataProfile();
this.GetDataDashBoard();
}
async GetDataProfile(){
try {
var Token = await AsyncStorage.getItem('@MySuperStore:token');
this.setState({token: Token});
console.log('Token Dashboard:' + Token);
} catch(error){
console.log('Error profiledashboard')
}
var url = 'http://api.acknowlogy.tl2.thoughtlab.info/api/v1/account/profile';
fetch (url, {
method: 'GET',
headers:{
Accept: 'application/json',
'Authorization': 'Bearer '+ Token
}
})
.then(res => res.json())
.then(res => {this.setState({
photoProfile: res.profilePhotoUrl,
nameProfile: res.name})
});
//console.log(nameProfile)
//console.log(responseJson.profilePhotoUrl)
console.log('url de la foto '+ this.state.photoProfile)
.catch(error => console.error('Error:', error))
.then(response => console.log('Success:', response));
}
async GetDataDashBoard(){
try {
var Token = await AsyncStorage.getItem('@MySuperStore:token');
console.log('Token Dashboard:' + Token);
} catch(error){
console.log('Error dashdashboard')
}
var url = 'http://api.acknowlogy.tl2.thoughtlab.info/api/v1/account/dashboard';
fetch (url, {
method: 'GET',
headers:{
Accept: 'application/json',
'Authorization': 'Bearer ' + Token
}
})
.then(response => response.json(console.log(response)))
//console.log(response)
.catch(error => console.error('Error:', error))
.then(response => console.log('Success:', response));
}
render() {
const uri ='uri:'+'"'+this.state.photoProfile+'"'
return (
<ScrollView>
<View style={styles.container}>
<Image
source={require('../assets/background2.png')}
style={{ position: 'absolute',
width: '100%',
height: '100%',
resizeMode: 'cover',
justifyContent: 'center',
flex: 1,
}}
/>
<Image
source={{uri}}
style={styles.avatar}
/>
<Text>{this.state.nameProfile}</Text>
<View style={{marginTop:30, flexDirection:'row', justifyContent:'center'}}>
<Icon
reverse
name='exclamation-triangle'
type='font-awesome'
color='#517fa4'
onPress={() => console.log('hello')}
/>
<Icon
reverse
name='star'
type='font-awesome'
color='#517fa4'
onPress={() => console.log('hello')}
/>
<Icon
reverse
name='clipboard'
type='font-awesome'
color='#517fa4'
onPress={() => console.log('hello')}
/>
<Icon
reverse
name='tv'
type='font-awesome'
color='#517fa4'
onPress={() => console.log('hello')}
/>
</View>
<View>
<Text style={styles.titleDash}>Your Score Averages</Text>
</View>
<View style={{marginTop:30, justifyContent:'space-around',flex: 1,
flexDirection: 'row'}}>
<View>
<Text>Safety Card</Text>
<Text>0.1</Text>
</View>
<View>
<Text>Safety Quizes</Text>
<Text>0.2</Text>
</View>
<View>
<Text>acknowlegements</Text>
<Text>0.3</Text>
</View>
</View>
<View style={{flex: 1,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
marginBottom: 10}}>
<Text style={[styles.titleDash, {flex: 1, justifyContent: 'space-between',}]}>Taks Due</Text>
<Text style={[styles.titleDash, {flex: 1, justifyContent: 'space-between',}]}>VIEW ALL ></Text>
</View>
</View>
</ScrollView>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'flex-start',
},
avatar:{
height: 100,
width: 100,
borderRadius:50,
marginBottom: 10,
borderWidth:4,
marginTop :20,
borderColor: '#070719',
},
titleDash:{
color: 'white',
fontSize: 20,
fontWeight: 'bold',
marginTop: 20,
marginBottom: 20,
textDecorationLine:'underline'
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment