import * as React from 'react'; import { connect } from "react-redux"; import { View, Text, StyleSheet, TouchableOpacity, ScrollView, RefreshControl, Alert } from 'react-native'; import { WebView } from 'react-native-webview'; import NetInfo from "../../components/netstatus" import CustomHeader from '../../components/header.js'; import Theme from '../../components/theme.style.js'; import Elements from '../../components/elements.js'; import DB from '../../components/storage/'; import REQUEST from '../../components/api/'; import CustomSafeArea from '../../components/safeArea.component'; class Rewards extends React.Component { constructor(props) { super(props) } state = { loading: true, data: "", connection: false, guest: false, } componentDidMount() { this.initRewards() } componentWillUnmount() { } initRewards = () => { NetInfo.netstatus(isConnected => { if(isConnected) { this.init() } else { Elements.nointernet2(this.props) } }) } init = async () => { let isGuest = await DB.get("is_guest"); const SESSION = await DB.session() this.setState({ guest: isGuest, connection: true }) if(!this.state.guest){ try{ await REQUEST("shared_treats", "get", { Authorization: SESSION.token }, {}, {}, async (res) => { if(res.status == 1 && res.data){ this.setState({ data: res.data, loading: false, refreshing: false }) } }, (err) => { if(err?.message){ Alert.alert("Information", `\n${err?.message}`); this.setState({ loading: false, refreshing: false }) } }, "Shared treats", "Fetch" ) } catch(err) { this.setState({ loading: false, refreshing: false }) } } } onReload = () => { this.setState({ refreshing: true }); this.init(); } toRender = () => { if(!this.state.connection && !this.state.loading){ return ( this.initRewards()} /> ) } return ( } > ) } render() { return ( { !this.state.guest ? {this.toRender()} : You won't be able to access some of the pages unless you will apply for a card or login. { this.props.navigation.navigate('Login') }}> Enroll Card } ); } } const mapStateToProps = (state) => { return { app_theme: state.appThemeReducer.theme } } export default connect(mapStateToProps, null)(Rewards) export const styles = StyleSheet.create({ enrollBtn: { backgroundColor: '#e74610', height: Theme.screen.h / 19, marginHorizontal: 15, borderRadius: 10, alignItems: 'center', justifyContent: 'center', marginVertical: 15, paddingHorizontal: 15, elevation: 2 }, enrollBtnTxt: { textAlign: 'center', alignItems: 'center', color: '#fff', fontWeight: '600', fontSize: 14 }, viewStyle: { height: Theme.screen.h, flex: 1, flexDirection: 'row', justifyContent: 'center' }, viewStyle1: { justifyContent: 'center', alignItems: 'center', textAlign: 'center', } })