Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CONST/SENTRY_LABEL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,7 @@ const SENTRY_LABEL = {
TRIP_ROOM_PREVIEW: {
CARD: 'TripRoomPreview-Card',
RESERVATION: 'TripRoomPreview-Reservation',
BOOKING: 'TripRoomPreview-Booking',
VIEW_BUTTON: 'TripRoomPreview-ViewButton',
},
TRIP_DETAILS: {
Expand Down
55 changes: 9 additions & 46 deletions src/components/ReportActionItem/TripDetailsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ import variables from '@styles/variables';

import CONST from '@src/CONST';
import type {ReservationData} from '@src/libs/TripReservationUtils';
import {formatCancelledDescription, formatTransitLocationLabel, getPNRReservationDataFromTripReport, getTripReservationCode, getTripReservationIcon} from '@src/libs/TripReservationUtils';
import {
formatCancelledDescription,
formatTransitLocationLabel,
getBookingTitle,
getPNRReservationDataFromTripReport,
getTripReservationCode,
getTripReservationIcon,
} from '@src/libs/TripReservationUtils';
import ONYXKEYS from '@src/ONYXKEYS';
import {DYNAMIC_ROUTES} from '@src/ROUTES';
import type {Report} from '@src/types/onyx';
Expand All @@ -32,7 +39,6 @@ import type Transaction from '@src/types/onyx/Transaction';

import type {OnyxEntry} from 'react-native-onyx';

import {differenceInCalendarDays} from 'date-fns';
import {Str} from 'expensify-common';
import React from 'react';
import {View} from 'react-native';
Expand Down Expand Up @@ -196,49 +202,6 @@ function TripDetailsView({tripRoomReport, shouldShowHorizontalRule, tripTransact
return `${convertToDisplayString(amount, currency)} • ${trips.toLowerCase()}`;
};

const getTripTitle = (reservations: ReservationData[]) => {
if (reservations.length === 0) {
return '';
}

const firstReservation = reservations.at(0)?.reservation;
const lastReservation = reservations.at(reservations.length - 1)?.reservation;

if (!lastReservation || !firstReservation) {
return '';
}

switch (firstReservation?.type) {
case CONST.RESERVATION_TYPE.FLIGHT: {
const destinationReservation = reservations.findLast((reservation) => reservation.reservation.legId === firstReservation.legId);
if (!destinationReservation) {
return '';
}
return `${translate('travel.flightTo')} ${formatTransitLocationLabel(destinationReservation.reservation.end, true)}`;
}
case CONST.RESERVATION_TYPE.TRAIN:
if (reservations.length === 2 && firstReservation.start.shortName === lastReservation.end.shortName) {
return `${translate('travel.trainTo')} ${Str.recapitalize(lastReservation.start.longName ?? '')}`;
}
return `${translate('travel.trainTo')} ${Str.recapitalize(lastReservation.end.longName ?? '')}`;
case CONST.RESERVATION_TYPE.HOTEL: {
const nights = differenceInCalendarDays(new Date(lastReservation?.end.date), new Date(firstReservation.start.date));
return `${nights} ${nights > 1 ? translate('travel.nightsIn') : translate('travel.nightIn')} ${Str.recapitalize(firstReservation.start.longName ?? '')}`;
}
case CONST.RESERVATION_TYPE.CAR: {
const days = differenceInCalendarDays(new Date(lastReservation.end.date), new Date(firstReservation.start.date));

if (days > 0) {
return `${days} ${days > 1 ? translate('common.days') : translate('common.day')}${translate('travel.carRental')}`;
}

return `${DateUtils.getFormattedDurationBetweenDates(translate, new Date(firstReservation.start.date), new Date(lastReservation.end.date))}${translate('travel.carRental')}`;
}
default:
return '';
}
};

const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${tripRoomReport?.reportID}`);

if (!tripRoomReport) {
Expand All @@ -263,7 +226,7 @@ function TripDetailsView({tripRoomReport, shouldShowHorizontalRule, tripTransact
{reservationsData.map(({reservations, pnrID, currency, totalFareAmount}) => (
<Section
key={pnrID}
title={getTripTitle(reservations)}
title={getBookingTitle(translate, reservations)}
subtitle={getTripDescription(totalFareAmount, currency, reservations)}
containerStyles={[styles.ph0, styles.mh0, styles.mb0, shouldUseNarrowLayout ? styles.workspaceSectionMobile : styles.workspaceSection]}
titleStyles={[styles.textStrong, styles.textNormal, styles.ph5]}
Expand Down
106 changes: 101 additions & 5 deletions src/components/ReportActionItem/TripRoomPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import {PressableWithoutFeedback} from '@components/Pressable';
import {showContextMenuForReport, useShowContextMenuActions, useShowContextMenuState} from '@components/ShowContextMenuContext';
import StatusBadge from '@components/StatusBadge';
import Text from '@components/Text';

import {useCurrencyListActions} from '@hooks/useCurrencyList';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePermissions from '@hooks/usePermissions';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
Expand All @@ -20,14 +23,23 @@ import {canUseTouchScreen} from '@libs/DeviceCapabilities';
import getReportRouteForCurrentContext from '@libs/Navigation/helpers/getReportRouteForCurrentContext';
import Navigation from '@libs/Navigation/Navigation';
import {getOriginalMessage} from '@libs/ReportActionsUtils';
import type {ReservationData} from '@libs/TripReservationUtils';
import {formatCancelledDescription, getReservationsFromTripReport, getTripReservationIcon, getTripTotal} from '@libs/TripReservationUtils';
import {canApproveAnyBooking, getBookingStatusBadge} from '@libs/TravelApprovalUtils';
import type {ReservationData, ReservationPNRData} from '@libs/TripReservationUtils';
import {
formatCancelledDescription,
getBookingTitle,
getPNRReservationDataFromTripReport,
getReservationsFromTripReport,
getTripReservationIcon,
getTripTotal,
} from '@libs/TripReservationUtils';

import variables from '@styles/variables';

import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Report, ReportAction} from '@src/types/onyx';
import type {BookingApproval} from '@src/types/onyx/ReportNameValuePairs';
import type {Reservation} from '@src/types/onyx/Transaction';

import type {ListRenderItemInfo, StyleProp, ViewStyle} from 'react-native';
Expand Down Expand Up @@ -118,8 +130,66 @@ function ReservationView({reservation, onPress, isCancelled}: ReservationViewPro
);
}

type BookingViewProps = {
booking: ReservationPNRData;

/** The booking's approval state, which sets its status badge */
bookingApproval?: BookingApproval;

onPress: () => void;
};

function BookingView({booking, bookingApproval, onPress}: BookingViewProps) {
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {translate} = useLocalize();
const expensifyIcons = useMemoizedLazyExpensifyIcons(['Plane', 'PlaneCircleSlash', 'Bed', 'BedCircleSlash', 'CarWithKey', 'CarCircleSlash', 'Train', 'TrainCircleSlash', 'Luggage']);

const firstReservation = booking.reservations.at(0)?.reservation;
const isCancelled = booking.reservations.every((reservation) => reservation.isCancelled);
const statusBadge = getBookingStatusBadge(translate, theme.reportStatusBadge, bookingApproval);
const description = formatCancelledDescription(translate('iou.canceled'), firstReservation ? translate(`travel.${firstReservation.type}`) : '', isCancelled);

return (
// eslint-disable-next-line @typescript-eslint/no-deprecated -- Matches the reservation rows above; the compound MenuItem has no leaf for the trip reservation icon.
<MenuItemWithTopDescription
sentryLabel={CONST.SENTRY_LABEL.TRIP_ROOM_PREVIEW.BOOKING}
description={description}
descriptionTextStyle={[styles.textLabelSupporting, styles.lh16]}
title={getBookingTitle(translate, booking.reservations)}
titleStyle={[styles.mt1, isCancelled && styles.textSupporting]}
numberOfLinesTitle={1}
accessibilityLabel={isCancelled ? description : undefined}
secondaryIcon={getTripReservationIcon(expensifyIcons, firstReservation?.type, isCancelled)}
secondaryIconFill={theme.icon}
wrapperStyle={[styles.taskDescriptionMenuItem, styles.p0]}
shouldGreyOutWhenDisabled={false}
shouldRemoveBackground
onPress={onPress}
Comment thread
suneox marked this conversation as resolved.
Resolved
iconHeight={variables.iconSizeNormal}
iconWidth={variables.iconSizeNormal}
iconStyles={[StyleUtils.getTripReservationIconContainer(false), styles.mr3, styles.alignSelfCenter]}
isSmallAvatarSubscriptMenu
shouldShowRightComponent={!!statusBadge}
rightComponent={
!!statusBadge && (
<StatusBadge
text={statusBadge.text}
backgroundColor={statusBadge.backgroundColor}
textColor={statusBadge.textColor}
badgeStyles={styles.ml3}
/>
)
}
/>
);
}

function TripRoomPreview({action, containerStyles, isHovered = false}: TripRoomPreviewProps) {
const styles = useThemeStyles();
const {isBetaEnabled} = usePermissions();
const {accountID: currentUserAccountID} = useCurrentUserPersonalDetails();
const {translate, dateFnsLocale} = useLocalize();
const {convertToDisplayString} = useCurrencyListActions();
const {anchor: contextMenuAnchorRef, shouldDisplayContextMenu = true, originalReportID} = useShowContextMenuState();
Expand All @@ -134,7 +204,11 @@ function TripRoomPreview({action, containerStyles, isHovered = false}: TripRoomP
const chatReportID = chatReport?.reportID ?? linkedReportID;
const tripTransactions = useTripTransactions(chatReportID);

const reservationsData: ReservationData[] = getReservationsFromTripReport(chatReport, reportNameValuePairs, tripTransactions);
// With travel approval, the preview lists bookings (the unit approvers decide on) instead of flight legs
const isTravelApprovalEnabled = isBetaEnabled(CONST.BETAS.TRAVEL_APPROVAL);
const reservationsData: ReservationData[] = isTravelApprovalEnabled ? [] : getReservationsFromTripReport(chatReport, reportNameValuePairs, tripTransactions);
const bookingsData: ReservationPNRData[] = isTravelApprovalEnabled ? getPNRReservationDataFromTripReport(chatReport, reportNameValuePairs, tripTransactions) : [];
const shouldShowReview = isTravelApprovalEnabled && canApproveAnyBooking(reportNameValuePairs?.tripData, currentUserAccountID);
Comment thread
suneox marked this conversation as resolved.
Resolved
const dateInfo =
reportNameValuePairs?.tripData?.startDate && reportNameValuePairs?.tripData?.endDate
? DateUtils.getFormattedDateRange(translate, dateFnsLocale, new Date(reportNameValuePairs.tripData.startDate), new Date(reportNameValuePairs.tripData.endDate))
Expand All @@ -159,6 +233,18 @@ function TripRoomPreview({action, containerStyles, isHovered = false}: TripRoomP
/>
);

const renderBooking = ({item}: ListRenderItemInfo<ReservationPNRData>) => (
<BookingView
booking={item}
bookingApproval={reportNameValuePairs?.tripData?.bookingApprovalState?.[item.pnrID]}
onPress={navigateToTrip}
/>
);

const reservationCount = isTravelApprovalEnabled
? translate('travel.bookingCount', {count: bookingsData.length})
: `${reservationsData.length} ${(reservationsData.length < 2 ? translate('travel.trip') : translate('travel.trips')).toLowerCase()}`;

return (
<OfflineWithFeedback
pendingAction={action?.pendingAction}
Expand Down Expand Up @@ -186,7 +272,7 @@ function TripRoomPreview({action, containerStyles, isHovered = false}: TripRoomP
<View>
<Text style={[styles.headerText, styles.mb1]}>{chatReport?.reportName}</Text>
<Text style={[styles.textLabelSupporting, styles.lh16]}>
{dateInfo} • {reservationsData.length} {(reservationsData.length < 2 ? translate('travel.trip') : translate('travel.trips')).toLowerCase()}
{dateInfo} • {reservationCount}
</Text>
</View>
{reservationsData.length > 0 && (
Expand All @@ -197,16 +283,26 @@ function TripRoomPreview({action, containerStyles, isHovered = false}: TripRoomP
renderItem={renderItem}
/>
)}
{bookingsData.length > 0 && (
<FlatList
data={bookingsData}
keyExtractor={(item) => item.pnrID}
style={[styles.border, styles.borderRadiusComponentLarge, styles.p4, styles.flexGrow0]}
contentContainerStyle={styles.gap4}
renderItem={renderBooking}
/>
)}
<View style={[styles.flex1, styles.flexRow, styles.justifyContentBetween, styles.alignItemsCenter]}>
<Text style={[styles.textLabelSupporting, styles.lh16]}>{translate('common.total')}</Text>
<Text style={[styles.headerText, styles.lineHeightXLarge]}>{displayAmount}</Text>
</View>

<Button
variant={shouldShowReview ? CONST.BUTTON_VARIANT.SUCCESS : undefined}
onPress={navigateToTrip}
sentryLabel={CONST.SENTRY_LABEL.TRIP_ROOM_PREVIEW.VIEW_BUTTON}
>
<Button.Text>{translate('common.view')}</Button.Text>
<Button.Text>{shouldShowReview ? translate('common.review') : translate('common.view')}</Button.Text>
</Button>
</View>
</PressableWithoutFeedback>
Expand Down
4 changes: 4 additions & 0 deletions src/languages/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5244,6 +5244,10 @@ ${amount} für ${merchant} – ${date}`,
hardApproval: (time: string) => `Wird automatisch in ${time} storniert, wenn nicht genehmigt.`,
},
},
bookingCount: ({count}: {count: number}) => ({
one: '1 Buchung',
other: `${count} Buchungen`,
}),
},
workspace: {
common: {
Expand Down
4 changes: 4 additions & 0 deletions src/languages/el.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5308,6 +5308,10 @@ ${amount} για ${merchant} - ${date}`,
hardApproval: (time: string) => `Ακυρώνεται αυτόματα σε ${time} αν δεν εγκριθεί.`,
},
},
bookingCount: ({count}: {count: number}) => ({
one: '1 κράτηση',
other: `${count} κρατήσεις`,
}),
},
proactiveAppReview: {
title: 'Σας αρέσει το νέο Expensify;',
Expand Down
4 changes: 4 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5351,6 +5351,10 @@ const translations = {
viewTripDetails: 'View trip details',
trip: 'Trip',
trips: 'Trips',
bookingCount: ({count}: {count: number}) => ({
one: '1 booking',
other: `${count} bookings`,
}),
tripSummary: 'Trip summary',
departs: 'Departs',
errorMessage: 'Something went wrong. Please try again later.',
Expand Down
4 changes: 4 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5213,6 +5213,10 @@ ${amount} para ${merchant} - ${date}`,
hardApproval: (time: string) => `Se cancela automáticamente en ${time} si no se aprueba.`,
},
},
bookingCount: ({count}: {count: number}) => ({
one: '1 reserva',
other: `${count} reservas`,
}),
},
proactiveAppReview: {
title: '¿Te gusta New Expensify?',
Expand Down
4 changes: 4 additions & 0 deletions src/languages/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5255,6 +5255,10 @@ ${amount} pour ${merchant} - ${date}`,
hardApproval: (time: string) => `Annulation automatique dans ${time} si non approuvé.`,
},
},
bookingCount: ({count}: {count: number}) => ({
one: `${count} réservation`,
other: `${count} réservations`,
}),
},
workspace: {
common: {
Expand Down
4 changes: 4 additions & 0 deletions src/languages/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5213,6 +5213,10 @@ ${amount} per ${merchant} - ${date}`,
hardApproval: (time: string) => `Annullamento automatico tra ${time} se non approvata.`,
},
},
bookingCount: ({count}: {count: number}) => ({
one: '1 prenotazione',
other: `${count} prenotazioni`,
}),
},
workspace: {
common: {
Expand Down
4 changes: 4 additions & 0 deletions src/languages/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5164,6 +5164,10 @@ ${integrationName === CONST.ONBOARDING_ACCOUNTING_MAPPING.other ? 'あなたの'
hardApproval: (time: string) => `承認されない場合は ${time} で自動的にキャンセルされます。`,
},
},
bookingCount: ({count}: {count: number}) => ({
one: '1件の予約',
other: `${count}件の予約`,
}),
},
workspace: {
common: {
Expand Down
4 changes: 4 additions & 0 deletions src/languages/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5210,6 +5210,10 @@ ${amount} voor ${merchant} - ${date}`,
hardApproval: (time: string) => `Wordt automatisch geannuleerd over ${time} als deze niet is goedgekeurd.`,
},
},
bookingCount: ({count}: {count: number}) => ({
one: '1 boeking',
other: `${count} boekingen`,
}),
},
workspace: {
common: {
Expand Down
6 changes: 6 additions & 0 deletions src/languages/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5250,6 +5250,12 @@ ${amount} dla ${merchant} - ${date}`,
hardApproval: (time: string) => `Automatycznie anuluje się za ${time}, jeśli nie zostanie zatwierdzone.`,
},
},
bookingCount: ({count}: {count: number}) => ({
one: '1 rezerwacja',
few: `${count} rezerwacje`,
many: `${count} rezerwacji`,
other: `${count} rezerwacji`,
}),
},
workspace: {
common: {
Expand Down
4 changes: 4 additions & 0 deletions src/languages/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5216,6 +5216,10 @@ ${amount} para ${merchant} - ${date}`,
hardApproval: (time: string) => `Cancela automaticamente em ${time} se não for aprovado.`,
},
},
bookingCount: ({count}: {count: number}) => ({
one: `${count} reserva`,
other: `${count} reservas`,
}),
},
workspace: {
common: {
Expand Down
4 changes: 4 additions & 0 deletions src/languages/zh-hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5040,6 +5040,10 @@ ${amount},商户:${merchant} - 日期:${date}`,
status: {outstanding: '未结', approved: '已批准', rejected: '已拒绝', canceled: '已取消'},
deadline: {softApproval: (time: string) => `将在 ${time} 后自动批准。在此之前可免费取消。`, hardApproval: (time: string) => `若未获批准,将在 ${time} 后自动取消。`},
},
bookingCount: ({count}: {count: number}) => ({
one: '1 个预订',
other: `${count} 个预订`,
}),
},
workspace: {
common: {
Expand Down
Loading
Loading