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