244 lines
7.5 KiB
JavaScript
244 lines
7.5 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()
|
|
}
|
|
})
|
|
}
|
|
|
|
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)
|
|
|
|
// const TermsConditions = (props) => {
|
|
|
|
// const sender = props.route?.params
|
|
// const [connection, setconnection] = useState(false)
|
|
// const [data, setdata] = useState(props.terms_and_conditions)
|
|
// const netInfo = useNetInfo()
|
|
|
|
// const init = async () => {
|
|
// try{
|
|
// await REQUEST("terms_and_privacy", "get", {}, {}, {},
|
|
// async (res) => {
|
|
// if(res.status == 1 && res.data){
|
|
// await setdata(await res.data)
|
|
// props.saveAppTermsAndConditions(res.data)
|
|
// }else{
|
|
// console.log(res.message, res.data)
|
|
// }
|
|
// }, function(error){
|
|
// console.log(error)
|
|
// }
|
|
// )
|
|
// }catch(error){
|
|
// console.log(error)
|
|
// }
|
|
// }
|
|
|
|
// useEffect(() => {
|
|
// NetInfo.fetch().then(state => {
|
|
// if(state.isConnected){
|
|
// setconnection(true)
|
|
// if(props.terms_and_conditions == undefined) init()
|
|
// }else{
|
|
// Elements.nointernet2()
|
|
// }
|
|
// });
|
|
// }, [props])
|
|
|
|
// const setGuest = async () => {
|
|
// await DB.set("is_guest", "true", () =>{
|
|
// props.navigation.navigate("OnBoarding")
|
|
// }),
|
|
// (error) => {
|
|
// console.log(error)
|
|
// }
|
|
// }
|
|
|
|
// const render = () => {
|
|
// let contentStyle = `font-size: 29pt; font-family: 'Arial'; color: rgba(0, 0, 0, 0.6); padding:4%; padding-top: 1%;padding-bottom: 10%;`;
|
|
// let content = 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
|
|
// }}
|
|
// />)
|
|
// }
|
|
|
|
// if(!connection){
|
|
// return (
|
|
// <SafeAreaView style={{flex: 1}}>
|
|
// <CustomHeader title="" menu={false} onBackPress={() => {
|
|
// if(sender && sender.screen != "back") props.navigation.navigate(sender.screen)
|
|
// else if(sender && sender.screen == 'back') props.navigation.goBack()
|
|
// else props.navigation.navigate("Login")
|
|
// }} navigation={props} />
|
|
// </SafeAreaView>
|
|
// )
|
|
// }
|
|
|
|
// return (
|
|
// <SafeAreaView style={{flex: 1}}>
|
|
// <CustomHeader title="" menu={false} onBackPress={() => {
|
|
// if(sender && sender.screen != "back") props.navigation.navigate(sender.screen)
|
|
// else if(sender && sender.screen == 'back') props.navigation.goBack()
|
|
// else props.navigation.navigate("Login")
|
|
// }} navigation={props} />
|
|
// <View style={{flex: 1 }}>
|
|
// {render()}
|
|
// </View>
|
|
// {netInfo.isConnected && !sender ? <View style={{padding: 15, paddingTop: 5}}>
|
|
// <TouchableOpacity onPress={() => setGuest() }>
|
|
// <Text style={{textAlign: 'right', color: Theme.colors.primary, fontSize: 16}}>I Agree</Text>
|
|
// </TouchableOpacity>
|
|
// </View> : null }
|
|
// </SafeAreaView>
|
|
// );
|
|
// }
|
|
|
|
// const mapStateToProps = (state) => {
|
|
// return {
|
|
// terms_and_conditions: state.appTermsAndConditionsReducer.terms_and_conditions
|
|
// }
|
|
// }
|
|
|
|
// const mapDispatchToProps = {
|
|
// saveAppTermsAndConditions
|
|
// }
|
|
|
|
// export default connect(mapStateToProps, mapDispatchToProps)(TermsConditions)
|