|
|
@ -11,6 +11,7 @@ import { |
|
|
|
import tw from "tailwind-rn"; |
|
|
|
import tw from "tailwind-rn"; |
|
|
|
import { connect } from "react-redux"; |
|
|
|
import { connect } from "react-redux"; |
|
|
|
import Svg, { Defs, Pattern, Image, Path } from "react-native-svg"; |
|
|
|
import Svg, { Defs, Pattern, Image, Path } from "react-native-svg"; |
|
|
|
|
|
|
|
import { asyncAwesomeAlert } from "../../utils/AsyncWrappers"; |
|
|
|
import { digitToEn } from "../../utils"; |
|
|
|
import { digitToEn } from "../../utils"; |
|
|
|
import onInput from "../../utils/onInput"; |
|
|
|
import onInput from "../../utils/onInput"; |
|
|
|
import { user } from "../../redux/actions"; |
|
|
|
import { user } from "../../redux/actions"; |
|
|
@ -25,14 +26,14 @@ let ref2; |
|
|
|
let ref3; |
|
|
|
let ref3; |
|
|
|
let ref4; |
|
|
|
let ref4; |
|
|
|
|
|
|
|
|
|
|
|
let timer = 60; |
|
|
|
let timer = 120; |
|
|
|
|
|
|
|
|
|
|
|
function Otp(props) { |
|
|
|
function Otp(props) { |
|
|
|
const [firstCode, setFirstCode] = useState(""); |
|
|
|
const [firstCode, setFirstCode] = useState(""); |
|
|
|
const [secondCode, setSecondCode] = useState(""); |
|
|
|
const [secondCode, setSecondCode] = useState(""); |
|
|
|
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(120); |
|
|
|
const [loading, setLoading] = useState(false); |
|
|
|
const [loading, setLoading] = useState(false); |
|
|
|
const [timeEnd, setTimeEnd] = useState(false); |
|
|
|
const [timeEnd, setTimeEnd] = useState(false); |
|
|
|
|
|
|
|
|
|
|
@ -86,18 +87,26 @@ function Otp(props) { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const submit = async () => { |
|
|
|
const submit = async () => { |
|
|
|
setLoading(true); |
|
|
|
if (firstCode && secondCode && thirdCode && fourthCode) { |
|
|
|
props.sendOtp({ |
|
|
|
props.sendOtp({ |
|
|
|
cellphone: props.route.params?.phone, |
|
|
|
cellphone: props.route.params?.phone, |
|
|
|
otp: String(getEnCode()), |
|
|
|
otp: String(getEnCode()), |
|
|
|
applicationToken: "1", |
|
|
|
applicationToken: "1", |
|
|
|
userToken: "1", |
|
|
|
userToken: "1", |
|
|
|
}); |
|
|
|
}); |
|
|
|
setLoading(false); |
|
|
|
} else { |
|
|
|
|
|
|
|
asyncAwesomeAlert("خطا", "کد تاییدیه را کامل وارد کنید.", { |
|
|
|
|
|
|
|
showCancelButton: false, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
ref1.focus(); |
|
|
|
ref1.focus(); |
|
|
|
|
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
if (!timeEnd) { |
|
|
|
let interval = setInterval(() => { |
|
|
|
let interval = setInterval(() => { |
|
|
|
if (time > 0) { |
|
|
|
if (time > 0) { |
|
|
|
setTime(timer - 1); |
|
|
|
setTime(timer - 1); |
|
|
@ -107,26 +116,58 @@ function Otp(props) { |
|
|
|
let timeout = setTimeout(() => { |
|
|
|
let timeout = setTimeout(() => { |
|
|
|
clearInterval(interval); |
|
|
|
clearInterval(interval); |
|
|
|
setTimeEnd(true); |
|
|
|
setTimeEnd(true); |
|
|
|
}, 60000); |
|
|
|
}, 10000); |
|
|
|
return () => { |
|
|
|
return () => { |
|
|
|
clearInterval(interval); |
|
|
|
clearInterval(interval); |
|
|
|
clearTimeout(timeout); |
|
|
|
clearTimeout(timeout); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, [timeEnd]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const duration = React.useCallback( |
|
|
|
|
|
|
|
(value) => { |
|
|
|
|
|
|
|
const minute = value % 60; |
|
|
|
|
|
|
|
const hour = Math.floor(value / 60); |
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
|
|
(hour > 0 |
|
|
|
|
|
|
|
? (hour.toString().length === 1 ? "0" + hour.toString() : hour) + "" |
|
|
|
|
|
|
|
: "") + |
|
|
|
|
|
|
|
":" + |
|
|
|
|
|
|
|
(minute.toString().length === 1 ? "0" + minute.toString() : minute) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
[props.route] |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const submitCellphone = React.useCallback(() => { |
|
|
|
|
|
|
|
setTimeEnd(false); |
|
|
|
|
|
|
|
setTime(120); |
|
|
|
|
|
|
|
setFirstCode(""); |
|
|
|
|
|
|
|
setSecondCode(""); |
|
|
|
|
|
|
|
setThirdCode(""); |
|
|
|
|
|
|
|
setFourthCode(""); |
|
|
|
|
|
|
|
props.sendCellphone({ cellphone: props.cellphone }); |
|
|
|
|
|
|
|
timer = 120; |
|
|
|
}, []); |
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
if (props.isLogin) { |
|
|
|
if (props.isLogin) { |
|
|
|
props.navigation.navigate('Root'); |
|
|
|
props.navigation.navigate("Root"); |
|
|
|
} |
|
|
|
} |
|
|
|
}, [props.isLogin]); |
|
|
|
}, [props.isLogin]); |
|
|
|
|
|
|
|
|
|
|
|
const goBack = () => { |
|
|
|
const goBack = () => { |
|
|
|
timer = 60; |
|
|
|
timer = 120; |
|
|
|
props.navigation.navigate("Login"); |
|
|
|
props.navigation.navigate("Login"); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<View style={[tw("px-4 flex-1 justify-center items-center bg-white"), {minHeight: height}]}> |
|
|
|
<View |
|
|
|
|
|
|
|
style={[ |
|
|
|
|
|
|
|
tw("px-4 flex-1 justify-center items-center bg-white"), |
|
|
|
|
|
|
|
{ minHeight: height }, |
|
|
|
|
|
|
|
]} |
|
|
|
|
|
|
|
> |
|
|
|
<Svg |
|
|
|
<Svg |
|
|
|
xmlns="http://www.w3.org/2000/svg" |
|
|
|
xmlns="http://www.w3.org/2000/svg" |
|
|
|
xmlnsXlink="http://www.w3.org/1999/xlink" |
|
|
|
xmlnsXlink="http://www.w3.org/1999/xlink" |
|
|
@ -165,7 +206,8 @@ function Otp(props) { |
|
|
|
}, |
|
|
|
}, |
|
|
|
]} |
|
|
|
]} |
|
|
|
> |
|
|
|
> |
|
|
|
یک کد تائیدیه به شماره{" "} |
|
|
|
{" "} |
|
|
|
|
|
|
|
یک کد تائیدیه به شماره |
|
|
|
<Text |
|
|
|
<Text |
|
|
|
style={{ |
|
|
|
style={{ |
|
|
|
color: Colors.theme1[props.theme].greenCF, |
|
|
|
color: Colors.theme1[props.theme].greenCF, |
|
|
@ -174,7 +216,7 @@ function Otp(props) { |
|
|
|
}} |
|
|
|
}} |
|
|
|
> |
|
|
|
> |
|
|
|
{props.route.params?.phone || "09123456789"} |
|
|
|
{props.route.params?.phone || "09123456789"} |
|
|
|
</Text>{" "} |
|
|
|
</Text> |
|
|
|
ارسال شد. آن را در قسمت زیر وارد کنید. |
|
|
|
ارسال شد. آن را در قسمت زیر وارد کنید. |
|
|
|
</Text> |
|
|
|
</Text> |
|
|
|
<View |
|
|
|
<View |
|
|
@ -299,13 +341,32 @@ function Otp(props) { |
|
|
|
}, |
|
|
|
}, |
|
|
|
]} |
|
|
|
]} |
|
|
|
> |
|
|
|
> |
|
|
|
{"زمان باقی مانده تا ارسال مجدد: " + time} |
|
|
|
{"زمان باقی مانده تا ارسال مجدد: " + duration(time)} |
|
|
|
</Text> |
|
|
|
</Text> |
|
|
|
) : ( |
|
|
|
) : ( |
|
|
|
|
|
|
|
<View style={tw("flex")}> |
|
|
|
<TouchableOpacity |
|
|
|
<TouchableOpacity |
|
|
|
style={{ |
|
|
|
style={{ |
|
|
|
marginTop: 30, |
|
|
|
marginTop: 30, |
|
|
|
}} |
|
|
|
}} |
|
|
|
|
|
|
|
onPress={() => submitCellphone()} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
<Text |
|
|
|
|
|
|
|
style={{ |
|
|
|
|
|
|
|
textAlign: "center", |
|
|
|
|
|
|
|
fontFamily: "light", |
|
|
|
|
|
|
|
fontSize: fontSize.base, |
|
|
|
|
|
|
|
color: Colors.theme1[props.theme].greenBA, |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
{"ارسال مجدد کد"} |
|
|
|
|
|
|
|
</Text> |
|
|
|
|
|
|
|
</TouchableOpacity> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<TouchableOpacity |
|
|
|
|
|
|
|
style={{ |
|
|
|
|
|
|
|
marginTop: 10, |
|
|
|
|
|
|
|
}} |
|
|
|
onPress={() => goBack()} |
|
|
|
onPress={() => goBack()} |
|
|
|
> |
|
|
|
> |
|
|
|
<Text |
|
|
|
<Text |
|
|
@ -319,6 +380,7 @@ function Otp(props) { |
|
|
|
{"بازگشت به مرحله قبل و اصلاح شماره"} |
|
|
|
{"بازگشت به مرحله قبل و اصلاح شماره"} |
|
|
|
</Text> |
|
|
|
</Text> |
|
|
|
</TouchableOpacity> |
|
|
|
</TouchableOpacity> |
|
|
|
|
|
|
|
</View> |
|
|
|
)} |
|
|
|
)} |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
</View> |
|
|
@ -328,11 +390,12 @@ function Otp(props) { |
|
|
|
const mapStateToProps = (state) => ({ |
|
|
|
const mapStateToProps = (state) => ({ |
|
|
|
isLogin: state.user.status, |
|
|
|
isLogin: state.user.status, |
|
|
|
mobile: state.publicApi.mobile, |
|
|
|
mobile: state.publicApi.mobile, |
|
|
|
theme: state.publicApi.theme |
|
|
|
theme: state.publicApi.theme, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = { |
|
|
|
const mapDispatchToProps = { |
|
|
|
sendOtp: user.otp_login, |
|
|
|
sendOtp: user.otp_login, |
|
|
|
|
|
|
|
sendCellphone: user.otp, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Otp); |
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Otp); |
|
|
|