|
|
@@ -27,22 +27,34 @@ const ForgetPasswordPage: React.FC<ForgetPasswordPageProps> = ({
|
|
|
const [canSendOtp, setCanSendOtp] = useState(true);
|
|
|
const [lockEmailInput, setLockEmailInput] = useState(false);
|
|
|
const [data, setData] = useState('');
|
|
|
+ const [isLoading, setIsLoading] = useState(false);
|
|
|
+ const [isLoading2, setIsLoading2] = useState(false);
|
|
|
|
|
|
- const handleVerification = () => {
|
|
|
+ const handleVerification = async () => {
|
|
|
+ setIsLoading(true);
|
|
|
if (!forgetPasswordFormData.otp && !forgetPasswordFormData.email) {
|
|
|
setAuthError('請確保所有資料都已填寫');
|
|
|
} else if (!forgetPasswordFormData.otp) {
|
|
|
setAuthError('請輸入OTP驗證碼');
|
|
|
} else {
|
|
|
setAuthError('');
|
|
|
-
|
|
|
- authenticationService.verifyingOtpForgetPassword(
|
|
|
- forgetPasswordFormData.email.toLowerCase(),
|
|
|
- forgetPasswordFormData.otp,
|
|
|
- setForgetPasswordFormData,
|
|
|
- setData
|
|
|
- );
|
|
|
+ try {
|
|
|
+ const result =
|
|
|
+ await authenticationService.verifyingOtpForgetPassword(
|
|
|
+ forgetPasswordFormData.email.toLowerCase(),
|
|
|
+ forgetPasswordFormData.otp,
|
|
|
+ setForgetPasswordFormData,
|
|
|
+ setData
|
|
|
+ );
|
|
|
+ if (result === false) {
|
|
|
+ setAuthError('驗證OTP時發生錯誤,請稍後再試');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Error verifying OTP:', error);
|
|
|
+ setAuthError('驗證OTP時發生錯誤,請稍後再試');
|
|
|
+ }
|
|
|
}
|
|
|
+ setIsLoading(false);
|
|
|
};
|
|
|
|
|
|
const handleFormDataChange: HandleForgetPasswordFormDataChange = (
|
|
|
@@ -85,12 +97,12 @@ const ForgetPasswordPage: React.FC<ForgetPasswordPageProps> = ({
|
|
|
setError('請確保新密碼和確認密碼相同');
|
|
|
} else {
|
|
|
setError('');
|
|
|
+ setIsLoading2(true);
|
|
|
try {
|
|
|
- const success =
|
|
|
- await authenticationService.changePassword(
|
|
|
- forgetPasswordFormData.confirmedNewPassword,
|
|
|
- data
|
|
|
- );
|
|
|
+ const success = await authenticationService.changePassword(
|
|
|
+ forgetPasswordFormData.confirmedNewPassword,
|
|
|
+ data
|
|
|
+ );
|
|
|
if (success) {
|
|
|
setScreen(1);
|
|
|
} else {
|
|
|
@@ -99,6 +111,8 @@ const ForgetPasswordPage: React.FC<ForgetPasswordPageProps> = ({
|
|
|
} catch (error) {
|
|
|
console.error('Error changing password:', error);
|
|
|
setError('發生錯誤,請稍後再試');
|
|
|
+ } finally {
|
|
|
+ setIsLoading2(false);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
@@ -143,7 +157,7 @@ const ForgetPasswordPage: React.FC<ForgetPasswordPageProps> = ({
|
|
|
<NormalButton
|
|
|
title={
|
|
|
<Text style={{ color: '#fff' }}>
|
|
|
- {lockEmailInput ? '已發送' : '驗證'}
|
|
|
+ {lockEmailInput ? '已發送' : '發送'}
|
|
|
</Text>
|
|
|
}
|
|
|
onPress={handleSubmitOtp}
|
|
|
@@ -153,7 +167,10 @@ const ForgetPasswordPage: React.FC<ForgetPasswordPageProps> = ({
|
|
|
<NormalButton
|
|
|
title={
|
|
|
<Text style={{ color: '#fff' }}>
|
|
|
- {forgetPasswordFormData.otpAuthCompleted == true
|
|
|
+ {isLoading
|
|
|
+ ? '驗證中...'
|
|
|
+ : forgetPasswordFormData.otpAuthCompleted ==
|
|
|
+ true
|
|
|
? '已驗證'
|
|
|
: '驗證'}
|
|
|
</Text>
|
|
|
@@ -217,7 +234,9 @@ const ForgetPasswordPage: React.FC<ForgetPasswordPageProps> = ({
|
|
|
/>
|
|
|
<NormalButton
|
|
|
title={
|
|
|
- <Text style={{ color: '#fff' }}>重置</Text>
|
|
|
+ <Text style={{ color: '#fff' }}>
|
|
|
+ {isLoading ? '重置中...' : '重置'}
|
|
|
+ </Text>
|
|
|
}
|
|
|
onPress={handleFinishResetPassword}
|
|
|
extendedStyle={{}}
|