accountSettingPageComponent.tsx 6.8 KB

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