import { View, Text, StyleSheet, TextInput, Pressable } from "react-native"; import { useEffect, useState } from "react"; import { SignUpFormData, HandleSignUpFormDataChange } from "../../../../types/signup"; import PhoneInput from "../../../global/phone_input"; import NumberInput from "../../../global/number_input"; import NormalButton from "../../../global/normal_button"; type VerificationProps = { setScreen: React.Dispatch>; formData: SignUpFormData; handleFormDataChange: HandleSignUpFormDataChange; }; const Verification: React.FC = ({ 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("請確保所有資料都已填寫。"); } 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 ? ( 重新發送 ) : ( 發送 ); return ( <> 請驗證您的電話號碼 驗證} onPress={() => { handleVerification(); }} extendedStyle={{}} /> {error && {error}} 修改電話號碼 ); }; const styles = StyleSheet.create({ container: { flex: 1, marginHorizontal: 20, }, text: { fontSize: 20, paddingBottom: 10, }, errorMessage: { fontSize: 14, color: "#ff0033", fontWeight: "400", marginLeft: 10, marginTop: 10, }, footer: { color: "#02677D", fontSize: 16, paddingVertical: 10 }, }); export default Verification;