import * as React from 'react'; import {useState, useEffect} from 'react'; import {View, Text, TouchableOpacity, Image, ImageBackground} from 'react-native'; import Theme from '../theme.style'; import Assets from '../assets.manager'; import Icon from '../icons.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 Header extends React.PureComponent { constructor(props) { super(props) this.btnstyle = { marginLeft: 10 }; this.name = '' this.cardnumber = '' this.points = '' } state = { profile: null } componentDidMount() { this.init() } componentWillUnmount() { } init = async () => { let stored = await DB.profile() this.setState({ profile: stored }) this.name = stored && stored?.data ? stored.data : {} this.cardnumber = stored && stored?.data ? stored.data.card_number : '' this.points = stored && stored?.data ? stored.data.points : '' } navigate = (screen, onBackPress) => { this.props.navigation.navigate('MyProfile', { tab: screen == "mycard" ? "ProfileCardTab" : "ProfileTransactionsTab", onBackPress: onBackPress }); } openDrawer = () => { this.props.navigation.openDrawer() } render() { return ( this.openDrawer()}> {this.name ? Theme.formatter.NAME(this.name) : ''} {Theme.formatter.CN(this.cardnumber)} Points: {Theme.formatter.CRNCY(this.points)} navigate("transactions", this.props.reload() || null)} style={styles.borderedButton}> My Transactions navigate("mycard", this.props.reload() || null)} style={styles.borderedButton}> My Card ) } } export default Header // export default function Header({navigation, reload}){ // const openDrawer = () => { navigation.navigation.openDrawer();} // const btnstyle = {marginLeft: 10}; // const navigate = (screen, onBackPress) => { // // navigation.navigate("MyProfile", {screen: screen == "mycard" ? "ProfileCardTab" : "ProfileTransactionsTab", params: "card"}) // navigation.navigation.navigate('MyProfile', { // tab: screen == "mycard" ? "ProfileCardTab" : "ProfileTransactionsTab", // onBackPress: onBackPress // }); // } // const [profile, setprofile] = useState({}) // const init = async () => { // let stored = await DB.profile() // setprofile(stored) // } // useEffect(() => { // init() // }, []) // // console.log("PROFILE FROM EMPTY", profile) // let name = profile && profile?.data ? profile.data : {} // let cardnumber = profile && profile?.data ? profile.data.card_number : '' // let points = profile && profile?.data ? profile.data.points : '' // return ( // // // // // // // // // // // // // // // {name ? Theme.formatter.NAME(name) : ''} // // // {Theme.formatter.CN(cardnumber)} // // // Points: {Theme.formatter.CRNCY(points)} // // // // // // navigate("transactions", reload || null)} style={styles.borderedButton}> // My Transactions // // navigate("mycard", reload || null)} style={styles.borderedButton}> // My Card // // // // // // // ); // }