import * as React from 'react'; import { SafeAreaView, Text, View, FlatList, Alert, Platform, TouchableOpacity } from 'react-native'; import { connect } from "react-redux"; import { createDrawerNavigator } from '@react-navigation/drawer'; import { Avatar, Icon, ListItem } from 'react-native-elements'; import { openModal } from '../redux/actions/AlertActions.js'; import Assets from './assets.manager.js'; import Elements from './elements.js'; import DB from './storage/'; import Theme from '../components/theme.style.js'; import NetInfo from "../components/netstatus"; import CustomSafeArea from './safeArea.component.js'; import AdjustableText from './text/AdjustableText.js'; const User = [ { name: 'Guest', avatar_url: Assets.logo.profileHolder, subtitle: '', icon: 'chevron-right', }, ]; const Options = [ { title: 'My Profile', icon: 'account', screen: 'MyProfile', props: { tab: 0, onBackPress: () => console.log('backed') } }, { title: 'Top-up Points', icon: 'topup', screen: 'TopUp', }, { title: 'Fuel Efficiency Tracker', icon: 'fuelTab', screen: 'Tracker', }, ]; const Options2 = [ { title: 'About Us', icon: 'about', screen: 'About', }, { title: 'Loyalty Program', icon: 'card', screen: 'Loyalty', }, { title: 'Contact Us', icon: 'contact', screen: 'Contact', }, { title: 'Getting Started', icon: 'tutorial', screen: 'OnBoarding', }, ]; const Drawer = createDrawerNavigator(); const styles = { container: { padding: 13, paddingTop: 14 }, title: { fontSize: 13, marginLeft: 12 }, titleDisabled: { fontSize: 13, marginLeft: 12, color: '#7e7e7e' }, icon: { size: 28 }, enrollBtn: { backgroundColor: '#e74610', height: Theme.screen.h / 17, marginHorizontal: 15, borderRadius: 10, alignItems: 'center', justifyContent: 'center', }, enrollBtnTxt: { textAlign: 'center', alignItems: 'center', color: '#fff', fontWeight: '600', fontSize: 16, }, marginEnroll: { ...Platform.select({ ios: { marginTop: Theme.screen.h / 2 - 270, }, android: { marginTop: Theme.screen.h / 2 - 230, }, }), }, }; class CustomDrawer extends React.PureComponent { constructor(props) { super(props) this.logoutdialog = false } state = { loading: false, guest: false } componentDidMount() { this.init() } componentWillUnmount() { } init = async () => { let isGuest = await DB.get('is_guest'); this.setState({ guest: isGuest }) }; onLogout = async () => { this.setState({ loading: true }) NetInfo.netstatus(async (isConnected) => { if (isConnected) { this.setState({ loading: false }) this.logoutAccount(success => { let props = this.props.props props.navigation.reset({ index: 0, routes: [{ name: 'Mpin' }], }); }, error => { }) } else { this.setState({ loading: false }) Elements.nointernet2(this.props); } }) }; logoutAccount = (successCallback, errorCallback) => { DB.logoutAccount(success => { successCallback() }, error => { errorCallback() }) } navigateTo = (screen = null, param = null, drawerParam = null) => { let props = this.props.props let params = screen == "OnBoarding" ? { onBackToMain: () => this.backToMainView() } : param props.navigation.closeDrawer(drawerParam) props.navigation.navigate(screen, params) } renderItem(item) { let range = 4; let indexes = [0, 4, 8, 12]; let cn = ''; for (let i = 0; i < indexes.length; i++) { cn += item.subtitle.substr(indexes[i], range) + (i < indexes.length - 1 ? ' ' : '') } if (this.state.guest) { return ( Guest You are not login! ); } else { return ( {item.name} {cn} this.navigateTo('Account', { test: {} })} /> ); } } backToMainView = () => { this.props.props.navigation.navigate('Main') } render() { return ( index.toString()} bounces={false} data={this.props.User} navigation={this.props.navigation} renderItem={({ item, index }) => { return this.renderItem(item, index) }} style={{ flexGrow: 0 }} /> {Options.map((item, i) => ( { this.navigateTo(item.screen, item.props || {}) }}> {item.title} ))} {Options2.map((item, i) => ( { this.navigateTo(item.screen, item.props || {}, item.screen) }}> {item.title} ))} {this.state.guest ? ( { let props = this.props.props await DB.set("is_guest", "false", () => { props.navigation.reset({ index: 0, routes: [{ name: 'Login' }], }); }, () => { }); }}> Enroll Your Card Now ) : ( { this.props.props.navigation.closeDrawer(); Alert.alert("Logout", '\n' + 'Are you sure you want to logout?', [{ text: "CANCEL", onPress: () => { } }, { text: "OK", onPress: () => this.onLogout() }]) }} > Logout )} ) } } const mapStateToProps = (state) => { return { app_theme: state.appThemeReducer.theme } } const mapDispatchToProps = { openModal } export default connect(mapStateToProps, mapDispatchToProps)(CustomDrawer)