|
@@ -8,17 +8,16 @@ import { authenticationService } from '../../../../service/authService';
|
|
|
import PhoneInput from '../../../global/phone_input';
|
|
import PhoneInput from '../../../global/phone_input';
|
|
|
import * as SecureStore from 'expo-secure-store';
|
|
import * as SecureStore from 'expo-secure-store';
|
|
|
import { usePushNotifications } from '../../../../app/hooks/usePushNotifications';
|
|
import { usePushNotifications } from '../../../../app/hooks/usePushNotifications';
|
|
|
|
|
+import { useTranslation } from '../../../../util/hooks/useTranslation';
|
|
|
|
|
|
|
|
const BindingPhoneNumberPageStepTwo = ({ bindingFormData, setBindingFormData, setScreen }: any) => {
|
|
const BindingPhoneNumberPageStepTwo = ({ bindingFormData, setBindingFormData, setScreen }: any) => {
|
|
|
- const [authError, setAuthError] = useState('');
|
|
|
|
|
|
|
+ const { t } = useTranslation(); // 使用翻译钩子
|
|
|
const [error, setError] = useState('');
|
|
const [error, setError] = useState('');
|
|
|
- const [canSendOtp, setCanSendOtp] = useState(true);
|
|
|
|
|
const [lockEmailInput, setLockEmailInput] = useState(false);
|
|
const [lockEmailInput, setLockEmailInput] = useState(false);
|
|
|
- const [data, setData] = useState('');
|
|
|
|
|
- const [isLoading, setIsLoading] = useState(false);
|
|
|
|
|
const [isLoading2, setIsLoading2] = useState(false);
|
|
const [isLoading2, setIsLoading2] = useState(false);
|
|
|
const [countdown, setCountdown] = useState(0);
|
|
const [countdown, setCountdown] = useState(0);
|
|
|
const { expoPushToken } = usePushNotifications();
|
|
const { expoPushToken } = usePushNotifications();
|
|
|
|
|
+
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
let timer: NodeJS.Timeout;
|
|
let timer: NodeJS.Timeout;
|
|
|
if (countdown > 0) {
|
|
if (countdown > 0) {
|
|
@@ -32,93 +31,7 @@ const BindingPhoneNumberPageStepTwo = ({ bindingFormData, setBindingFormData, se
|
|
|
if (timer) clearInterval(timer);
|
|
if (timer) clearInterval(timer);
|
|
|
};
|
|
};
|
|
|
}, [countdown]);
|
|
}, [countdown]);
|
|
|
- // const handleVerification = async () => {
|
|
|
|
|
- // setIsLoading(true);
|
|
|
|
|
- // if (!forgetPasswordFormData.otp && !forgetPasswordFormData.email) {
|
|
|
|
|
- // setAuthError('請確保所有資料都已填寫');
|
|
|
|
|
- // } else if (!forgetPasswordFormData.otp) {
|
|
|
|
|
- // setAuthError('請輸入OTP驗證碼');
|
|
|
|
|
- // } else {
|
|
|
|
|
- // setAuthError('');
|
|
|
|
|
- // 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 = (
|
|
|
|
|
- // field,
|
|
|
|
|
- // value
|
|
|
|
|
- // ) => {
|
|
|
|
|
- // setForgetPasswordFormData((prevFormData) => ({
|
|
|
|
|
- // ...prevFormData,
|
|
|
|
|
- // [field]: value
|
|
|
|
|
- // }));
|
|
|
|
|
- // };
|
|
|
|
|
-
|
|
|
|
|
- // const handleSubmitOtp = () => {
|
|
|
|
|
- // if (forgetPasswordFormData.email) {
|
|
|
|
|
- // if (canSendOtp) {
|
|
|
|
|
- // const lowerCaseEmail =
|
|
|
|
|
- // forgetPasswordFormData.email.toLowerCase();
|
|
|
|
|
- // setCanSendOtp(false);
|
|
|
|
|
- // setLockEmailInput(true);
|
|
|
|
|
- // authenticationService.sendForgetPasswordOtp(lowerCaseEmail);
|
|
|
|
|
- // //can only request otp every 60 seconds
|
|
|
|
|
- // setTimeout(() => {
|
|
|
|
|
- // setCanSendOtp(true);
|
|
|
|
|
- // setLockEmailInput(false);
|
|
|
|
|
- // }, 60000);
|
|
|
|
|
- // setAuthError('');
|
|
|
|
|
- // } else {
|
|
|
|
|
- // setAuthError('請等待一分鐘後再重新發送。');
|
|
|
|
|
- // }
|
|
|
|
|
- // } else {
|
|
|
|
|
- // setAuthError('請確保所有資料都已填寫。');
|
|
|
|
|
- // }
|
|
|
|
|
- // };
|
|
|
|
|
-
|
|
|
|
|
- // const handleFinishResetPassword = async () => {
|
|
|
|
|
- // if (
|
|
|
|
|
- // forgetPasswordFormData.newPassword !==
|
|
|
|
|
- // forgetPasswordFormData.confirmedNewPassword
|
|
|
|
|
- // ) {
|
|
|
|
|
- // setError('請確保新密碼和確認密碼相同');
|
|
|
|
|
- // } else {
|
|
|
|
|
- // setError('');
|
|
|
|
|
- // setIsLoading2(true);
|
|
|
|
|
- // try {
|
|
|
|
|
- // const success = await authenticationService.changePassword(
|
|
|
|
|
- // forgetPasswordFormData.confirmedNewPassword,
|
|
|
|
|
- // data
|
|
|
|
|
- // );
|
|
|
|
|
- // if (success) {
|
|
|
|
|
- // setScreen(1);
|
|
|
|
|
- // } else {
|
|
|
|
|
- // setError('密碼重置失敗,請稍後再試');
|
|
|
|
|
- // }
|
|
|
|
|
- // } catch (error) {
|
|
|
|
|
- // console.error('Error changing password:', error);
|
|
|
|
|
- // setError('發生錯誤,請稍後再試');
|
|
|
|
|
- // } finally {
|
|
|
|
|
- // setIsLoading2(false);
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- // };
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
const handleConfirmBindingPhone = async () => {
|
|
const handleConfirmBindingPhone = async () => {
|
|
|
setIsLoading2(true);
|
|
setIsLoading2(true);
|
|
|
try {
|
|
try {
|
|
@@ -132,23 +45,24 @@ const BindingPhoneNumberPageStepTwo = ({ bindingFormData, setBindingFormData, se
|
|
|
if (result.status == 200) {
|
|
if (result.status == 200) {
|
|
|
setScreen(2);
|
|
setScreen(2);
|
|
|
} else {
|
|
} else {
|
|
|
- setError('綁定手機號碼失敗,請檢查您輸入的OTP並再試一次');
|
|
|
|
|
|
|
+ setError(t('binding.two.phone_binding_failed'));
|
|
|
}
|
|
}
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
- Alert.alert('綁定手機號碼失敗,請檢查您輸入的OTP並再試一次');
|
|
|
|
|
|
|
+ Alert.alert(t('binding.two.phone_binding_failed'));
|
|
|
} finally {
|
|
} finally {
|
|
|
setIsLoading2(false);
|
|
setIsLoading2(false);
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
+
|
|
|
const handleRequestOtp = async () => {
|
|
const handleRequestOtp = async () => {
|
|
|
try {
|
|
try {
|
|
|
//this check if phone same,
|
|
//this check if phone same,
|
|
|
const checkPhoneSame = await authenticationService.checkPhoneSame(bindingFormData.phoneNumber);
|
|
const checkPhoneSame = await authenticationService.checkPhoneSame(bindingFormData.phoneNumber);
|
|
|
if (checkPhoneSame?.status == 422) {
|
|
if (checkPhoneSame?.status == 422) {
|
|
|
//this means phone not same
|
|
//this means phone not same
|
|
|
- Alert.alert('確認您的手機號碼', '您以後將使用現在輸入的號碼進行登入。請按下確認表示您已知悉。', [
|
|
|
|
|
|
|
+ Alert.alert(t('binding.two.confirm_phone_number'), t('binding.two.phone_usage_notice'), [
|
|
|
{
|
|
{
|
|
|
- text: '確認並發出驗證碼',
|
|
|
|
|
|
|
+ text: t('binding.two.confirm_and_send_otp'),
|
|
|
onPress: async () => {
|
|
onPress: async () => {
|
|
|
try {
|
|
try {
|
|
|
const token = await SecureStore.getItemAsync('accessToken');
|
|
const token = await SecureStore.getItemAsync('accessToken');
|
|
@@ -169,12 +83,12 @@ const BindingPhoneNumberPageStepTwo = ({ bindingFormData, setBindingFormData, se
|
|
|
setLockEmailInput(true);
|
|
setLockEmailInput(true);
|
|
|
setCountdown(60);
|
|
setCountdown(60);
|
|
|
} else {
|
|
} else {
|
|
|
- setError('發送OTP失敗,請聯絡工作人員');
|
|
|
|
|
|
|
+ setError(t('binding.two.send_otp_failed'));
|
|
|
}
|
|
}
|
|
|
} catch (error) {}
|
|
} catch (error) {}
|
|
|
} else {
|
|
} else {
|
|
|
//this means change phone failed
|
|
//this means change phone failed
|
|
|
- Alert.alert('修改手機號碼失敗,請稍後再試');
|
|
|
|
|
|
|
+ Alert.alert(t('binding.two.change_phone_failed'));
|
|
|
}
|
|
}
|
|
|
} catch (error) {}
|
|
} catch (error) {}
|
|
|
}
|
|
}
|
|
@@ -187,7 +101,7 @@ const BindingPhoneNumberPageStepTwo = ({ bindingFormData, setBindingFormData, se
|
|
|
setLockEmailInput(true);
|
|
setLockEmailInput(true);
|
|
|
setCountdown(60); // Start 60 second countdown
|
|
setCountdown(60); // Start 60 second countdown
|
|
|
} else {
|
|
} else {
|
|
|
- setError('發送OTP失敗,請稍後再試');
|
|
|
|
|
|
|
+ setError(t('binding.two.send_otp_failed'));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} catch (error) {}
|
|
} catch (error) {}
|
|
@@ -197,7 +111,7 @@ const BindingPhoneNumberPageStepTwo = ({ bindingFormData, setBindingFormData, se
|
|
|
<>
|
|
<>
|
|
|
<View style={styles.container}>
|
|
<View style={styles.container}>
|
|
|
<View style={styles.bottomContainer}>
|
|
<View style={styles.bottomContainer}>
|
|
|
- <Text style={styles.text}>請輸入手機號碼,此手機號碼將用作登入用途</Text>
|
|
|
|
|
|
|
+ <Text style={styles.text}>{t('binding.two.enter_phone_for_login')}</Text>
|
|
|
<PhoneInput
|
|
<PhoneInput
|
|
|
value={bindingFormData?.phoneNumber || ''}
|
|
value={bindingFormData?.phoneNumber || ''}
|
|
|
onChangeText={(phoneNumber) => {
|
|
onChangeText={(phoneNumber) => {
|
|
@@ -206,21 +120,10 @@ const BindingPhoneNumberPageStepTwo = ({ bindingFormData, setBindingFormData, se
|
|
|
phoneNumber: phoneNumber
|
|
phoneNumber: phoneNumber
|
|
|
});
|
|
});
|
|
|
}}
|
|
}}
|
|
|
- placeholder="請輸入手機號碼"
|
|
|
|
|
|
|
+ placeholder={t('binding.two.enter_phone_number')}
|
|
|
editable={!lockEmailInput}
|
|
editable={!lockEmailInput}
|
|
|
extendedStyle={{ opacity: !lockEmailInput ? 1 : 0.5 }}
|
|
extendedStyle={{ opacity: !lockEmailInput ? 1 : 0.5 }}
|
|
|
/>
|
|
/>
|
|
|
- {/* <NormalInput
|
|
|
|
|
- placeholder="請輸入手機號碼"
|
|
|
|
|
- onChangeText={(phoneNumber) =>
|
|
|
|
|
- setBindingFormData({
|
|
|
|
|
- ...bindingFormData,
|
|
|
|
|
- phoneNumber: phoneNumber
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- // editable={!lockEmailInput}
|
|
|
|
|
- // extendedStyle={{ opacity: !lockEmailInput ? 1 : 0.5 }}
|
|
|
|
|
- /> */}
|
|
|
|
|
<View
|
|
<View
|
|
|
style={{
|
|
style={{
|
|
|
display: 'flex',
|
|
display: 'flex',
|
|
@@ -230,18 +133,16 @@ const BindingPhoneNumberPageStepTwo = ({ bindingFormData, setBindingFormData, se
|
|
|
}}
|
|
}}
|
|
|
>
|
|
>
|
|
|
<NumberInput
|
|
<NumberInput
|
|
|
- placeholder="OTP驗證碼"
|
|
|
|
|
|
|
+ placeholder={t('binding.two.otp_verification_code')}
|
|
|
onChangeText={(t) => setBindingFormData({ ...bindingFormData, otp: t })}
|
|
onChangeText={(t) => setBindingFormData({ ...bindingFormData, otp: t })}
|
|
|
- // editable={!forgetPasswordFormData.otpAuthCompleted}
|
|
|
|
|
extendedStyle={{
|
|
extendedStyle={{
|
|
|
flex: 1
|
|
flex: 1
|
|
|
- // opacity: !forgetPasswordFormData.otpAuthCompleted ? 1 : 0.5
|
|
|
|
|
}}
|
|
}}
|
|
|
/>
|
|
/>
|
|
|
<NormalButton
|
|
<NormalButton
|
|
|
title={
|
|
title={
|
|
|
<Text style={{ color: '#fff' }}>
|
|
<Text style={{ color: '#fff' }}>
|
|
|
- {lockEmailInput ? `已發送 (${countdown}s)` : '發送'}
|
|
|
|
|
|
|
+ {lockEmailInput ? `${t('binding.two.sent')} (${countdown}s)` : t('binding.two.send')}
|
|
|
</Text>
|
|
</Text>
|
|
|
}
|
|
}
|
|
|
onPress={handleRequestOtp}
|
|
onPress={handleRequestOtp}
|
|
@@ -250,75 +151,9 @@ const BindingPhoneNumberPageStepTwo = ({ bindingFormData, setBindingFormData, se
|
|
|
/>
|
|
/>
|
|
|
</View>
|
|
</View>
|
|
|
<NormalButton
|
|
<NormalButton
|
|
|
- title={<Text style={{ color: '#fff' }}>{isLoading2 ? '處理中...' : '確認'}</Text>}
|
|
|
|
|
|
|
+ title={<Text style={{ color: '#fff' }}>{isLoading2 ? t('binding.two.processing') : t('binding.two.confirm')}</Text>}
|
|
|
onPress={handleConfirmBindingPhone}
|
|
onPress={handleConfirmBindingPhone}
|
|
|
- // extendedStyle={
|
|
|
|
|
- // forgetPasswordFormData.otpAuthCompleted == true ? { backgroundColor: '#70787C' } : {}
|
|
|
|
|
- // }
|
|
|
|
|
/>
|
|
/>
|
|
|
- {/* {lockEmailInput && (
|
|
|
|
|
- <Pressable
|
|
|
|
|
- // disabled={forgetPasswordFormData.otpAuthCompleted}
|
|
|
|
|
- onPress={() => setLockEmailInput(false)}
|
|
|
|
|
- >
|
|
|
|
|
- <Text
|
|
|
|
|
- style={[
|
|
|
|
|
- styles.footer
|
|
|
|
|
- // forgetPasswordFormData.otpAuthCompleted && {
|
|
|
|
|
- // opacity: 0.5
|
|
|
|
|
- // }
|
|
|
|
|
- ]}
|
|
|
|
|
- >
|
|
|
|
|
- 重新整理
|
|
|
|
|
- </Text>
|
|
|
|
|
- </Pressable>
|
|
|
|
|
- )} */}
|
|
|
|
|
-
|
|
|
|
|
- {/* {authError && <Text style={styles.errorMessage}>{authError}</Text>}
|
|
|
|
|
- {lockEmailInput && (
|
|
|
|
|
- <Pressable
|
|
|
|
|
- disabled={forgetPasswordFormData.otpAuthCompleted}
|
|
|
|
|
- onPress={() => setLockEmailInput(false)}
|
|
|
|
|
- >
|
|
|
|
|
- <Text
|
|
|
|
|
- style={[
|
|
|
|
|
- styles.footer,
|
|
|
|
|
- forgetPasswordFormData.otpAuthCompleted && {
|
|
|
|
|
- opacity: 0.5
|
|
|
|
|
- }
|
|
|
|
|
- ]}
|
|
|
|
|
- >
|
|
|
|
|
- 修改電子郵件
|
|
|
|
|
- </Text>
|
|
|
|
|
- </Pressable>
|
|
|
|
|
- )}
|
|
|
|
|
-
|
|
|
|
|
- {forgetPasswordFormData.otpAuthCompleted && (
|
|
|
|
|
- <View
|
|
|
|
|
- style={[
|
|
|
|
|
- styles.hiddenPasswordFields,
|
|
|
|
|
- forgetPasswordFormData.otpAuthCompleted ? styles.opacityFull : styles.opacityZero
|
|
|
|
|
- ]}
|
|
|
|
|
- >
|
|
|
|
|
- <NormalInput
|
|
|
|
|
- placeholder="新密碼"
|
|
|
|
|
- onChangeText={(t) => handleFormDataChange('newPassword', t)}
|
|
|
|
|
- secureTextEntry={true}
|
|
|
|
|
- textContentType={'oneTimeCode'}
|
|
|
|
|
- />
|
|
|
|
|
- <NormalInput
|
|
|
|
|
- placeholder="確認密碼"
|
|
|
|
|
- onChangeText={(t) => handleFormDataChange('confirmedNewPassword', t)}
|
|
|
|
|
- secureTextEntry={true}
|
|
|
|
|
- textContentType={'oneTimeCode'}
|
|
|
|
|
- />
|
|
|
|
|
- <NormalButton
|
|
|
|
|
- title={<Text style={{ color: '#fff' }}>{isLoading ? '重置中...' : '重置'}</Text>}
|
|
|
|
|
- onPress={handleFinishResetPassword}
|
|
|
|
|
- extendedStyle={{}}
|
|
|
|
|
- />
|
|
|
|
|
- </View>
|
|
|
|
|
- )} */}
|
|
|
|
|
|
|
|
|
|
{error && <Text style={styles.errorMessage}>{error}</Text>}
|
|
{error && <Text style={styles.errorMessage}>{error}</Text>}
|
|
|
</View>
|
|
</View>
|
|
@@ -371,4 +206,4 @@ const styles = StyleSheet.create({
|
|
|
footer: { color: '#02677D', fontSize: 16, paddingVertical: 10 }
|
|
footer: { color: '#02677D', fontSize: 16, paddingVertical: 10 }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
-export default BindingPhoneNumberPageStepTwo;
|
|
|
|
|
|
|
+export default BindingPhoneNumberPageStepTwo;
|