import React, { Component } from 'react' import { ScrollView, View, Alert } from 'react-native' import Image from 'react-native-fast-image' import { Button } from 'native-base' import { BackgroundImage_RegisterForm } from '../../components/BackgroundImage_RegisterForm' import Text from '../../components/Text'; import LinearGradient from 'react-native-linear-gradient'; import Icon from 'src/components/Icon' import { CustomButton } from '../../components/CustomButton' import { bindActionCreators } from 'redux' import { connect } from 'react-redux' import { getUserProfile } from '../../api/UserApi'; import moment from 'moment' import { NavigationEvents } from 'react-navigation' import IndicatorLoading from '../../components/IndicatorLoading'; import { loginWithFacebook,disconnectWithFacebook } from '../../components/FacebookUtils'; import { t } from '../../utils/i18n' class ProfileScreen extends Component { constructor(props) { super(props) this.state = { isLoading: false, user:{}, room:null, profileImage: require('../../../assets/images/profile.png') } this.getUserData = this.getUserData.bind(this) } componentDidMount(){ // this.getUserData() this.setState({ isLoading: true }) }; getUserData(){ this.setState({ isLoading: true }) getUserProfile() .then(res => { // console.log('user profile -------> ',res); if(res.ok){ let image = require('../../../assets/images/profile.png') if (res.data.user.image && res.data.user.image.url){ image = { uri: res.data.user.image.url } } this.props.user.show_birth_date = res.data.user.birth_date this.setState({ isLoading: false, user: res.data.user, room: res.data.room, profileImage : image, }) }else{ this.setState({ isLoading: false }) } }) } connectFBSuccess = () => { this.state.user.fb_is_link = 't'; Alert.alert('Connect with Facebook Success', '', [ { text: 'ok', onPress: () => { this.getUserData() } } ]) }; disConnectFBSuccess = () => { this.state.user.fb_is_link = 'f'; this.state.user.fb_token = null; Alert.alert('Disconnect with Facebook Success', '', [ { text: 'ok', onPress: () => { this.getUserData() } } ]) }; refreshPage() { window.location.reload(false); } render() { return ( { console.log('getUserData'); this.getUserData() }} /> {t('profile')} {t('category')} {this.state.user.is_customer ? t('customer') : t('guest')} {t('name')} {this.state.user.name} {t('email')} {this.state.user.email} {t('phone2')} {this.state.user.mobile} {t('citizen_id')} {this.state.user.tax_id} {t('gender')} {this.state.user.gender == "male" || this.state.user.gender == "ชาย" ? t('male') : t('female')} {t('birth_date')} {moment(this.state.user.birth_date).add(543, 'years').format('DD-MM-YYYY')} { this.state.room != null && {t('accom_info')} {t('accommodation')} {this.state.room.project_name} {t('zone')} {this.state.room.zone_name} {t('room2')} {this.state.room.number} } { !this.state.user.fb_is_link? : } ) } } const styles = { container: { flexDirection: 'column', height: '100%', }, image_profile: { display: 'flex', alignItems: 'center', justifyContent: 'center', borderRadius: '25%', }, text_field_style: { color: 'white', width: '35%', marginBottom: 8, fontSize: 14, }, data_field_style: { color: 'white', marginLeft: 5, fontSize: 14, width: '65%', } } const mapDisPatchToProps = state => { return state.app } const prop_set = dispatch => bindActionCreators({ }, dispatch) export default connect(mapDisPatchToProps, prop_set)(ProfileScreen)