splash.js 4.11 KB

import React from 'react';
import OneSignal from 'react-native-onesignal'
import { AppRegistry, View, Text, TouchableOpacity, Image, StyleSheet, } from 'react-native';
import { NavigationActions, StackActions } from 'react-navigation';
import NetInfo from '@react-native-community/netinfo';
import Snackbar from 'react-native-snackbar';
import { API } from "./WebServices/RestClient";
import AsyncStorage from '@react-native-community/async-storage';
//One signal new method since they relesed the SDK new version and havent relese complete documentation as example 
//id :25b8f6bc-6ba5-467c-aa1d-8d40aff11a82


const resetAction = StackActions.reset({
  index: 0,
  actions: [
    NavigationActions.navigate({ routeName: 'NavigationRouter' })
  ]
})

export default class App extends React.Component {


  constructor(props) {
    super(props);

    this.state = {
      name: props.name,
      isSubscribed: false,
      requiresPrivacyConsent: false,
      isLocationShared: false,
      inputValue: "",
      consoleValue: ""
    }
  }

  async componentDidMount() {
    /* O N E S I G N A L   S E T U P */
    OneSignal.setAppId("25b8f6bc-6ba5-467c-aa1d-8d40aff11a82");
    OneSignal.setLogLevel(6, 0);
    OneSignal.setRequiresUserPrivacyConsent(this.state.requiresPrivacyConsent);
    OneSignal.promptForPushNotificationsWithUserResponse(response => {
      this.OSLog("Prompt response:", response);
    });


    OneSignal.setNotificationOpenedHandler(notification => {
      console.log("OneSignal: notification opened:", notification);
    });
  
    OneSignal.setInAppMessageClickHandler(event => {
      //this.OSLog("OneSignal IAM clicked:", event);
    });
    OneSignal.addEmailSubscriptionObserver((event) => {
      // this.OSLog("OneSignal: email subscription changed: ", event);
    });
    OneSignal.addSubscriptionObserver(event => {
      // this.OSLog("OneSignal: subscription changed:", event);
      this.setState({ isSubscribed: event.to.isSubscribed })
    });
    OneSignal.addPermissionObserver(event => {
      // this.OSLog("OneSignal: permission changed:", event);
    });
    const state = await OneSignal.getDeviceState();
    // alert(this.state.userId)
    AsyncStorage.setItem('userId', state.userId);
    console.log(state.userId)
    setTimeout(
            () => {
              this.Maintenance();
            },
            2000
          );
  }

//Maintanace Page for Checking the Heathcheck
  Maintenance = () => {
    NetInfo.fetch().then(state => {
      if (state.type == "none" || state.type == "unknown" || state.type == 'undefined') {
        console.log(state.type);
        Snackbar.show({
          title: 'No Internet Connection',
          backgroundColor: '#b52424',
          textAlign:'center',
          alignItems: 'center',
          duration: Snackbar.LENGTH_LONG,
        });
        // this.props.navigation.dispatch(respropsetAction)
        this.props.navigation.dispatch(resetAction)
      } 
      else {
        fetch(API + "healthCheck.php")
          .then((response) => response.json())
          .then((responseJson) => {
            console.warn(JSON.stringify(responseJson))
            if (responseJson.dbconnect === 'dbconnected') {
              console.warn(responseJson);

              this.props.navigation.dispatch(resetAction)
            }
            else {
              console.warn(responseJson);
              this.props.navigation.navigate('Maintenance');
            }
          })
          .catch((error) => {
            this.props.navigation.navigate('Maintenance');
            console.log(error);

          });
      }
    });

  };

  render() {

    return (
      <View style={{ flex: 1, justifyContent: "center", alignItems: "center", }} >
        <Image style={{ width: 400, height: 150 }} source={require('./Images/agile2.png')} />
        <Text style={styles.text}>Powered by Novisync</Text>
        <Text></Text>
        <Text style={styles.text1}>1.0.1  15-09-2021</Text>
      </View>
    );
  };
}
const styles = StyleSheet.create({

  text: {

    textAlign: 'center',
    fontSize: 20,
    color: 'black',


  },
  text: {

    textAlign: 'center',
    fontSize: 15,
    color: 'black',


  },
})