import React, { Component } from "react"; import { Platform, StyleSheet, View, TextInput, TouchableOpacity } from "react-native"; import { observable } from "mobx"; import { observer, inject } from "mobx-react/native"; import Text from "react-native-text"; import { scale, verticalScale, moderateScale } from "react-native-size-matters"; import { Dropdown } from "react-native-material-dropdown"; import { Button } from "react-native-elements"; import firebase from "react-native-firebase"; import Toast, { DURATION } from "react-native-easy-toast"; //component import DrawerNavigationHeader from "../../components/Public/drawerNavigationHeader"; import theme from "../../config/colors"; import { Fonts } from "../../config/fonts"; import Size from "../../config/size"; import Countdown, { CountdownStatus } from "rn-countdown"; // function import { width, height } from "../../config/screen"; import AsyncStorageHelper from "../../config/asyncStorageHelper"; import Loader from "../../components/Public/loader"; const asyncStorageHelper = new AsyncStorageHelper(); const size = new Size(); @inject(["menuStore"], ["userStore"]) @observer export default class AccountSettings extends Component { @observable pickupPointIndexExist = false; password = ""; pickupPoint = []; @observable index = 1; @observable code = 0; @observable password = ""; @observable verificationCode = ""; static navigationOptions = { drawerLabel: "Account" }; constructor(props) { super(props); this.store = this.props.userStore; this.menuStore = this.props.menuStore; } navigatieAction(page, Param) { this.props.navigation.navigate(page, Param); } checking() { asyncStorageHelper.getData("pickupPointId", pickupPointId => { if (pickupPointId != null) { console.log("index: " + pickupPointId); this.pickupPointIndexExist = true; this.index = this.getIndex(pickupPointId); } }); } changeIndex(index) { this.tabMap.index = index; } positionValue() { if (this.pickupPointIndexExist) { return this.store.pickupPointLabel[this.pickupPointIndex].value; } else { return null; } } positionChange(id) { asyncStorageHelper.saveData("pickupPointId", id); this.menuStore.getMenuItem(); } handleNetworkFailed = () => alert("network failed"); handleStopCountdown = () => this.countdown && this.countdown.stopCountdown(); handleClickCountdown = () => { var bodyFormData = new FormData(); bodyFormData.append("country_code", "852"); bodyFormData.append( "phone_number", this.store.userData.data.member.mobile.toString() ); this.store.sendsmsVerify(bodyFormData, this); }; getIndex(id) { var index = this.store.pickupPointLabel.findIndex(function(item, i) { return item.id == parseInt(id); }); return index; } startToCountDown = () => { this.countdown && this.countdown.startCountdown(); }; resetPassword() { // this.store.signupPost(api.signup, this.signInData, this); if (this.verificationCode != null || this.verificationCode != "") { if (this.password != null || this.password != "") { if (this.password.length >= 8) { var data = { verificationCode: this.verificationCode, mobile: this.store.userData.data.member.mobile.toString(), countryCode: "852", password: this.password }; this.store.forgotPassword(data, this); } else { this.refs.toast.show("your password must be at least 8 characters"); } } else { this.refs.toast.show("Please enter reset password"); } } else { this.refs.toast.show("Please enter verification number"); } } countDownButton() { return ( (this.countdown = r)} time={60} onPress={this.handleClickCountdown} onNetworkFailed={this.handleNetworkFailed} onDidFinishCountdown={this.handleCountdownOver} > {({ status, time }) => { let title, containerStyle, titleStyle; switch (status) { case CountdownStatus.Idle: title = "send"; containerStyle = styles.countdown; titleStyle = styles.countdownTitle; break; case CountdownStatus.Counting: title = `sent(${time})`; containerStyle = styles.countdown; titleStyle = styles.countdownTitle; break; case CountdownStatus.Over: title = "send"; containerStyle = styles.countdown; titleStyle = styles.countdownTitle; break; } return ( {title} ); }} ); } render() { if (this.store.logined) { this.checking(); return ( {this.store.userData.data.member.name} {this.store.userData.data.member.email} +{this.store.userData.data.member.countryCode}{" "} {this.store.userData.data.member.mobile} (this.password = value)} /> {this.countDownButton()} (this.verificationCode = text)} placeholderTextColor={theme.foodNameColor} />