From 347714992d9d4ec941f65823e1ac0abed8fe89e2 Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Mon, 2 Dec 2024 11:38:20 +0100 Subject: [PATCH] Add TrainTripDetails component to display train reservation details --- src/pages/Travel/TrainTripDetails.tsx | 114 ++++++++++++++++++++++++++ src/pages/Travel/TripDetailsPage.tsx | 8 ++ 2 files changed, 122 insertions(+) create mode 100644 src/pages/Travel/TrainTripDetails.tsx diff --git a/src/pages/Travel/TrainTripDetails.tsx b/src/pages/Travel/TrainTripDetails.tsx new file mode 100644 index 00000000000..afaac7fdbf8 --- /dev/null +++ b/src/pages/Travel/TrainTripDetails.tsx @@ -0,0 +1,114 @@ +import React from 'react'; +import {View} from 'react-native'; +import type {OnyxEntry} from 'react-native-onyx'; +import * as Expensicons from '@components/Icon/Expensicons'; +import MenuItem from '@components/MenuItem'; +import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; +import useLocalize from '@hooks/useLocalize'; +import useStyleUtils from '@hooks/useStyleUtils'; +import useTheme from '@hooks/useTheme'; +import useThemeStyles from '@hooks/useThemeStyles'; +import DateUtils from '@libs/DateUtils'; +import * as TripReservationUtils from '@libs/TripReservationUtils'; +import CONST from '@src/CONST'; +import type {PersonalDetails, Transaction} from '@src/types/onyx'; + +type TrainTripDetailsProps = { + transaction: OnyxEntry; + personalDetails: OnyxEntry; + reservationIndex: number; +}; + +function TrainTripDetails({transaction, personalDetails, reservationIndex}: TrainTripDetailsProps) { + const styles = useThemeStyles(); + const theme = useTheme(); + const StyleUtils = useStyleUtils(); + const {translate} = useLocalize(); + + const trainReservation = transaction?.receipt?.reservationList?.at(reservationIndex); + + if (!trainReservation) { + return null; + } + + const reservationIcon = TripReservationUtils.getTripReservationIcon(trainReservation.type); + const startDate = DateUtils.getFormattedTransportDateAndHour(new Date(trainReservation.start.date)); + const endDate = DateUtils.getFormattedTransportDateAndHour(new Date(trainReservation.end.date)); + + return ( + <> + + + + + + + + {!!trainReservation.coachNumber && ( + + + + )} + {!!trainReservation.seatNumber && ( + + + + )} + + + {!!trainReservation.confirmations?.at(0)?.value && ( + + )} + + ); +} + +TrainTripDetails.displayName = 'TrainTripDetails'; + +export default TrainTripDetails; diff --git a/src/pages/Travel/TripDetailsPage.tsx b/src/pages/Travel/TripDetailsPage.tsx index ee732829921..0b80f8b049d 100644 --- a/src/pages/Travel/TripDetailsPage.tsx +++ b/src/pages/Travel/TripDetailsPage.tsx @@ -21,6 +21,7 @@ import type SCREENS from '@src/SCREENS'; import CarTripDetails from './CarTripDetails'; import FlightTripDetails from './FlightTripDetails'; import HotelTripDetails from './HotelTripDetails'; +import TrainTripDetails from './TrainTripDetails'; type TripDetailsPageProps = StackScreenProps; @@ -75,6 +76,13 @@ function TripDetailsPage({route}: TripDetailsPageProps) { personalDetails={personalDetails} /> )} + {reservationType === CONST.RESERVATION_TYPE.TRAIN && ( + + )}