createWallet.tsx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import { View, Text, StyleSheet, ActivityIndicator, Pressable } from 'react-native';
  2. import NormalInput from '../../../global/normal_input';
  3. import NormalButton from '../../../global/normal_button';
  4. import { Ionicons } from '@expo/vector-icons';
  5. import { useState } from 'react';
  6. import useSignUpStore from '../../../../providers/signup_form_store';
  7. import { authenticationService } from '../../../../service/authService';
  8. import { Alert } from 'react-native';
  9. import useVehicleStore from '../../../../providers/vehicle_store';
  10. import { usePushNotifications } from '../../../../app/hooks/usePushNotifications';
  11. import { useTranslation } from '../../../../util/hooks/useTranslation';
  12. type CreateWalletProps = {
  13. goToNextPage: () => void;
  14. };
  15. const CreateWallet: React.FC<CreateWalletProps> = ({ goToNextPage }) => {
  16. const { expoPushToken } = usePushNotifications();
  17. const [isLoading, setIsLoading] = useState(false);
  18. const { signUpFormData, setSignUpFormData } = useSignUpStore();
  19. const [error, setError] = useState('');
  20. const [showPassword1, setShowPassword1] = useState(false);
  21. const [showPassword2, setShowPassword2] = useState(false);
  22. const [passwordConfirm, setPasswordConfirm] = useState('');
  23. const {
  24. BrandID,
  25. ModelID,
  26. } = useVehicleStore();
  27. const { t, ready, currentLanguage } = useTranslation();
  28. console.log('expoPushToken?.data', expoPushToken?.data);
  29. let customerData: any = {
  30. customerBaseInfo: {
  31. name: signUpFormData.nickName.trim(),
  32. email: signUpFormData.email,
  33. password: signUpFormData.password,
  34. gender: signUpFormData.gender,
  35. birthday: signUpFormData.birthDateDay + '/' + signUpFormData.birthDateMonth + '/11',
  36. address: signUpFormData.address,
  37. phone: parseInt(signUpFormData.phone as string, 10),
  38. isUberDriver: signUpFormData.isUberDriver,
  39. notify_session_id:
  40. expoPushToken?.data ||
  41. `ExponentPushToken[TestToken${Math.random().toString(36).substring(2, 8).toUpperCase()}]`
  42. }
  43. };
  44. if (ModelID !== '' && BrandID !== '' && signUpFormData.licensePlate !== '') {
  45. customerData.customerCarInfo = {
  46. type_id: ModelID,
  47. brand_id: BrandID,
  48. licensePlate: signUpFormData.licensePlate
  49. };
  50. }
  51. const handleNext = async () => {
  52. if (
  53. signUpFormData.email === '' ||
  54. signUpFormData.password === '' ||
  55. signUpFormData.phone === '' ||
  56. passwordConfirm === ''
  57. ) {
  58. setError(t("register.four.error1"));
  59. } else if (signUpFormData.password !== passwordConfirm) {
  60. Alert.alert(t("register.four.alert1"));
  61. } else {
  62. setError('');
  63. setIsLoading(true);
  64. try {
  65. const result = await authenticationService.signUp(customerData);
  66. console.log('handleNext in CreateWallet Page, i am sending this customerData', customerData);
  67. if (result) {
  68. goToNextPage();
  69. } else {
  70. Alert.alert(t("register.four.alert2"));
  71. }
  72. } catch (error) {
  73. setError(t("register.four.error2"));
  74. } finally {
  75. setIsLoading(false);
  76. }
  77. }
  78. };
  79. return (
  80. <View style={styles.container}>
  81. <Text style={styles.text}>{t("register.four.label")}</Text>
  82. <View
  83. style={{
  84. display: 'flex',
  85. flexDirection: 'column',
  86. gap: 10
  87. }}
  88. >
  89. <NormalInput
  90. placeholder={t("register.four.label")}
  91. onChangeText={(email) =>
  92. setSignUpFormData({
  93. ...signUpFormData,
  94. email: email
  95. })
  96. }
  97. autoCapitalize="none"
  98. />
  99. <NormalInput
  100. placeholder={t("register.four.password")}
  101. onChangeText={(text) => {
  102. setSignUpFormData({
  103. ...signUpFormData,
  104. password: text
  105. });
  106. }}
  107. secureTextEntry={!showPassword1}
  108. />
  109. <Pressable
  110. className="absolute right-4 top-0 bottom-0 justify-center"
  111. onPress={() => setShowPassword1(!showPassword1)}
  112. >
  113. <Ionicons name={showPassword1 ? 'eye-outline' : 'eye-off-outline'} size={24} color="#02677D" />
  114. </Pressable>
  115. <View className="mb-4">
  116. <NormalInput
  117. placeholder={t("register.four.confirmPassword")}
  118. onChangeText={(text) => setPasswordConfirm(text)}
  119. secureTextEntry={!showPassword2}
  120. />
  121. <Pressable
  122. className="absolute right-4 top-0 bottom-0 justify-center"
  123. onPress={() => setShowPassword2(!showPassword2)}
  124. >
  125. <Ionicons
  126. name={showPassword2 ? 'eye-outline' : 'eye-off-outline'}
  127. size={24}
  128. color="#02677D"
  129. />
  130. </Pressable>
  131. </View>
  132. </View>
  133. {error && <Text style={styles.errorMessage}>{error}</Text>}
  134. <View>
  135. <NormalButton
  136. title={isLoading ? <ActivityIndicator /> : <Text style={{ color: '#fff' }}>{t("register.four.complete")}</Text>}
  137. onPress={handleNext}
  138. extendedStyle={{}}
  139. />
  140. </View>
  141. </View>
  142. );
  143. };
  144. const styles = StyleSheet.create({
  145. container: {
  146. flex: 1,
  147. marginHorizontal: 20
  148. },
  149. text: {
  150. fontSize: 20,
  151. paddingBottom: 10
  152. },
  153. errorMessage: {
  154. fontSize: 14,
  155. color: '#ff0033',
  156. fontWeight: '400',
  157. marginLeft: 10,
  158. marginBottom: 10
  159. }
  160. });
  161. export default CreateWallet;