futureReservationPageComponent.tsx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // component/chargingPage/futureReservationPageComponent.tsx
  2. import { View, Text, ScrollView, StyleSheet, ActivityIndicator } from 'react-native';
  3. import { useEffect, useState } from 'react';
  4. import { SafeAreaView } from 'react-native-safe-area-context';
  5. import NormalButton from '../global/normal_button';
  6. import { router } from 'expo-router';
  7. import { convertToHKTime } from '../../util/lib';
  8. import { useTranslation } from '../../util/hooks/useTranslation';
  9. const FutureReservationPageComponent = ({ data }) => {
  10. const { t } = useTranslation();
  11. const [loading, setLoading] = useState(false);
  12. const [stationInfo, setStationInfo] = useState(null);
  13. const plan = data.book_time === data.end_time ? t('future_reservation.full_charge') : t('future_reservation.per_kwh');
  14. const kwh = data.total_power === null ? '' : `${data.total_power} kWh`;
  15. ///如果充電停機 應該show 充電停機 not 80 kWh
  16. useEffect(() => {
  17. if (data && data.connector && data.connector.EquipmentID && data.connector.EquipmentID.StationID) {
  18. try {
  19. const parsedSnapshot = JSON.parse(data.connector.EquipmentID.StationID.snapshot);
  20. setStationInfo(parsedSnapshot);
  21. } catch (error) {
  22. console.error('Error parsing station snapshot:', error);
  23. }
  24. }
  25. }, [data]);
  26. return (
  27. <SafeAreaView edges={['top', 'left', 'right']} className="flex-1 bg-white">
  28. <ScrollView className="flex-1 mt-8 " nestedScrollEnabled={true} showsVerticalScrollIndicator={false}>
  29. <View className="mx-[5%]">
  30. <View className="">
  31. <Text className="text-5xl pt-1 pb-6">{t('future_reservation.no_charging_vehicle')}</Text>
  32. {loading ? (
  33. <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
  34. <ActivityIndicator color="#34657b" />
  35. </View>
  36. ) : (
  37. <>
  38. <Text className="text-2xl pb-2 ">{t('future_reservation.next_reservation')}</Text>
  39. <View className="border-gray-200 border rounded-md">
  40. <View className="flex-1 mt-4 mx-[5%] ">
  41. <View className="flex-1 flex-row items-center pb-3">
  42. <View className="flex-1 flex-column">
  43. <Text style={styles.grayColor} className="text-base">
  44. {t('future_reservation.date')}
  45. </Text>
  46. <Text style={styles.greenColor} className="text-4xl text-center pt-2">
  47. {convertToHKTime(data.book_time)
  48. .hkDate.split('/')
  49. .reverse()
  50. .slice(1)
  51. .join(t('future_reservation.month'))}
  52. </Text>
  53. </View>
  54. <View className="flex-1 flex-column">
  55. <Text style={styles.grayColor} className="text-base pl-7">
  56. {t('future_reservation.time')}
  57. </Text>
  58. <Text style={styles.greenColor} className="text-4xl text-center pt-2">
  59. {convertToHKTime(data.book_time).hkTime.slice(0, 5)}
  60. </Text>
  61. </View>
  62. </View>
  63. <View className="flex-1 flex-column justify-center space-y-1 pb-3">
  64. <Text style={styles.grayColor} className="text-base">
  65. {t('future_reservation.charging_location')}
  66. </Text>
  67. <Text style={styles.greenColor} className="text-2xl ">
  68. {stationInfo?.StationName || 'N/A'}
  69. </Text>
  70. <Text style={styles.grayColor} className="text-sm">
  71. {stationInfo?.Address || 'N/A'}
  72. </Text>
  73. </View>
  74. <View className="flex-1 flex-row pb-3 ">
  75. <View className="flex-column flex-1">
  76. <Text style={styles.grayColor} className="text-base">
  77. {t('future_reservation.plan')}
  78. </Text>
  79. <Text style={styles.greenColor} className="text-lg">
  80. {plan}
  81. </Text>
  82. <Text style={styles.grayColor} className="text-sm">
  83. {kwh}
  84. </Text>
  85. </View>
  86. {/* <View className="flex-column flex-1">
  87. <Text style={styles.grayColor} className="text-base">
  88. 車輛
  89. </Text>
  90. <Text style={styles.greenColor} className="text-lg">
  91. {data.car.car_brand.name}
  92. </Text>
  93. <Text style={styles.greenColor} className="text-lg">
  94. {data.car.car_type.name}
  95. </Text>
  96. </View> */}
  97. </View>
  98. </View>
  99. </View>
  100. <View className="pt-6">
  101. <NormalButton
  102. title={<Text className="text-white text-lg">{t('future_reservation.return_home')}</Text>}
  103. onPress={() => router.push('mainPage')}
  104. />
  105. </View>
  106. </>
  107. )}
  108. </View>
  109. </View>
  110. </ScrollView>
  111. </SafeAreaView>
  112. );
  113. };
  114. const styles = StyleSheet.create({
  115. grayColor: {
  116. color: '#888888'
  117. },
  118. greenColor: {
  119. color: '#02677D'
  120. }
  121. });
  122. export default FutureReservationPageComponent;