accountSettingPageComponent.tsx 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import { View, Text, ScrollView, Pressable, Button, Alert } from 'react-native';
  2. import React, { useContext } from 'react';
  3. import { SafeAreaView } from 'react-native-safe-area-context';
  4. import { router } from 'expo-router';
  5. import { CrossLogoSvg, RightArrowIconSvg } from '../global/SVG';
  6. import { AuthContext, useAuth } from '../../context/AuthProvider';
  7. const AccountSettingPageComponent = () => {
  8. const { user } = useContext(AuthContext);
  9. const { logout } = useAuth();
  10. console.log(user);
  11. const genderText = user?.gender === 'woman' ? '女' : user?.gender === 'man' ? '男' : user?.gender;
  12. const handleDeletionAccount = () => {
  13. Alert.alert('Delete Account', 'Are you sure you want to delete your account? This action cannot be undone.', [
  14. {
  15. text: 'Cancel',
  16. style: 'cancel'
  17. },
  18. {
  19. text: 'Delete',
  20. style: 'destructive',
  21. onPress: async () => {
  22. try {
  23. logout();
  24. // await walletService.deleteWallet(user.id);
  25. // Handle successful deletion (e.g., logout and redirect)
  26. // You might want to add additional logic here
  27. } catch (error) {
  28. console.error('Error deleting account:', error);
  29. Alert.alert('Error', 'Failed to delete account. Please try again.');
  30. }
  31. }
  32. }
  33. ]);
  34. };
  35. return (
  36. <SafeAreaView className="flex-1 bg-white" edges={['top', 'right', 'left']}>
  37. <ScrollView className="flex-1 mx-[5%]" showsVerticalScrollIndicator={false}>
  38. <View style={{ marginTop: 25 }}>
  39. <Pressable
  40. onPress={() => {
  41. router.replace('/accountMainPage');
  42. }}
  43. >
  44. <CrossLogoSvg />
  45. </Pressable>
  46. <Text style={{ fontSize: 45, marginVertical: 25 }}>帳戶管理</Text>
  47. </View>
  48. <View>
  49. <View className="flex-col">
  50. <Pressable onPress={() => console.log('abc')}>
  51. <View className="flex-row items-center justify-between">
  52. <View className="flex-col py-4">
  53. <Text className="text-lg pb-1">電郵地址</Text>
  54. <Text style={{ color: '#555555' }}>{user?.email}</Text>
  55. </View>
  56. {/* <RightArrowIconSvg /> */}
  57. </View>
  58. </Pressable>
  59. <View className="h-0.5 bg-[#f4f4f4] " />
  60. </View>
  61. <View className="flex-col ">
  62. <Pressable onPress={() => router.push('changePasswordPage')}>
  63. <View className="flex-row items-center justify-between">
  64. <View className="flex-col py-4">
  65. <Text className="text-lg pb-1">帳戶密碼</Text>
  66. <Text style={{ color: '#555555' }}>********</Text>
  67. </View>
  68. <RightArrowIconSvg />
  69. </View>
  70. </Pressable>
  71. <View className="h-0.5 bg-[#f4f4f4] " />
  72. </View>
  73. <View className="flex-col ">
  74. <Pressable onPress={() => router.push('changeNamePage')}>
  75. <View className="flex-row items-center justify-between">
  76. <View className="flex-col py-4">
  77. <Text className="text-lg pb-1">暱稱</Text>
  78. <Text style={{ color: '#555555' }}>{user?.nickname}</Text>
  79. </View>
  80. <RightArrowIconSvg />
  81. </View>
  82. </Pressable>
  83. <View className="h-0.5 bg-[#f4f4f4]" />
  84. </View>
  85. <View className="flex-col ">
  86. <Pressable onPress={() => router.push('changeGenderPage')}>
  87. <View className="flex-row items-center justify-between">
  88. <View className="flex-col py-4">
  89. <Text className="text-lg pb-1">性別</Text>
  90. <Text style={{ color: '#555555' }}>{genderText}</Text>
  91. </View>
  92. <RightArrowIconSvg />
  93. </View>
  94. </Pressable>
  95. <View className="h-0.5 bg-[#f4f4f4]" />
  96. </View>
  97. <View className="flex-col ">
  98. <Pressable onPress={() => router.push('changeCarPage')}>
  99. <View className="flex-row items-center justify-between">
  100. <View className="flex-col py-4">
  101. <Text className="text-lg pb-1">車牌號碼</Text>
  102. <Text style={{ color: '#555555' }}>{user?.car}</Text>
  103. </View>
  104. <RightArrowIconSvg />
  105. </View>
  106. </Pressable>
  107. <View className="h-0.5 bg-[#f4f4f4]" />
  108. </View>
  109. <View className="flex-col ">
  110. {/* <Pressable onPress={() => router.push('changePhonePage')}>
  111. <View className="flex-row items-center justify-between">
  112. <View className="flex-co py-4">
  113. <Text className="text-lg pb-1">電話號碼</Text>
  114. <Text style={{ color: '#555555' }}>
  115. {user?.phone ? `+852 ${user.phone}` : 'No phone number provided'}
  116. </Text>
  117. </View>
  118. <RightArrowIconSvg />
  119. </View>
  120. </Pressable>
  121. <View className="h-0.5 bg-[#f4f4f4]" /> */}
  122. <Button onPress={handleDeletionAccount} title="刪除帳戶" color="red"></Button>
  123. </View>
  124. </View>
  125. </ScrollView>
  126. </SafeAreaView>
  127. );
  128. };
  129. export default AccountSettingPageComponent;