Skip to content

Instantly share code, notes, and snippets.

@guaracyalima
Created July 2, 2018 23:45
Show Gist options
  • Save guaracyalima/4baedce22465b89f1213ec0585bddabc to your computer and use it in GitHub Desktop.
Save guaracyalima/4baedce22465b89f1213ec0585bddabc to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import { View, Text, StatusBar, Image, ScrollView, TouchableOpacity, AsyncStorage } from 'react-native';
import { Actions } from 'react-native-router-flux';
import axios from 'axios';
import css from '../../styles/main-styles';
import { api } from '../../../env';
import OneSignal from 'react-native-onesignal';
const insurances = require('../../../assets/img/icons/icon_seguros.png');
const notification = require('../../../assets/img/icons/icon_notificacoes.png');
const mail = require('../../../assets/img/icons/icon_mensagens.png');
const brasal = require('../../../assets/img/icons/icon_brasal.png');
const attendiment = require('../../../assets/img/icons/icon_atendimento.png');
const friend = require('../../../assets/img/icons/icon_indicacao.png');
const logo = require('../../../assets/img/logo/fq.png');
const bg = require('../../../assets/img/bg/login/login.jpg');
export default class Insurances extends Component {
constructor(props) {
super(props);
this.state = { name: '', emial: '', cpf: '', user_id: '', options: '' };
}
async getToken() {
const value = await AsyncStorage.getItem('@MySuperStore:token');
let options = { headers: { Authorization: `Bearer ${value}` } };
this.setState({options: options})
await axios.get(`${api.apiUrl}/user`, options)
.then((res) => {
this.setState({
name: res.data.name,
email: res.data.email,
cpf: res.data.cpf,
user_id: res.data.id
});
OneSignal.addEventListener('ids', this.onIds)
})
.catch(error => console.log('erro ao trazer dados do usuario logado', error));
}
onIds(device) {
console.log('Informacoes sdfsdo device', device)
this.__updatePlayerid(device);
}
componentWillMount() {
setTimeout(() => {
this.getToken();
}, 1200);
}
__updatePlayerid(data){
let dt = {
player_id: data.userId,
user_id: this.state.user_id
}
console.log('o trem montado')
axios.put(`${api.apiUrl}/playerid/${this.state.user_id}`, dt, this.state.options)
.then( res => console.log('Dados atualizados com sucesso', res))
.catch(error => console.log('Erro ao atualizar os dados do player', error))
}
render() {
return (
<Image source={bg} style={css.bg}>
<ScrollView>
<StatusBar
barStyle="light-content"
/>
<View style={css.featured}>
<View style={css.logo}>
<Image source={logo} style={css.logoImage} />
</View>
<Text style={css.wellcomeClient}>Bem vindo, {this.state.name}</Text>
<View style={css.list_food}>
<View style={css.list_food_item}>
<View>
<TouchableOpacity onPress={() => { Actions.myinsurances({ cpf: this.state.cpf }); }}>
<Image source={insurances} style={css.list_food_item_image} />
</TouchableOpacity>
<Text style={css.textOfDescriptionOfImage} >Seguros</Text>
</View>
<View>
<TouchableOpacity onPress={() => { Actions.notifications({ cpf: this.state.cpf }); }}>
<Image source={notification} style={css.list_food_item_image} />
</TouchableOpacity>
<Text style={css.textOfDescriptionOfImage} >Notificações</Text>
</View>
<View>
<TouchableOpacity onPress={() => { Actions.messages({
cpf: this.state.cpf,
user_id: this.state.user_id,
name: this.state.name,
email: this.state.email}); }}>
<Image source={mail} style={css.list_food_item_image} />
</TouchableOpacity>
<Text style={css.textOfDescriptionOfImage} >Mensagens</Text>
</View>
</View>
<View style={css.list_food_item}>
<View>
<TouchableOpacity onPress={() => { Actions.broker(); }}>
<Image source={brasal} style={css.list_food_item_image} />
</TouchableOpacity>
<Text style={css.textOfDescriptionOfImage} >Brasal</Text>
</View>
<View>
<TouchableOpacity onPress={() => { Actions.attendance(); }}>
<Image source={attendiment} style={css.list_food_item_image} />
</TouchableOpacity>
<Text style={css.textOfDescriptionOfImage} >Atendimento</Text>
</View>
<View>
<TouchableOpacity onPress={() => { Actions.friendly(); }}>
<Image source={friend} style={css.list_food_item_image} />
</TouchableOpacity>
<Text style={css.textOfDescriptionOfImage} >Indicar amigo</Text>
</View>
</View>
</View>
</View>
</ScrollView>
</Image>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment