bindingPhoneNumberPage.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import { View, Text, StyleSheet, Pressable, Alert } from 'react-native';
  2. import { useState } from 'react';
  3. import { Ionicons } from '@expo/vector-icons';
  4. import NormalButton from '../../../global/normal_button';
  5. import NormalInput from '../../../global/normal_input';
  6. import { authenticationService } from '../../../../service/authService';
  7. import { useTranslation } from '../../../../util/hooks/useTranslation';
  8. const BindingPhoneNumberPage = ({ bindingFormData, setBindingFormData, setScreen }: any) => {
  9. const { t } = useTranslation(); // 使用翻译钩子
  10. const [error, setError] = useState('');
  11. const [isLoading, setIsLoading] = useState(false);
  12. const [showPassword, setShowPassword] = useState(false);
  13. const handleVerification = async () => {
  14. setIsLoading(true);
  15. try {
  16. const isBinding = true;
  17. const response = await authenticationService.emailLogin(
  18. bindingFormData.email,
  19. bindingFormData.password,
  20. isBinding
  21. );
  22. if (response == true) {
  23. setScreen(1);
  24. } else {
  25. Alert.alert(t('binding.one.login_failed'));
  26. }
  27. } catch (error) {
  28. console.error('Login error:', error);
  29. } finally {
  30. setIsLoading(false);
  31. }
  32. };
  33. return (
  34. <>
  35. <View style={styles.container}>
  36. <View style={styles.bottomContainer}>
  37. <Text style={styles.text}>{t('binding.one.enter_existing_email')}</Text>
  38. <View className="pb-2">
  39. <NormalInput
  40. placeholder={t('binding.one.enter_your_email')}
  41. onChangeText={(email) =>
  42. setBindingFormData({
  43. ...bindingFormData,
  44. email: email
  45. })
  46. }
  47. textContentType="username"
  48. autoComplete="username"
  49. keyboardType="email-address"
  50. autoCapitalize="none"
  51. />
  52. </View>
  53. <View className="pb-2">
  54. <NormalInput
  55. placeholder={t('binding.one.enter_your_password')}
  56. onChangeText={(password) =>
  57. setBindingFormData({
  58. ...bindingFormData,
  59. password: password
  60. })
  61. }
  62. secureTextEntry={!showPassword}
  63. extendedStyle={{ borderRadius: 12, padding: 20, paddingRight: 50 }}
  64. textContentType="password"
  65. autoComplete="password"
  66. />
  67. <Pressable
  68. className="absolute right-4 top-0 bottom-0 justify-center"
  69. onPress={() => setShowPassword(!showPassword)}
  70. >
  71. <Ionicons
  72. name={showPassword ? 'eye-outline' : 'eye-off-outline'}
  73. size={24}
  74. color="#02677D"
  75. />
  76. </Pressable>
  77. </View>
  78. <NormalButton
  79. title={<Text style={{ color: '#fff' }}>{isLoading ? t('binding.one.processing') : t('common.next')}</Text>}
  80. onPress={handleVerification}
  81. />
  82. {error && <Text style={styles.errorMessage}>{error}</Text>}
  83. </View>
  84. </View>
  85. </>
  86. );
  87. };
  88. const styles = StyleSheet.create({
  89. container: {
  90. flex: 1,
  91. marginHorizontal: 20
  92. },
  93. titleText: {
  94. fontSize: 24,
  95. fontWeight: '300'
  96. },
  97. bottomContainer: {
  98. flex: 3,
  99. paddingBottom: 100
  100. },
  101. breakline: {
  102. width: 24,
  103. height: 1,
  104. backgroundColor: '#000000',
  105. marginVertical: 17
  106. },
  107. text: {
  108. fontSize: 18,
  109. paddingBottom: 10
  110. },
  111. hiddenPasswordFields: {
  112. gap: 10,
  113. paddingTop: 10
  114. },
  115. opacityZero: {
  116. opacity: 0
  117. },
  118. opacityFull: {
  119. opacity: 1
  120. },
  121. errorMessage: {
  122. fontSize: 14,
  123. color: '#ff0033',
  124. fontWeight: '400',
  125. marginLeft: 10,
  126. marginTop: 10
  127. },
  128. footer: { color: '#02677D', fontSize: 16, paddingVertical: 10 }
  129. });
  130. export default BindingPhoneNumberPage;