139 lines
4.2 KiB
JavaScript
139 lines
4.2 KiB
JavaScript
|
|
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('<body>', `<body style="${contentStyle}">`)
|
|
return (
|
|
<WebView
|
|
domStorageEnabled={true}
|
|
originWhitelist={['*']}
|
|
source={{ html: content }}
|
|
style={{
|
|
backgroundColor: 'transparent',
|
|
width: Theme.screen.w,
|
|
height: Theme.screen.h,
|
|
padding: 15
|
|
}}
|
|
/>
|
|
)
|
|
}
|
|
|
|
render() {
|
|
if(!this.state.connection){
|
|
return (
|
|
<SafeAreaView style={{flex: 1}}>
|
|
<CustomHeader title="" menu={false} onBackPress={() => {
|
|
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} />
|
|
</SafeAreaView>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<CustomSafeArea>
|
|
<CustomHeader title="" menu={false} onBackPress={() => {
|
|
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} />
|
|
<View style={{flex: 1 }}>
|
|
{this.renderWebView()}
|
|
</View>
|
|
{this.state.connection && !this.sender ? <View style={{padding: 15, paddingTop: 5}}>
|
|
<TouchableOpacity onPress={() => this.setGuest() }>
|
|
<Text style={{textAlign: 'right', color: Theme.colors.primary, fontSize: 16}}>I Accept</Text>
|
|
</TouchableOpacity>
|
|
</View> : null }
|
|
</CustomSafeArea>
|
|
);
|
|
}
|
|
}
|
|
|
|
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)
|