bindingPhoneNumberPage.tsx 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. import { View, Text, StyleSheet, Pressable, Alert } from 'react-native';
  2. import { useState } from 'react';
  3. import { Ionicons } from '@expo/vector-icons';
  4. import NumberInput from '../../../global/number_input';
  5. import NormalButton from '../../../global/normal_button';
  6. import NormalInput from '../../../global/normal_input';
  7. import { authenticationService } from '../../../../service/authService';
  8. const BindingPhoneNumberPage = ({ bindingFormData, setBindingFormData, setScreen }: any) => {
  9. const [authError, setAuthError] = useState('');
  10. const [error, setError] = useState('');
  11. const [canSendOtp, setCanSendOtp] = useState(true);
  12. const [lockEmailInput, setLockEmailInput] = useState(false);
  13. const [data, setData] = useState('');
  14. const [isLoading, setIsLoading] = useState(false);
  15. const [isLoading2, setIsLoading2] = useState(false);
  16. const [showPassword, setShowPassword] = useState(false);
  17. // const handleVerification = async () => {
  18. // setIsLoading(true);
  19. // if (!forgetPasswordFormData.otp && !forgetPasswordFormData.email) {
  20. // setAuthError('請確保所有資料都已填寫');
  21. // } else if (!forgetPasswordFormData.otp) {
  22. // setAuthError('請輸入OTP驗證碼');
  23. // } else {
  24. // setAuthError('');
  25. // try {
  26. // const result = await authenticationService.verifyingOtpForgetPassword(
  27. // forgetPasswordFormData.email.toLowerCase(),
  28. // forgetPasswordFormData.otp,
  29. // setForgetPasswordFormData,
  30. // setData
  31. // );
  32. // if (result === false) {
  33. // setAuthError('驗證OTP時發生錯誤,請稍後再試');
  34. // }
  35. // } catch (error) {
  36. // console.error('Error verifying OTP:', error);
  37. // setAuthError('驗證OTP時發生錯誤,請稍後再試');
  38. // }
  39. // }
  40. // setIsLoading(false);
  41. // };
  42. // const handleFormDataChange: HandleForgetPasswordFormDataChange = (field, value) => {
  43. // setForgetPasswordFormData((prevFormData) => ({
  44. // ...prevFormData,
  45. // [field]: value
  46. // }));
  47. // };
  48. // const handleSubmitOtp = () => {
  49. // if (forgetPasswordFormData.email) {
  50. // if (canSendOtp) {
  51. // const lowerCaseEmail = forgetPasswordFormData.email.toLowerCase();
  52. // setCanSendOtp(false);
  53. // setLockEmailInput(true);
  54. // authenticationService.sendForgetPasswordOtp(lowerCaseEmail);
  55. // //can only request otp every 60 seconds
  56. // setTimeout(() => {
  57. // setCanSendOtp(true);
  58. // setLockEmailInput(false);
  59. // }, 60000);
  60. // setAuthError('');
  61. // } else {
  62. // setAuthError('請等待一分鐘後再重新發送。');
  63. // }
  64. // } else {
  65. // setAuthError('請確保所有資料都已填寫。');
  66. // }
  67. // };
  68. // const handleFinishResetPassword = async () => {
  69. // if (forgetPasswordFormData.newPassword !== forgetPasswordFormData.confirmedNewPassword) {
  70. // setError('請確保新密碼和確認密碼相同');
  71. // } else {
  72. // setError('');
  73. // setIsLoading2(true);
  74. // try {
  75. // const success = await authenticationService.changePassword(
  76. // forgetPasswordFormData.confirmedNewPassword,
  77. // data
  78. // );
  79. // if (success) {
  80. // setScreen(1);
  81. // } else {
  82. // setError('密碼重置失敗,請稍後再試');
  83. // }
  84. // } catch (error) {
  85. // console.error('Error changing password:', error);
  86. // setError('發生錯誤,請稍後再試');
  87. // } finally {
  88. // setIsLoading2(false);
  89. // }
  90. // }
  91. // };
  92. const handleVerification = async () => {
  93. setIsLoading(true);
  94. try {
  95. const isBinding = true;
  96. const response = await authenticationService.emailLogin(
  97. bindingFormData.email,
  98. bindingFormData.password,
  99. isBinding
  100. );
  101. if (response == true) {
  102. setScreen(1);
  103. } else {
  104. Alert.alert('登入失敗,請檢查您輸入的帳號密碼並再試一次');
  105. }
  106. } catch (error) {
  107. } finally {
  108. setIsLoading(false);
  109. }
  110. };
  111. return (
  112. <>
  113. <View style={styles.container}>
  114. <View style={styles.bottomContainer}>
  115. <Text style={styles.text}>請輸入現有電子郵件</Text>
  116. <View className="pb-2">
  117. <NormalInput
  118. placeholder="請填寫您的電子郵件"
  119. onChangeText={(email) =>
  120. setBindingFormData({
  121. ...bindingFormData,
  122. email: email
  123. })
  124. }
  125. textContentType="username"
  126. autoComplete="username"
  127. keyboardType="email-address"
  128. autoCapitalize="none"
  129. />
  130. </View>
  131. <View className="pb-2">
  132. <NormalInput
  133. placeholder="請填寫您的密碼"
  134. onChangeText={(password) =>
  135. setBindingFormData({
  136. ...bindingFormData,
  137. password: password
  138. })
  139. }
  140. secureTextEntry={!showPassword}
  141. extendedStyle={{ borderRadius: 12, padding: 20, paddingRight: 50 }}
  142. textContentType="password"
  143. autoComplete="password"
  144. />
  145. <Pressable
  146. className="absolute right-4 top-0 bottom-0 justify-center"
  147. onPress={() => setShowPassword(!showPassword)}
  148. >
  149. <Ionicons
  150. name={showPassword ? 'eye-outline' : 'eye-off-outline'}
  151. size={24}
  152. color="#02677D"
  153. />
  154. </Pressable>
  155. </View>
  156. <NormalButton
  157. title={<Text style={{ color: '#fff' }}>{isLoading ? '處理中...' : '下一步'}</Text>}
  158. onPress={handleVerification}
  159. // extendedStyle={
  160. // forgetPasswordFormData.otpAuthCompleted == true ? { backgroundColor: '#70787C' } : {}
  161. // }
  162. />
  163. {error && <Text style={styles.errorMessage}>{error}</Text>}
  164. </View>
  165. </View>
  166. </>
  167. );
  168. };
  169. const styles = StyleSheet.create({
  170. container: {
  171. flex: 1,
  172. marginHorizontal: 20
  173. },
  174. titleText: {
  175. fontSize: 24,
  176. fontWeight: '300'
  177. },
  178. bottomContainer: {
  179. flex: 3,
  180. paddingBottom: 100
  181. },
  182. breakline: {
  183. width: 24,
  184. height: 1,
  185. backgroundColor: '#000000',
  186. marginVertical: 17
  187. },
  188. text: {
  189. fontSize: 18,
  190. paddingBottom: 10
  191. },
  192. hiddenPasswordFields: {
  193. gap: 10,
  194. paddingTop: 10
  195. },
  196. opacityZero: {
  197. opacity: 0
  198. },
  199. opacityFull: {
  200. opacity: 1
  201. },
  202. errorMessage: {
  203. fontSize: 14,
  204. color: '#ff0033',
  205. fontWeight: '400',
  206. marginLeft: 10,
  207. marginTop: 10
  208. },
  209. footer: { color: '#02677D', fontSize: 16, paddingVertical: 10 }
  210. });
  211. export default BindingPhoneNumberPage;