Skip to content

Commit

Permalink
Add TrainTripDetails component to display train reservation details
Browse files Browse the repository at this point in the history
  • Loading branch information
blazejkustra committed Dec 2, 2024
1 parent 9f7ca7e commit 3477149
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 0 deletions.
114 changes: 114 additions & 0 deletions src/pages/Travel/TrainTripDetails.tsx
Original file line number Diff line number Diff line change
@@ -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<Transaction>;
personalDetails: OnyxEntry<PersonalDetails>;
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 (
<>
<MenuItem
label={translate('travel.trainDetails.passenger')}
title={personalDetails?.displayName}
icon={personalDetails?.avatar ?? Expensicons.FallbackAvatar}
iconType={CONST.ICON_TYPE_AVATAR}
description={personalDetails?.login}
interactive={false}
wrapperStyle={styles.pb3}
/>

<MenuItem
title={`${trainReservation.start.longName} (${trainReservation.start.shortName}) ${translate('common.conjunctionTo')} ${trainReservation.end.longName} (${
trainReservation.end.shortName
})`}
description={`${trainReservation.company?.longName} ${CONST.DOT_SEPARATOR} ${trainReservation.route?.name}`}
descriptionTextStyle={[styles.textLabelSupporting, styles.lh16]}
secondaryIcon={reservationIcon}
wrapperStyle={[styles.taskDescriptionMenuItem]}
numberOfLinesDescription={2}
iconHeight={20}
iconWidth={20}
iconStyles={[StyleUtils.getTripReservationIconContainer(false), styles.mr3]}
secondaryIconFill={theme.icon}
interactive={false}
/>
<MenuItemWithTopDescription
description={`${translate('travel.trainDetails.departs')} ${CONST.DOT_SEPARATOR} ${startDate.date}`}
title={startDate.hour}
helperText={`${trainReservation.start.longName} (${trainReservation.start.shortName})`}
helperTextStyle={[styles.pb3, styles.mtn2]}
interactive={false}
/>
<MenuItemWithTopDescription
description={`${translate('travel.trainDetails.arrives')} ${CONST.DOT_SEPARATOR} ${endDate.date}`}
title={endDate.hour}
helperText={`${trainReservation.end.longName} (${trainReservation.end.shortName})`}
helperTextStyle={[styles.pb3, styles.mtn2]}
interactive={false}
/>

<View style={[styles.flexRow, styles.flexWrap]}>
{!!trainReservation.coachNumber && (
<View style={styles.w50}>
<MenuItemWithTopDescription
description={translate('travel.trainDetails.coachNumber')}
title={trainReservation.coachNumber}
interactive={false}
/>
</View>
)}
{!!trainReservation.seatNumber && (
<View style={styles.w50}>
<MenuItemWithTopDescription
description={translate('travel.trainDetails.seat')}
title={trainReservation.seatNumber}
interactive={false}
/>
</View>
)}
</View>

{!!trainReservation.confirmations?.at(0)?.value && (
<MenuItemWithTopDescription
description={translate('travel.trainDetails.confirmation')}
title={trainReservation.confirmations?.at(0)?.value}
interactive={false}
/>
)}
</>
);
}

TrainTripDetails.displayName = 'TrainTripDetails';

export default TrainTripDetails;
8 changes: 8 additions & 0 deletions src/pages/Travel/TripDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<TravelNavigatorParamList, typeof SCREENS.TRAVEL.TRIP_DETAILS>;

Expand Down Expand Up @@ -75,6 +76,13 @@ function TripDetailsPage({route}: TripDetailsPageProps) {
personalDetails={personalDetails}
/>
)}
{reservationType === CONST.RESERVATION_TYPE.TRAIN && (
<TrainTripDetails
transaction={transaction}
personalDetails={personalDetails}
reservationIndex={route.params.reservationIndex}
/>
)}
<MenuItem
title={translate('travel.modifyTrip')}
icon={Expensicons.Pencil}
Expand Down

0 comments on commit 3477149

Please sign in to comment.