homePage.tsx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import { View, Text, ScrollView, FlatList, Pressable, ActivityIndicator, Image } from 'react-native';
  2. import NormalButton from '../global/normal_button';
  3. import { SafeAreaView } from 'react-native-safe-area-context';
  4. import { router } from 'expo-router';
  5. import RecentlyBookedScrollView from '../global/recentlyBookedScrollView';
  6. import {
  7. BellIconSvg,
  8. HomeIconSvg,
  9. MyBookingIconSvg,
  10. MyVehicleIconSvg,
  11. QrCodeIconSvg,
  12. VipCodeIconSvg
  13. } from '../global/SVG';
  14. import { AuthContext } from '../../context/AuthProvider';
  15. import { useContext, useEffect, useState } from 'react';
  16. import { authenticationService } from '../../service/authService';
  17. import { chargeStationService } from '../../service/chargeStationService';
  18. import { walletService } from '../../service/walletService';
  19. import useUserInfoStore from '../../providers/userinfo_store';
  20. interface HomePageProps {}
  21. const HomePage: React.FC<HomePageProps> = () => {
  22. const now = new Date();
  23. const { user } = useContext(AuthContext);
  24. const { userID, setUserID } = useUserInfoStore();
  25. // Effect for fetching user ID
  26. useEffect(() => {
  27. const fetchID = async () => {
  28. try {
  29. const response = await authenticationService.getUserInfo();
  30. if (response) {
  31. setUserID(response.data.id);
  32. } else {
  33. console.log('fail to set user ID');
  34. }
  35. } catch (error) {
  36. console.log(error);
  37. }
  38. };
  39. fetchID();
  40. }, []);
  41. return (
  42. <SafeAreaView edges={['top', 'left', 'right']} className="flex-1 bg-white">
  43. <ScrollView showsVerticalScrollIndicator={false} className="flex-1 mx-[5%] ">
  44. <View className=" flex-1 pt-8 ">
  45. <View className="flex-row items-center pb-4">
  46. <HomeIconSvg />
  47. <View className="pl-2 flex-1 flex-column ">
  48. <View className="flex-row justify-between">
  49. <Text className="text-lg pb-1">你好!</Text>
  50. <BellIconSvg />
  51. </View>
  52. <Text className="text-4xl font-light ">{user?.nickname}</Text>
  53. </View>
  54. </View>
  55. <View className=" flex-1 justify-center ">
  56. <Pressable onPress={() => router.push('searchPage')}>
  57. <View
  58. style={{
  59. borderWidth: 1,
  60. padding: 24,
  61. borderRadius: 12,
  62. borderColor: '#bbbbbb',
  63. maxWidth: '100%'
  64. }}
  65. >
  66. <Text style={{ color: '#888888', fontSize: 16 }}>搜尋充電站或地區..</Text>
  67. </View>
  68. </Pressable>
  69. </View>
  70. </View>
  71. <View className="flex-1">
  72. <RecentlyBookedScrollView />
  73. </View>
  74. <View className="flex-1">
  75. <View className=" mb-4">
  76. <NormalButton
  77. // onPress={() => console.log('掃瞄及充電')}
  78. onPress={() => router.push('scanQrPage')}
  79. title={
  80. <View className="flex flex-row space-x-2 items-center">
  81. <QrCodeIconSvg />
  82. <Text className="text-white font-bold text-lg">掃描及充電</Text>
  83. </View>
  84. }
  85. extendedStyle={{
  86. alignItems: 'flex-start',
  87. padding: 24
  88. }}
  89. />
  90. </View>
  91. <View className="flex-1 flex-row justify-between gap-6">
  92. <View className="flex-1">
  93. <NormalButton
  94. onPress={() => router.push('bookingMenuPage')}
  95. title={
  96. <View className="flex flex-row space-x-2 items-center ">
  97. <MyBookingIconSvg />
  98. <Text className="text-white font-bold text-lg">我的預約</Text>
  99. </View>
  100. }
  101. extendedStyle={{
  102. alignItems: 'flex-start',
  103. padding: 24
  104. }}
  105. />
  106. </View>
  107. <View className="flex-1">
  108. <NormalButton
  109. onPress={() => router.push('myVehiclePage')}
  110. title={
  111. <View className="flex flex-row space-x-2 items-center">
  112. <MyVehicleIconSvg />
  113. <Text className="text-white font-bold text-lg">我的車輛</Text>
  114. </View>
  115. }
  116. extendedStyle={{
  117. alignItems: 'flex-start',
  118. padding: 24
  119. }}
  120. />
  121. </View>
  122. </View>
  123. <View className="mt-4">
  124. <NormalButton
  125. // onPress={() => console.log('掃瞄及充電')}
  126. onPress={() => router.push('vipQrPage')}
  127. title={
  128. <View className="flex flex-row items-center space-x-2">
  129. <VipCodeIconSvg />
  130. <Text className="text-white font-bold text-lg">專屬會員二維碼</Text>
  131. </View>
  132. }
  133. extendedStyle={{
  134. alignItems: 'flex-start',
  135. padding: 24
  136. }}
  137. />
  138. </View>
  139. </View>
  140. </ScrollView>
  141. </SafeAreaView>
  142. );
  143. };
  144. export default HomePage;