|
|
@@ -2,7 +2,7 @@ import { View, Text, ScrollView, Pressable, StyleSheet, Alert } from 'react-nati
|
|
|
import { SafeAreaView } from 'react-native-safe-area-context';
|
|
|
import { router, useLocalSearchParams, useNavigation } from 'expo-router';
|
|
|
import NormalButton from '../global/normal_button';
|
|
|
-import { useEffect } from 'react';
|
|
|
+import { useEffect, useState } from 'react';
|
|
|
import { chargeStationService } from '../../service/chargeStationService';
|
|
|
import useUserInfoStore from '../../providers/userinfo_store';
|
|
|
import { PreviousPageBlackSvg } from '../global/SVG';
|
|
|
@@ -10,14 +10,21 @@ import { PreviousPageBlackSvg } from '../global/SVG';
|
|
|
const PenaltyPaymentPageComponent = () => {
|
|
|
const params = useLocalSearchParams();
|
|
|
const { userID } = useUserInfoStore();
|
|
|
- console.log('params in penaltyPaymentPageComponent', params);
|
|
|
const navigation = useNavigation();
|
|
|
-
|
|
|
+ const [leaving_time, setLeavingTime] = useState<string | null>(null)
|
|
|
useEffect(() => {
|
|
|
navigation.setOptions({
|
|
|
gestureEnabled: false
|
|
|
});
|
|
|
}, [navigation]);
|
|
|
+ useEffect(() => {
|
|
|
+ chargeStationService.fetchChargingDetails(params.id.toString()).then(res => {
|
|
|
+ if (res && res[0].charging.length > 0) {
|
|
|
+ const { date, time } = convertBookingDateTime(res[0].charging[0].leaving_time as string);
|
|
|
+ setLeavingTime(time);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }, [params]);
|
|
|
const convertBookingDateTime = (isoDateString: string): { date: string; time: string } => {
|
|
|
const bookingDate = new Date(isoDateString);
|
|
|
|
|
|
@@ -41,14 +48,13 @@ const PenaltyPaymentPageComponent = () => {
|
|
|
|
|
|
const calculateUserEndTime = (actualEndTimeStr: string, penaltyFee: string): string => {
|
|
|
const actualEndTime = new Date(actualEndTimeStr);
|
|
|
- const penaltyMinutes = Math.floor(parseFloat(penaltyFee) / 3); // $3 per minute
|
|
|
+ const penaltyMinutes = Math.floor(parseFloat(penaltyFee) / 3) + 15 // $3 per minute
|
|
|
const userEndTime = new Date(actualEndTime.getTime() + penaltyMinutes * 60000); // add minutes
|
|
|
|
|
|
return userEndTime.toISOString();
|
|
|
};
|
|
|
|
|
|
- const { date, time } = convertBookingDateTime(params.book_time);
|
|
|
- const { date: end_date, time: end_time } = convertBookingDateTime(params.end_time as string);
|
|
|
+ const { date, time } = convertBookingDateTime(params.book_time as string);
|
|
|
const { date: actual_end_date, time: actual_end_time } = convertBookingDateTime(params.actual_end_time as string);
|
|
|
const { time: user_end_time } = convertBookingDateTime(
|
|
|
calculateUserEndTime(params.actual_end_time as string, params.penalty_fee as string)
|
|
|
@@ -96,9 +102,6 @@ const PenaltyPaymentPageComponent = () => {
|
|
|
</Pressable>
|
|
|
<Text className="text-3xl my-8 text-center">尚未繳付罰款的充電記錄</Text>
|
|
|
</View>
|
|
|
- {/* <View className="pl-8 pt-8">
|
|
|
- <Text className="text-3xl mt-8">尚未繳付罰款的充電記錄</Text>
|
|
|
- </View> */}
|
|
|
|
|
|
<View className="flex-1 mt-4 mx-[5%]">
|
|
|
<View className="flex-1 flex-row items-center pb-3">
|
|
|
@@ -115,7 +118,7 @@ const PenaltyPaymentPageComponent = () => {
|
|
|
實際充電結束時間
|
|
|
</Text>
|
|
|
<Text style={styles.greenColor} className="text-4xl text-center pt-2">
|
|
|
- {user_end_time}
|
|
|
+ {leaving_time || user_end_time}
|
|
|
</Text>
|
|
|
</View>
|
|
|
</View>
|