import * as React from 'react'; import { Text, View, Image, TouchableOpacity, ImageBackground, Platform } from 'react-native'; import { connect } from "react-redux"; import { AdjustableText } from './text' import Icon from './icons.js'; import Theme from './theme.style.js'; import Assets from './assets.manager.js'; import DB from './storage/'; const styles = { borderedButton: { padding: 5, borderColor: '#fff', borderRadius: 5, borderWidth: 2, height: 45, width: 130, margin: 5, justifyContent: 'center' }, textBig: { } } class CustomHeader extends React.Component { constructor(props) { super(props) this.navigation = props.navigation?.navigation || props.navigation this.profile = null this.btnstyle = { marginLeft: 10 } this.openDrawer = () => { this.navigation?.openDrawer() } this.BackToHome = () => { this.navigation?.navigate(props.backscreen || "MenuTab") } } state = { profile: (this.props.userinfo != undefined) ? this.props.userinfo : {}, guest: false } componentDidMount() { this.init() } componentWillUnmount() { } init = async () => { let stored = await DB.profile() let isGuest = await DB.get("is_guest") this.setState({ profile: this.props.userinfo, guest: isGuest }) if(this.props.userinfo == undefined) { this.setState({ profile: stored, guest: isGuest }) } } navigate = (screen, onBackPress) => { this.props.navigation?.navigate('MyProfile', { tab: screen == "mycard" ? 1 : 2, onBackPress: onBackPress }); } getName = (p) => { let data = p?.data || this.state.profile?.data return data ? data : {firstname: '', middlename: '', lastname: ''} } getCard = (p) => { let data = p?.data || this.state.profile?.data return data ? data.card_number : "" } getPoints = (p) => { let data = p?.data || this.state.profile?.data return data?.points } getPhoto = (p) => { let data = p?.data || this.state.profile?.data return data ? data.photo == '' ? Assets.logo.profileHolder : {uri: data.photo} : Assets.logo.profileHolder } getCardBackground = (p) => { let data = p?.data || this.state.profile?.data return data ? data.card_bg_image == '' ? Assets.cards.classic : {uri: data.card_bg_image} : Assets.cards.classic } renderButtonLeft() { if(this.props.menu) { return ( ) } else { return ( ) } } renderButtonRight() { if(!this.props.renderIQAir) return null; if(!this.state.guest) { return ( this.props.navigation?.navigate("IQAir")}> ) } } renderBanner() { return ( {this.renderButtonLeft()} {this.props.title || this.props.customTitle} {this.props.rightMenu || null} ) } render() { if(!this.props.banner) return this.renderBanner() this.profile = this.props.userinfo return ( {this.renderButtonLeft()} { !this.state.guest ? : } { !this.state.guest ? Theme.formatter.NAME(this.getName(this.profile ? this.profile : {})) : 'Guest' } { !this.state.guest ? Theme.formatter.CN(this.getCard(this.profile ? this.profile : {})) : '' } Points:   { !this.state.guest ? Theme.formatter.CRNCY(this.getPoints(this.profile ? this.profile : {})) : '0.00' } this.navigate("transactions", this.state.reload || null)} style={styles.borderedButton}> My Transactions this.navigate("mycard", this.state.reload || null)} style={styles.borderedButton}> My Card {this.renderButtonRight()} ) } } const mapStateToProps = (state) => { return { userinfo: state.appUserInfoReducer.userinfo, app_theme: state.appThemeReducer.theme } } export default connect(mapStateToProps, null)(CustomHeader)