homePage.tsx 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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, currentPrice, setUserID, setCurrentPrice } = 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. useEffect(() => {
  42. const fetchCurrentPrice = async () => {
  43. try {
  44. const response = await chargeStationService.getCurrentPrice();
  45. if (response) {
  46. setCurrentPrice(response);
  47. }
  48. } catch (error) {
  49. console.log('main page fetch current price error', error);
  50. }
  51. };
  52. fetchCurrentPrice();
  53. }, []);
  54. return (
  55. <SafeAreaView edges={['top', 'left', 'right']} className="flex-1 bg-white">
  56. <ScrollView showsVerticalScrollIndicator={false} className="flex-1 mx-[5%] ">
  57. <View className=" flex-1 pt-8 ">
  58. <View className="flex-row items-center pb-4">
  59. <HomeIconSvg />
  60. <View className="pl-2 flex-1 flex-column ">
  61. <View className="flex-row justify-between">
  62. <Text className="text-lg pb-1">你好!</Text>
  63. {/* <BellIconSvg /> */}
  64. </View>
  65. <Text className="text-4xl font-light ">{user?.nickname}</Text>
  66. </View>
  67. </View>
  68. <View className=" flex-1 justify-center ">
  69. <Pressable onPress={() => router.push('searchPage')}>
  70. <View
  71. style={{
  72. borderWidth: 1,
  73. padding: 24,
  74. borderRadius: 12,
  75. borderColor: '#bbbbbb',
  76. maxWidth: '100%'
  77. }}
  78. >
  79. <Text style={{ color: '#888888', fontSize: 16 }}>搜尋充電站或地區..</Text>
  80. </View>
  81. </Pressable>
  82. </View>
  83. </View>
  84. <View className="flex-1">
  85. <RecentlyBookedScrollView />
  86. </View>
  87. <View className="flex-1">
  88. <View className=" mb-4">
  89. <NormalButton
  90. // onPress={() => console.log('掃瞄及充電')}
  91. onPress={() => router.push('scanQrPage')}
  92. title={
  93. <View className="flex flex-row space-x-2 items-center">
  94. <QrCodeIconSvg />
  95. <Text className="text-white font-bold text-lg">掃描及充電</Text>
  96. </View>
  97. }
  98. extendedStyle={{
  99. alignItems: 'flex-start',
  100. padding: 24
  101. }}
  102. />
  103. </View>
  104. <View className="flex-1 flex-row justify-between gap-6">
  105. <View className="flex-1">
  106. <NormalButton
  107. onPress={() => router.push('bookingMenuPage')}
  108. title={
  109. <View className="flex flex-row space-x-2 items-center ">
  110. <MyBookingIconSvg />
  111. <Text className="text-white font-bold text-lg">我的預約</Text>
  112. </View>
  113. }
  114. extendedStyle={{
  115. alignItems: 'flex-start',
  116. padding: 24
  117. }}
  118. />
  119. </View>
  120. <View className="flex-1">
  121. {/* <NormalButton
  122. onPress={() => router.push('myVehiclePage')}
  123. title={
  124. <View className="flex flex-row space-x-2 items-center">
  125. <MyVehicleIconSvg />
  126. <Text className="text-white font-bold text-lg">我的車輛</Text>
  127. </View>
  128. }
  129. extendedStyle={{
  130. alignItems: 'flex-start',
  131. padding: 24
  132. }}
  133. /> */}
  134. <NormalButton
  135. onPress={() => router.push('accountMainPage')}
  136. title={
  137. <View className="flex flex-row space-x-2 items-center">
  138. <MyVehicleIconSvg />
  139. <Text className="text-white font-bold text-lg">我的帳戶</Text>
  140. </View>
  141. }
  142. extendedStyle={{
  143. alignItems: 'flex-start',
  144. padding: 24
  145. }}
  146. />
  147. </View>
  148. </View>
  149. <View className="mt-4">
  150. <NormalButton
  151. // onPress={() => console.log('掃瞄及充電')}
  152. onPress={() => router.push('vipQrPage')}
  153. title={
  154. <View className="flex flex-row items-center space-x-2">
  155. <VipCodeIconSvg />
  156. <Text className="text-white font-bold text-lg">專屬會員二維碼</Text>
  157. </View>
  158. }
  159. extendedStyle={{
  160. alignItems: 'flex-start',
  161. padding: 24
  162. }}
  163. />
  164. </View>
  165. </View>
  166. </ScrollView>
  167. </SafeAreaView>
  168. );
  169. };
  170. export default HomePage;