import * as React from 'react'; import { useState, useEffect } from 'react'; import { SafeAreaView, TouchableOpacity, View, Text } from 'react-native'; import { WebView } from 'react-native-webview'; import { useNetInfo } from "@react-native-community/netinfo"; import { connect } from "react-redux"; import { saveAppTermsAndConditions } from "../../redux/actions/AppTermsAndConditionsActions"; 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 NetInfo from "../../components/netstatus" import CustomSafeArea from '../../components/safeArea.component'; class TermsConditions extends React.PureComponent { constructor(props) { super(props) this.sender = props.route?.params } state = { connection: false, data: this.props.terms_and_conditions } componentDidMount() { this.init() } componentWillUnmount() { } init = () => { NetInfo.netstatus(isConnected => { if(isConnected){ this.setState({ connection: true }) if(this.props.terms_and_conditions == undefined) this.fetchTermsAndPrivacy() }else{ Elements.nointernet2(this.props) } }) } fetchTermsAndPrivacy = async () => { try{ await REQUEST("terms_and_privacy", "get", {}, {}, {}, async (res) => { if(res.status == 1 && res.data){ this.setState({ data: res.data }) this.props.saveAppTermsAndConditions(res.data) }else{ console.log(res.message, res.data) } }, function(error){ console.log(error) } ) }catch(error){ console.log(error) } } setGuest = async () => { await DB.set("is_guest", "true", () =>{ this.props.navigation.navigate("OnBoarding") }), (error) => { console.log(error) } } renderWebView = () => { let contentStyle = `font-size: 29pt; font-family: 'Arial'; color: ${this.props.app_theme?.theme.colors.text}; padding:4%; padding-top: 1%;padding-bottom: 10%;`; let content = this.state.data?.replace('', ``) return ( ) } render() { if(!this.state.connection){ return ( { if(this.sender && this.sender.screen != "back") this.props.navigation.navigate(this.sender.screen) else if(this.sender && this.sender.screen == 'back') this.props.navigation.goBack() else this.props.navigation.navigate("Login") }} navigation={this.props} /> ) } return ( { if(this.sender && this.sender.screen != "back") this.props.navigation.navigate(this.sender.screen) else if(this.sender && this.sender.screen == 'back') this.props.navigation.goBack() else this.props.navigation.navigate("Login") }} navigation={this.props} /> {this.renderWebView()} {this.state.connection && !this.sender ? this.setGuest() }> I Accept : null } ); } } const mapStateToProps = (state) => { return { terms_and_conditions: state.appTermsAndConditionsReducer.terms_and_conditions, app_theme: state.appThemeReducer.theme } } const mapDispatchToProps = { saveAppTermsAndConditions } export default connect(mapStateToProps, mapDispatchToProps)(TermsConditions)