import * as React from 'react'; import { useState, useEffect, useRef } from 'react'; import { connect } from "react-redux"; import { Platform, StyleSheet, SafeAreaView, TouchableOpacity, Button, View, Text, Image, TextInput, Alert, Modal } from 'react-native'; import {useNetInfo} from "@react-native-community/netinfo"; // import NetInfo from "@react-native-community/netinfo"; import NetInfo from "../../components/netstatus"; import CustomHeader from '../../components/header.js'; import Assets from '../../components/assets.manager.js'; import Elements from '../../components/elements.js'; import Theme from '../../components/theme.style.js'; import Icon from '../../components/icons.js'; import moment from 'moment'; import DB, { setsession } from '../../components/storage/'; import REQUEST from '../../components/api/'; import CustomSafeArea from '../../components/safeArea.component'; class LoginBirthday extends React.Component { constructor(props) { super(props) } state = { loading: false, datepicker: false, focus: false, activeInput: null, agree: false, birthdate: "", cardnumber: null, deviceUUID: null, valid: false, } componentDidMount() { this.init() } componentWillUnmount() { } init = async () => { this.setState({ cardnumber: this.props.route.params?.cardnumber, deviceUUID: this.props.route.params?.deviceUUID }) } setCardNumber = () => { this.setState({ valid: cardnumber.length == 15 ? true : false }) } onAgree = () => { this.setState({ agree: this.state.agree == false ? true : false }) if(this.state.cardnumber && !this.state.agree && this.state.birthdate){ this.setState({ valid: true }) }else{ this.setState({ valid: false }) } } requestOTP = async (lcard_uuid, mobile_number, successCallback, errorCallback) => { this.setState({ loading: true }) let params = `lcard_uuid=${lcard_uuid}&mobile=${Theme.formatter.PMBL(mobile_number)}&is_resend=false`; await REQUEST("requestOTP", "get", {}, params, {}, function(res){ successCallback(res) }, function(error){ errorCallback(error) }, "OTP", "Request" ) } submitForm = () => { NetInfo.netstatus(isConnected => { if(isConnected) { this.onSubmit(success => { this.requestOTP(success.lcard_uuid, success.mobile_number, onSuccess => { this.setState({ loading: false }) if(onSuccess.status == 1) { this.props.navigation.navigate("AccountOtp", { data: success, callback: this.props.route.params?.callback, type: this.props.route.params?.type }) } }, err => { Alert.alert("Information", `\n${err.message}`); this.setState({ loading: false }) }) }, err => { Alert.alert("Information", `\n${err.message}`); this.setState({ loading: false }) }) } else { Elements.nointernet2(this.props) } }) } onSubmit = async (successCallback, errorCallback) => { if(this.state.valid){ this.setState({ loading: true }) let formatbday = Theme.formatter.DT4API(this.state.birthdate) await REQUEST("login", "post", {}, {}, { birthdate: formatbday, deviceUUID: this.state.deviceUUID, card_number: this.state.cardnumber }, (data) => { if(data.data?.lcard_uuid && data.status == 1) { let sessiondata = { birthdate: formatbday, card_number: this.state.cardnumber, lcard_uuid: data.data?.lcard_uuid, mobile_number: data.data?.mobile_number } successCallback(sessiondata) } else { this.setState({ loading: false }) if(Platform.OS == 'ios'){ setTimeout(() => { Alert.alert("Information", '\n' + data.message) }, 700) }else{ Alert.alert("Information", '\n' + data.message) } errorCallback() } }, (error) => { this.setState({ loading: false }) errorCallback(error) }, "Login Credentials", "Submit") } } render() { return ( this.props.navigation.goBack()} navigation={this.props.navigation} /> Login Have an activated card? {this.state.cardnumber} this.props.navigation.goBack()} style={{flex: 0.4, alignSelf: 'flex-end', textAlign: 'right'}}> this.setState({ datepicker: true })}> Birthday {this.state.birthdate || "Select Date"} this.state.birthdate ? this.onAgree() : null} style={{flex: 0, paddingTop: 15}}> {!this.state.agree ? : } I agree to this.props.navigation.navigate("TermsConditions", {screen: "back"})}> Unioil's Data Privacy Policy. this.submitForm()} disabled={!this.state.valid} style={{padding: 20, paddingTop: 15, width: Theme.screen.w - 60, paddingBottom: 15, borderRadius: 10, backgroundColor: this.state.valid ? Theme.colors.primary : this.props.app_theme?.theme.dark ? this.props.app_theme?.theme.colors.border : Theme.colors.primary + "15"}}> Next { this.setState({ birthdate: selectedDate ? moment(selectedDate).format("MMMM DD, YYYY") : this.state.birthdate != null ? this.state.birthdate : null, datepicker: false }) }} onCancel={() => this.setState({ datepicker: false })} /> ); } } const mapStateToProps = (state) => { return { app_theme: state.appThemeReducer.theme } } export default connect(mapStateToProps, null)(LoginBirthday);