import * as React from 'react'; import { SafeAreaView, View, Text, ScrollView, Image, TouchableOpacity, Platform } from 'react-native'; import { connect } from "react-redux"; import { saveUserInfo } from "../../../redux/actions/AppUserInfoActions"; import NetInfo from "../../../components/netstatus" import Assets from '../../../components/assets.manager.js'; import Theme from '../../../components/theme.style.js'; import Elements from '../../../components/elements.js'; import CustomIcon from '../../../components/icons.js'; import { Avatar, Divider } from 'react-native-elements'; import DB from '../../../components/storage/'; class MyProfile extends React.PureComponent { constructor(props) { super(props) } state = { connected: false, loading: false, userProfile: (this.props.userinfo != undefined && this.props.userinfo.data != undefined) ? this.props.userinfo.data : null, session: null } componentDidMount() { this.init() } componentWillUnmount() { } init = () => { NetInfo.netstatus(isConnected => { if(isConnected){ this.loadUserProfile() }else{ Elements.nointernet2() } }) } loadUserProfile = async () => { if(this.props.userinfo == undefined) { const SESSION = await DB.session() this.setState({ connected: true, loading: true, session: SESSION }) try{ this.props.saveUserInfo({ token: SESSION.token, card_number: SESSION.user.card_number }).then(res => { this.setState({ userProfile: res.data, loading: false }) DB.updateProfile(res, function(){}, function(error){}) }) .catch(error => this.setState({ loading: false })) }catch(error){ this.setState({ loading: false }) } } else { this.setState({ connected: true, userProfile: this.props.userinfo.data, loading: false }) } } getData = (key) => { return this.state.userProfile != null ? this.state.userProfile[key] : "" } getFT = (type) => { let types = Assets.fueltypes for(var x=0;x { let types = Assets.vehicletypes for(var x=0;x { let navigation = this.props.navigation.navigation navigation.navigate("EditProfile", {data: this.state.userProfile, onGoBack: (data) => { console.log(data) this.setState({ userProfile: data, loading: false }) this.init() }}) } onSelectedPaymentCard = (payment_card) => { console.log(payment_card) } renderNoInternetView = () => { return ( { NetInfo.netstatus(isConnected => { if(isConnected){ this.init() }else{ Elements.nointernet2() } }) }} /> ) } render() { if(!this.state.connected) return this.renderNoInternetView() return ( {this.state.userProfile ? Theme.formatter.NAME(this.state.userProfile) : ''} this.onEdit()} style={{backgroundColor: Theme.colors.primary, marginTop: 5, padding: 15, borderRadius: 10}}> Edit Profile Card Number {this.state.userProfile ? Theme.formatter.CN(this.getData("card_number")) : ''} Mobile Number +{this.state.userProfile ? this.getData("mobile") : ''} Birthday {Theme.formatter.DTUI(this.getData("birthdate"))} Email {this.state.userProfile ? this.getData("email") : ''} Address {this.state.userProfile ? this.getData("address") : ''} Owned Vehicle Type {this.state.userProfile ? this.getVT(this.state.userProfile.vo_code) : ''} Fuel Type {this.state.userProfile ? this.getFT(this.state.userProfile.fueltype_code) : ''} {/* this.props.navigation.navigation.navigate('PayatpumpPaymentList', { displaySelectionCard: true })} style={{ flexDirection: 'row', justifyContent: 'center', alignItems: 'center', marginLeft: 16 }}> Pay at Pump Payment Methods */} ); } } const mapStateToProps = (state) => { return { userinfo: state.appUserInfoReducer.userinfo, app_theme: state.appThemeReducer.theme } } const mapDispatchToProps = { saveUserInfo } export default connect(mapStateToProps, mapDispatchToProps)(MyProfile)