|
|
@@ -1,5 +1,5 @@
|
|
|
-import { View, Text, StyleSheet, TextInput } from "react-native";
|
|
|
-import { useState } from "react";
|
|
|
+import { View, Text, StyleSheet, TextInput, Pressable } from "react-native";
|
|
|
+import { useEffect, useState } from "react";
|
|
|
import { FormData, HandleFormDataChange } from "../../../type";
|
|
|
import PhoneInput from "../../../global/phone_input";
|
|
|
import NumberInput from "../../../global/number_input";
|
|
|
@@ -14,20 +14,58 @@ type VerificationProps = {
|
|
|
const Verification: React.FC<VerificationProps> = ({ setScreen, formData, handleFormDataChange }) => {
|
|
|
const [error, setError] = useState("");
|
|
|
const [otp, setOtp] = useState("");
|
|
|
+ const [canSendOtp, setCanSendOtp] = useState(true);
|
|
|
+ const [lockPhoneInput, setLockPhoneInput] = useState(false);
|
|
|
|
|
|
const handleVerification = () => {
|
|
|
if (formData.phone === "" || otp === "") {
|
|
|
- setError("請輸入電話號碼和OTP驗證碼");
|
|
|
+ setError("請確保所有資料都已填寫。");
|
|
|
} else {
|
|
|
setError("");
|
|
|
setScreen((currentScreenNumber) => currentScreenNumber + 1);
|
|
|
}
|
|
|
};
|
|
|
+
|
|
|
+ const handleSubmitOtp = () => {
|
|
|
+ if (formData.phoneVerificationStatus) {
|
|
|
+ if (canSendOtp) {
|
|
|
+ setCanSendOtp(false);
|
|
|
+ setLockPhoneInput(true);
|
|
|
+ console.log(lockPhoneInput);
|
|
|
+ //can only request otp every 60 seconds
|
|
|
+ setTimeout(() => {
|
|
|
+ setCanSendOtp(true);
|
|
|
+ setLockPhoneInput(false);
|
|
|
+ }, 60000);
|
|
|
+ setError("");
|
|
|
+ } else {
|
|
|
+ setError("請等待一分鐘後再重新發送。");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ setError("請確保所有資料都已填寫。");
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleChangePhoneNumber = () => {
|
|
|
+ setLockPhoneInput(false);
|
|
|
+ };
|
|
|
+
|
|
|
+ const otpButtonText = lockPhoneInput ? (
|
|
|
+ <Text style={{ color: "#fff" }}>重新發送</Text>
|
|
|
+ ) : (
|
|
|
+ <Text style={{ color: "#fff" }}>發送</Text>
|
|
|
+ );
|
|
|
+
|
|
|
return (
|
|
|
<>
|
|
|
<View style={styles.container}>
|
|
|
<Text style={styles.text}>請驗證您的電話號碼</Text>
|
|
|
- <PhoneInput placeholder="電話號碼" handleFormDataChange={handleFormDataChange} />
|
|
|
+ <PhoneInput
|
|
|
+ placeholder={formData.phone ? formData.phone : "輸入電話號碼"}
|
|
|
+ handleFormDataChange={handleFormDataChange}
|
|
|
+ editable={!lockPhoneInput}
|
|
|
+ extendedStyle={{ opacity: !lockPhoneInput ? 1 : 0.5 }}
|
|
|
+ />
|
|
|
<View
|
|
|
style={{
|
|
|
display: "flex",
|
|
|
@@ -37,11 +75,7 @@ const Verification: React.FC<VerificationProps> = ({ setScreen, formData, handle
|
|
|
}}
|
|
|
>
|
|
|
<NumberInput placeholder="OTP驗證碼" onChangeText={setOtp} extendedStyle={{ flex: 1 }} />
|
|
|
- <NormalButton
|
|
|
- title={<Text style={{ color: "#fff" }}>發送</Text>}
|
|
|
- onPress={() => console.log("you pressed 發送")}
|
|
|
- extendedStyle={{ flex: 1 / 2 }}
|
|
|
- />
|
|
|
+ <NormalButton title={otpButtonText} onPress={handleSubmitOtp} extendedStyle={{ flex: 1 / 2 }} />
|
|
|
</View>
|
|
|
<NormalButton
|
|
|
title={<Text style={{ color: "#fff" }}>驗證</Text>}
|
|
|
@@ -51,6 +85,9 @@ const Verification: React.FC<VerificationProps> = ({ setScreen, formData, handle
|
|
|
extendedStyle={{}}
|
|
|
/>
|
|
|
{error && <Text style={styles.errorMessage}>{error}</Text>}
|
|
|
+ <Pressable onPress={handleChangePhoneNumber}>
|
|
|
+ <Text style={[styles.footer, { opacity: lockPhoneInput ? 1 : 0 }]}>修改電話號碼</Text>
|
|
|
+ </Pressable>
|
|
|
</View>
|
|
|
</>
|
|
|
);
|
|
|
@@ -72,5 +109,6 @@ const styles = StyleSheet.create({
|
|
|
marginLeft: 10,
|
|
|
marginTop: 10,
|
|
|
},
|
|
|
+ footer: { color: "#02677D", fontSize: 16, paddingVertical: 10 },
|
|
|
});
|
|
|
export default Verification;
|