|
|
|
@ -8,7 +8,7 @@ import { |
|
|
|
|
TouchableOpacity, |
|
|
|
|
ActivityIndicator, |
|
|
|
|
Appearance, |
|
|
|
|
Platform |
|
|
|
|
Platform, |
|
|
|
|
} from "react-native"; |
|
|
|
|
import tw from "tailwind-rn"; |
|
|
|
|
import { connect } from "react-redux"; |
|
|
|
@ -20,8 +20,7 @@ import { user } from "../../redux/actions"; |
|
|
|
|
import fontSize from "../../constants/fontSize"; |
|
|
|
|
import Colors from "../../constants/Colors"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const ios = Platform.OS === 'ios'; |
|
|
|
|
const ios = Platform.OS === "ios"; |
|
|
|
|
const { width } = Dimensions.get("window"); |
|
|
|
|
let ref1; |
|
|
|
|
let ref2; |
|
|
|
@ -38,40 +37,45 @@ function Otp(props) { |
|
|
|
|
const [fourthCode, setFourthCode] = useState(""); |
|
|
|
|
const [time, setTime] = useState(60); |
|
|
|
|
const [loading, setLoading] = useState(false); |
|
|
|
|
const [timeEnd, setTimeEnd] = useState(false); |
|
|
|
|
|
|
|
|
|
const onChangeCode = (value, key) => { |
|
|
|
|
switch (key) { |
|
|
|
|
case "1": |
|
|
|
|
setFirstCode(value); |
|
|
|
|
if (value !== "") { |
|
|
|
|
ref2.focus(); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case "2": |
|
|
|
|
setSecondCode(value); |
|
|
|
|
if (value !== "") { |
|
|
|
|
ref3.focus(); |
|
|
|
|
} else { |
|
|
|
|
ref1.focus(); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case "3": |
|
|
|
|
setThirdCode(value); |
|
|
|
|
if (value !== "") { |
|
|
|
|
ref4.focus(); |
|
|
|
|
} else { |
|
|
|
|
ref2.focus(); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case "4": |
|
|
|
|
setFourthCode(value); |
|
|
|
|
if (value !== "") { |
|
|
|
|
// ref3.focus();
|
|
|
|
|
} else { |
|
|
|
|
ref3.focus(); |
|
|
|
|
} |
|
|
|
|
if (onInput.numberOnly(value) || value === "") { |
|
|
|
|
switch (key) { |
|
|
|
|
case "1": |
|
|
|
|
setFirstCode(value); |
|
|
|
|
if (value !== "") { |
|
|
|
|
ref2.focus(); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case "2": |
|
|
|
|
setSecondCode(value); |
|
|
|
|
if (value !== "") { |
|
|
|
|
ref3.focus(); |
|
|
|
|
} else { |
|
|
|
|
ref1.focus(); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case "3": |
|
|
|
|
setThirdCode(value); |
|
|
|
|
if (value !== "") { |
|
|
|
|
ref4.focus(); |
|
|
|
|
} else { |
|
|
|
|
ref2.focus(); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case "4": |
|
|
|
|
setFourthCode(value); |
|
|
|
|
if (value !== "") { |
|
|
|
|
// ref3.focus();
|
|
|
|
|
} else { |
|
|
|
|
ref3.focus(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -105,6 +109,7 @@ function Otp(props) { |
|
|
|
|
}, 1000); |
|
|
|
|
let timeout = setTimeout(() => { |
|
|
|
|
clearInterval(interval); |
|
|
|
|
setTimeEnd(true); |
|
|
|
|
}, 60000); |
|
|
|
|
return () => { |
|
|
|
|
clearInterval(interval); |
|
|
|
@ -132,7 +137,11 @@ function Otp(props) { |
|
|
|
|
/> |
|
|
|
|
<Text |
|
|
|
|
style={[ |
|
|
|
|
tw(`w-full mt-2.5 ${ios ? 'text-right' : ""} ${props.mobile ? "" : "w-3/4"}`), |
|
|
|
|
tw( |
|
|
|
|
`w-full mt-2.5 ${ios ? "text-right" : ""} ${ |
|
|
|
|
props.mobile ? "" : "w-3/4" |
|
|
|
|
}` |
|
|
|
|
), |
|
|
|
|
{ |
|
|
|
|
fontSize: props.mobile ? fontSize.sm : fontSize.base, |
|
|
|
|
fontFamily: "regular", |
|
|
|
@ -152,12 +161,12 @@ function Otp(props) { |
|
|
|
|
fontSize: fontSize.xl3, |
|
|
|
|
fontFamily: "bold", |
|
|
|
|
color: Colors.theme1[colorScheme].green79, |
|
|
|
|
width : ios ? fontSize.xl3 + 40 : "" |
|
|
|
|
width: fontSize.xl3 + 40, |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
underlineColorAndroid={"transparent"} |
|
|
|
|
value={firstCode} |
|
|
|
|
maxLength={1} |
|
|
|
|
maxLength={2} |
|
|
|
|
ref={(ref) => (ref1 = ref)} |
|
|
|
|
onChangeText={(text) => onChangeCode(text, "1")} |
|
|
|
|
regex={onInput.numberOnly} |
|
|
|
@ -170,12 +179,12 @@ function Otp(props) { |
|
|
|
|
fontSize: fontSize.xl3, |
|
|
|
|
fontFamily: "bold", |
|
|
|
|
color: Colors.theme1[colorScheme].green79, |
|
|
|
|
width : ios ? fontSize.xl3 + 40 : "" |
|
|
|
|
width: fontSize.xl3 + 40, |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
underlineColorAndroid={"transparent"} |
|
|
|
|
value={secondCode} |
|
|
|
|
maxLength={1} |
|
|
|
|
maxLength={2} |
|
|
|
|
ref={(ref) => (ref2 = ref)} |
|
|
|
|
onChangeText={(text) => onChangeCode(text, "2")} |
|
|
|
|
regex={onInput.numberOnly} |
|
|
|
@ -188,12 +197,12 @@ function Otp(props) { |
|
|
|
|
fontSize: fontSize.xl3, |
|
|
|
|
fontFamily: "bold", |
|
|
|
|
color: Colors.theme1[colorScheme].green79, |
|
|
|
|
width : ios ? fontSize.xl3 + 40 : "" |
|
|
|
|
width: fontSize.xl3 + 40, |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
underlineColorAndroid={"transparent"} |
|
|
|
|
value={thirdCode} |
|
|
|
|
maxLength={1} |
|
|
|
|
maxLength={2} |
|
|
|
|
ref={(ref) => (ref3 = ref)} |
|
|
|
|
onChangeText={(text) => onChangeCode(text, "3")} |
|
|
|
|
regex={onInput.numberOnly} |
|
|
|
@ -206,12 +215,12 @@ function Otp(props) { |
|
|
|
|
fontSize: fontSize.xl3, |
|
|
|
|
fontFamily: "bold", |
|
|
|
|
color: Colors.theme1[colorScheme].green79, |
|
|
|
|
width : ios ? fontSize.xl3 + 40 : "" |
|
|
|
|
width: fontSize.xl3 + 40, |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
underlineColorAndroid={"transparent"} |
|
|
|
|
value={fourthCode} |
|
|
|
|
maxLength={1} |
|
|
|
|
maxLength={2} |
|
|
|
|
ref={(ref) => (ref4 = ref)} |
|
|
|
|
onChangeText={(text) => onChangeCode(text, "4")} |
|
|
|
|
regex={onInput.numberOnly} |
|
|
|
@ -221,7 +230,11 @@ function Otp(props) { |
|
|
|
|
<TouchableOpacity |
|
|
|
|
disabled={loading} |
|
|
|
|
style={[ |
|
|
|
|
tw(`w-full rounded-md py-2 mt-6 items-center justify-center ${props.mobile ? "" : "w-3/4"}`), |
|
|
|
|
tw( |
|
|
|
|
`w-full rounded-md py-2 mt-6 items-center justify-center ${ |
|
|
|
|
props.mobile ? "" : "w-3/4" |
|
|
|
|
}` |
|
|
|
|
), |
|
|
|
|
{ |
|
|
|
|
backgroundColor: Colors.theme1[colorScheme].greenCF, |
|
|
|
|
}, |
|
|
|
@ -243,31 +256,38 @@ function Otp(props) { |
|
|
|
|
)} |
|
|
|
|
</TouchableOpacity> |
|
|
|
|
<View> |
|
|
|
|
<Text |
|
|
|
|
style={[ |
|
|
|
|
tw("mt-7 text-center"), |
|
|
|
|
{ fontFamily: "light", fontSize: fontSize.base, color : Colors.theme1[colorScheme].gray20 }, |
|
|
|
|
]} |
|
|
|
|
> |
|
|
|
|
{"زمان باقی مانده تا انقضای کد: " + time} |
|
|
|
|
</Text> |
|
|
|
|
<TouchableOpacity |
|
|
|
|
style={{ |
|
|
|
|
marginTop: 20, |
|
|
|
|
}} |
|
|
|
|
onPress={() => props.navigation.navigate("Login")} |
|
|
|
|
> |
|
|
|
|
{!timeEnd ? ( |
|
|
|
|
<Text |
|
|
|
|
style={[ |
|
|
|
|
tw("mt-7 text-center"), |
|
|
|
|
{ |
|
|
|
|
fontFamily: "light", |
|
|
|
|
fontSize: fontSize.base, |
|
|
|
|
color: Colors.theme1[colorScheme].gray20, |
|
|
|
|
}, |
|
|
|
|
]} |
|
|
|
|
> |
|
|
|
|
{"زمان باقی مانده تا ارسال مجدد: " + time} |
|
|
|
|
</Text> |
|
|
|
|
) : ( |
|
|
|
|
<TouchableOpacity |
|
|
|
|
style={{ |
|
|
|
|
textAlign: "center", |
|
|
|
|
fontFamily: "light", |
|
|
|
|
fontSize: fontSize.base, |
|
|
|
|
color: Colors.theme1[colorScheme].greenBA, |
|
|
|
|
marginTop: 20, |
|
|
|
|
}} |
|
|
|
|
onPress={() => props.navigation.navigate("Login")} |
|
|
|
|
> |
|
|
|
|
{"بازگشت به مرحله قبل و اصلاح شماره"} |
|
|
|
|
</Text> |
|
|
|
|
</TouchableOpacity> |
|
|
|
|
<Text |
|
|
|
|
style={{ |
|
|
|
|
textAlign: "center", |
|
|
|
|
fontFamily: "light", |
|
|
|
|
fontSize: fontSize.base, |
|
|
|
|
color: Colors.theme1[colorScheme].greenBA, |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
|
{"بازگشت به مرحله قبل و اصلاح شماره"} |
|
|
|
|
</Text> |
|
|
|
|
</TouchableOpacity> |
|
|
|
|
)} |
|
|
|
|
</View> |
|
|
|
|
</View> |
|
|
|
|
); |
|
|
|
@ -275,7 +295,7 @@ function Otp(props) { |
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => ({ |
|
|
|
|
isLogin: state.user.status, |
|
|
|
|
mobile : state.publicApi.mobile |
|
|
|
|
mobile: state.publicApi.mobile, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = { |
|
|
|
|