|
|
|
@ -1,10 +1,23 @@ |
|
|
|
|
import React, {useEffect, useState} from 'react' |
|
|
|
|
import {View, Text, Image, TextInput, TouchableHighlight, Dimensions, StyleSheet, TouchableOpacity} from 'react-native'; |
|
|
|
|
import { |
|
|
|
|
View, |
|
|
|
|
Text, |
|
|
|
|
Image, |
|
|
|
|
TextInput, |
|
|
|
|
TouchableHighlight, |
|
|
|
|
Dimensions, |
|
|
|
|
StyleSheet, |
|
|
|
|
TouchableOpacity, |
|
|
|
|
ActivityIndicator |
|
|
|
|
} from 'react-native'; |
|
|
|
|
import {connect} from 'react-redux'; |
|
|
|
|
import Logo from "../../assets/images/logo.png"; |
|
|
|
|
import IranFlag from "../Login/components/IranFlag"; |
|
|
|
|
import {digitToEn, digitToPersian} from "../../utils"; |
|
|
|
|
import services from "./services"; |
|
|
|
|
import AsyncStorage from "@react-native-community/async-storage"; |
|
|
|
|
import {buildAction} from "../../reducers/DefaultReducer"; |
|
|
|
|
import {PROFILE_RECORD} from "../../actions/actionTypes"; |
|
|
|
|
|
|
|
|
|
const {width} = Dimensions.get('window') |
|
|
|
|
let ref1; |
|
|
|
@ -13,6 +26,13 @@ let ref3; |
|
|
|
|
let ref4; |
|
|
|
|
|
|
|
|
|
let timer = 60; |
|
|
|
|
|
|
|
|
|
const mapStateToProps = state => { |
|
|
|
|
return { |
|
|
|
|
profile: state.profile, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function Otp(props) { |
|
|
|
|
let faNums = ['۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹', '۰'] |
|
|
|
|
|
|
|
|
@ -21,6 +41,7 @@ function Otp(props) { |
|
|
|
|
const [thirdCode, setThirdCode] = useState(''); |
|
|
|
|
const [fourthCode, setFourthCode] = useState(''); |
|
|
|
|
const [time, setTime] = useState(60); |
|
|
|
|
const [loading, setLoading] = useState(false); |
|
|
|
|
|
|
|
|
|
const checkValue = (value) => { |
|
|
|
|
return faNums.includes(digitToPersian(value)); |
|
|
|
@ -45,6 +66,7 @@ function Otp(props) { |
|
|
|
|
break; |
|
|
|
|
case '4': |
|
|
|
|
setFourthCode(digitToPersian(value)) |
|
|
|
|
submit(); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -54,13 +76,29 @@ function Otp(props) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const submit = async () => { |
|
|
|
|
setLoading(true) |
|
|
|
|
let res = await services.sendOtpCode({ |
|
|
|
|
cellphone: props.route.params.phone, |
|
|
|
|
otp: getEnCode() |
|
|
|
|
otp: String(getEnCode()), |
|
|
|
|
applicationToken: "1", |
|
|
|
|
userToken: "1" |
|
|
|
|
}) |
|
|
|
|
if (res.ok) { |
|
|
|
|
console.log(res) |
|
|
|
|
setLoading(false) |
|
|
|
|
await AsyncStorage.setItem('accessToken', res.data.accessToken); |
|
|
|
|
await AsyncStorage.setItem('refreshToken', res.data.refreshToken); |
|
|
|
|
let action = buildAction(PROFILE_RECORD); |
|
|
|
|
await props.dispatch(action({ |
|
|
|
|
accessToken: res.data.accessToken, |
|
|
|
|
refreshToken: res.data.refreshToken, |
|
|
|
|
...res.data.profile, |
|
|
|
|
})) |
|
|
|
|
props.navigation.reset({ |
|
|
|
|
index: 0, |
|
|
|
|
routes: [{name: 'Home'}] |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
setLoading(false) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
@ -148,6 +186,7 @@ function Otp(props) { |
|
|
|
|
/> |
|
|
|
|
</View> |
|
|
|
|
<TouchableOpacity |
|
|
|
|
disabled={loading} |
|
|
|
|
style={{ |
|
|
|
|
width: width - 10, |
|
|
|
|
height: width / 9, |
|
|
|
@ -158,12 +197,15 @@ function Otp(props) { |
|
|
|
|
marginTop: 15, |
|
|
|
|
}} |
|
|
|
|
onPress={() => submit()}> |
|
|
|
|
{loading ? |
|
|
|
|
<ActivityIndicator color={'white'} size={'small'} /> : |
|
|
|
|
<Text style={{ |
|
|
|
|
color: 'white', |
|
|
|
|
fontSize: 18, |
|
|
|
|
}}> |
|
|
|
|
{'ثبت'} |
|
|
|
|
</Text> |
|
|
|
|
} |
|
|
|
|
</TouchableOpacity> |
|
|
|
|
<View> |
|
|
|
|
<Text style={{marginTop: 30, textAlign: 'center'}}> |
|
|
|
@ -174,10 +216,10 @@ function Otp(props) { |
|
|
|
|
marginTop: 20, |
|
|
|
|
}} |
|
|
|
|
onPress={() => { |
|
|
|
|
if (time !== 0) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
props.navigation.goBack(); |
|
|
|
|
props.navigation.reset({ |
|
|
|
|
index: 0, |
|
|
|
|
routes: [{ name: 'Login' }], |
|
|
|
|
}); |
|
|
|
|
}}> |
|
|
|
|
<Text style={{textAlign: 'center'}}> |
|
|
|
|
{'بازگشت به مرحله قبل و اصلاح شماره'} |
|
|
|
@ -193,11 +235,11 @@ const styles = StyleSheet.create({ |
|
|
|
|
width: width / 13 * 2, |
|
|
|
|
height: width / 16 * 2, |
|
|
|
|
backgroundColor: '#a2a2a2', |
|
|
|
|
color: '#333', |
|
|
|
|
color: '#000', |
|
|
|
|
fontSize: 22, |
|
|
|
|
borderRadius: 8, |
|
|
|
|
textAlign: 'center' |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
export default Otp; |
|
|
|
|
export default connect(mapStateToProps)(Otp); |
|
|
|
|