bindingPhoneNumberPage.tsx 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. console.log('bindingFormData', bindingFormData);
  97. const response = await authenticationService.emailLogin(
  98. bindingFormData.email,
  99. bindingFormData.password,
  100. isBinding
  101. );
  102. console.log(
  103. 'responseresponseresponseresponseresponseresponseresponseresponseresponseresponseresponseresponseresponseresponseresponseresponseresponseresponseresponseresponseresponseresponseresponseresponseresponseresponseresponseresponseresponse',
  104. response
  105. );
  106. if (response == true) {
  107. setScreen(1);
  108. } else {
  109. Alert.alert('登入失敗,請檢查您輸入的帳號密碼並再試一次');
  110. }
  111. } catch (error) {
  112. console.log(error);
  113. } finally {
  114. setIsLoading(false);
  115. }
  116. };
  117. return (
  118. <>
  119. <View style={styles.container}>
  120. <View style={styles.bottomContainer}>
  121. <Text style={styles.text}>請輸入現有電子郵件</Text>
  122. <View className="pb-2">
  123. <NormalInput
  124. placeholder="請填寫您的電子郵件"
  125. onChangeText={(email) =>
  126. setBindingFormData({
  127. ...bindingFormData,
  128. email: email
  129. })
  130. }
  131. textContentType="username"
  132. autoComplete="username"
  133. keyboardType="email-address"
  134. autoCapitalize="none"
  135. />
  136. </View>
  137. <View className="pb-2">
  138. <NormalInput
  139. placeholder="請填寫您的密碼"
  140. onChangeText={(password) =>
  141. setBindingFormData({
  142. ...bindingFormData,
  143. password: password
  144. })
  145. }
  146. secureTextEntry={!showPassword}
  147. extendedStyle={{ borderRadius: 12, padding: 20, paddingRight: 50 }}
  148. textContentType="password"
  149. autoComplete="password"
  150. />
  151. <Pressable
  152. className="absolute right-4 top-0 bottom-0 justify-center"
  153. onPress={() => setShowPassword(!showPassword)}
  154. >
  155. <Ionicons
  156. name={showPassword ? 'eye-outline' : 'eye-off-outline'}
  157. size={24}
  158. color="#02677D"
  159. />
  160. </Pressable>
  161. </View>
  162. <NormalButton
  163. title={<Text style={{ color: '#fff' }}>{isLoading ? '處理中...' : '下一步'}</Text>}
  164. onPress={handleVerification}
  165. // extendedStyle={
  166. // forgetPasswordFormData.otpAuthCompleted == true ? { backgroundColor: '#70787C' } : {}
  167. // }
  168. />
  169. {error && <Text style={styles.errorMessage}>{error}</Text>}
  170. </View>
  171. </View>
  172. </>
  173. );
  174. };
  175. const styles = StyleSheet.create({
  176. container: {
  177. flex: 1,
  178. marginHorizontal: 20
  179. },
  180. titleText: {
  181. fontSize: 24,
  182. fontWeight: '300'
  183. },
  184. bottomContainer: {
  185. flex: 3,
  186. paddingBottom: 100
  187. },
  188. breakline: {
  189. width: 24,
  190. height: 1,
  191. backgroundColor: '#000000',
  192. marginVertical: 17
  193. },
  194. text: {
  195. fontSize: 18,
  196. paddingBottom: 10
  197. },
  198. hiddenPasswordFields: {
  199. gap: 10,
  200. paddingTop: 10
  201. },
  202. opacityZero: {
  203. opacity: 0
  204. },
  205. opacityFull: {
  206. opacity: 1
  207. },
  208. errorMessage: {
  209. fontSize: 14,
  210. color: '#ff0033',
  211. fontWeight: '400',
  212. marginLeft: 10,
  213. marginTop: 10
  214. },
  215. footer: { color: '#02677D', fontSize: 16, paddingVertical: 10 }
  216. });
  217. export default BindingPhoneNumberPage;