import * as React from 'react'; import { StyleSheet, TouchableOpacity, View, Text, Image, Alert, Keyboard, ImageBackground } from 'react-native'; import { ContactOptions } from '../../components/contact.action'; import { connect } from "react-redux"; import DeviceInfo from "react-native-device-info"; import NetInfo from "../../components/netstatus"; 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 REQUEST from '../../components/api/'; import DB from '../../components/storage/'; import CustomInput from '../../components/custominput'; import CustomSafeArea from '../../components/safeArea.component'; import { Actionsheet, StatusBar } from 'native-base'; import elements from '../../components/elements.js'; class AddAccountCard extends React.PureComponent { constructor(props) { super(props) } state = { loading: false, focus: false, activeInput: null, cardnumber: "", deviceUUID: "", valid: false, mobilenumber: "", agree: false, openOptions: false } componentDidMount() { if(this.props.route.params?.reset){ this.reset() } this.init() } componentWillUnmount() { } init = async () => { await DB.reset() this.setState({ deviceUUID: await DB.get("deviceUUID") }) } reset = () => { this.setState({ loading: false, focus: false, activeInput: null, cardnumber: "", deviceUUID: "", valid: false, mobilenumber: "", agree: false }) } onErrorWarning = (success) => { console.log(success) if(Platform.OS == 'ios'){ setTimeout(() => { Alert.alert("Error", '\n' + success.message) }, 700) }else{ Alert.alert("Error", success.message) } } onSubmit = () => { Keyboard.dismiss(); NetInfo.netstatus(isConnected => { if(isConnected) { this.setState({ loading: true }) this.validateMobileNumber(success => { console.log(success) if(success.data.is_valid == 1 && success.status == 1){ this.setState({ loading: false }) this.props.navigation.navigate("LoginSendOTP", { lcard_uuid: success.data.user_id, mobile_number: Theme.formatter.MBNF(this.state.mobilenumber, 63), card_number: success.data.card_number }) } else { this.setState({ loading: false }) this.onErrorWarning(success) } }, error => { this.setState({ loading: false }) console.log(error) }) } else { this.setState({ loading: false }) Elements.nointernet2(this.props) } }) } onAgree = () => { this.setState({ agree: this.state.agree == false ? true : false }) } validateMobileNumber = async (successCallback, errorCallback) => { let phoneNumber = Theme.formatter.MBNF(this.state.mobilenumber, "") if(phoneNumber == null) { setTimeout(() => { Alert.alert("Error", '\n' + "Invalid mobile number") }, 700) this.setState({ loading: false }) return } await REQUEST("login_mobile", "post", {}, {}, { deviceUUID: this.state.deviceUUID, mobile_number: phoneNumber }, function(data){ successCallback(data) }, function(error){ errorCallback(error) }) } render() { let version = `v${DeviceInfo.getReadableVersion()}` return ( Make Life Rewarding Enter your mobile number. { let value = val.includes(".") ? val.replace(".", "") : val this.setState({ mobilenumber: value, valid: value.length == 13 ? true : false, agree: false }) }} /> this.state.valid ? this.onAgree() : null} style={{flex: 0, padding: 8}}> {!this.state.agree || !this.state.valid ? : } I agree to Unioil's this.props.navigation.navigate("TermsConditions")}> Data Privacy Policy. this.onSubmit()} disabled={(!this.state.agree || !this.state.valid)} style={{padding: 20, paddingTop: 15, width: Theme.screen.w * .73, paddingBottom: 15, borderRadius: 10, backgroundColor: (this.state.agree && this.state.valid) ? Theme.colors.primary : Theme.colors.darkGray + "40"}}> Log In or this.props.navigation.navigate("EnrollActivate", {screen: "Login"}) } style={{padding: 15, paddingTop: 12, width: Theme.screen.w * .65, paddingBottom: 12, borderRadius: 10, borderWidth: 2, borderColor: Theme.colors.white}}> Activate your Card this.props.navigation.navigate("ApplySelectCard") } style={{padding: 15, paddingTop: 12, width: Theme.screen.w * .65, paddingBottom: 12, borderRadius: 10, borderWidth: 2, borderColor: Theme.colors.white}}> Apply for a Card this.props.navigation.navigate("TermsConditions") } style={{paddingHorizontal: 15, width: Theme.screen.w - 80, paddingBottom: 12}}> Enter as Guest {this.setState({ openOptions: true })}} style={{padding: 15, alignItems: 'flex-start', flex: 1}}> Contact Us {}} style={{padding: 15, justifyContent: 'flex-end', flex: 1}}> {version} this.setState({ openOptions: false })}/> ) } } const mapStateToProps = (state) => { return { app_theme: state.appThemeReducer.theme } } export default connect(mapStateToProps, null)(AddAccountCard);