Skip to content

Commit 479aa6f

Browse files
committed
Use fare from tripdata payload
1 parent b44a57e commit 479aa6f

5 files changed

Lines changed: 42 additions & 12 deletions

File tree

cspell.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,6 @@
727727
"src/CONST/index.ts",
728728
"src/libs/SearchParser/*"
729729
],
730-
"ignoreRegExpList": [
731-
"@assets/.*"
732-
],
730+
"ignoreRegExpList": ["@assets/.*"],
733731
"useGitignore": true
734732
}

src/components/ReportActionItem/TripRoomPreview.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ import {convertToDisplayString} from '@libs/CurrencyUtils';
2020
import DateUtils from '@libs/DateUtils';
2121
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
2222
import Navigation from '@libs/Navigation/Navigation';
23-
import {getMoneyRequestSpendBreakdown} from '@libs/ReportUtils';
2423
import type {ReservationData} from '@libs/TripReservationUtils';
25-
import {getReservationsFromTripReport, getTripReservationIcon} from '@libs/TripReservationUtils';
24+
import {getReservationsFromTripReport, getTripReservationIcon, getTripTotal} from '@libs/TripReservationUtils';
2625
import type {ContextMenuAnchor} from '@pages/home/report/ContextMenu/ReportActionContextMenu';
2726
import variables from '@styles/variables';
2827
import * as Expensicons from '@src/components/Icon/Expensicons';
@@ -159,9 +158,10 @@ function TripRoomPreview({
159158
chatReport?.tripData?.startDate && chatReport?.tripData?.endDate
160159
? DateUtils.getFormattedDateRange(new Date(chatReport.tripData.startDate), new Date(chatReport.tripData.endDate))
161160
: '';
162-
const {totalDisplaySpend} = getMoneyRequestSpendBreakdown(chatReport);
161+
const reportCurrency = iouReport?.currency ?? chatReport?.currency;
162+
163+
const {totalDisplaySpend = 0, currency = reportCurrency} = chatReport ? getTripTotal(chatReport) : {};
163164

164-
const currency = iouReport?.currency ?? chatReport?.currency;
165165
const displayAmount = useMemo(() => {
166166
if (totalDisplaySpend) {
167167
return convertToDisplayString(totalDisplaySpend, currency);
@@ -181,6 +181,7 @@ function TripRoomPreview({
181181
/>
182182
);
183183

184+
console.debug('displayAmount', totalDisplaySpend, displayAmount);
184185
return (
185186
<OfflineWithFeedback
186187
pendingAction={action?.pendingAction}

src/libs/TripReservationUtils.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {Reservation, ReservationType} from '@src/types/onyx/Transaction';
66
import type Transaction from '@src/types/onyx/Transaction';
77
import type {AirPnr, CarPnr, HotelPnr, Pnr, PnrData, PnrTraveler, RailPnr, TripData} from '@src/types/onyx/TripData';
88
import type IconAsset from '@src/types/utils/IconAsset';
9+
import {getMoneyRequestSpendBreakdown} from './ReportUtils';
910

1011
function getTripReservationIcon(reservationType?: ReservationType): IconAsset {
1112
switch (reservationType) {
@@ -419,5 +420,19 @@ function getReservationsFromTripReport(tripReport?: Report, transactions?: Trans
419420
return [];
420421
}
421422

422-
export {getTripReservationIcon, getTripEReceiptIcon, getTripReservationCode, getReservationsFromTripReport};
423+
function getTripTotal(tripReport: Report): {
424+
totalDisplaySpend: number;
425+
currency?: string;
426+
} {
427+
if (tripReport?.tripData?.payload) {
428+
return {
429+
totalDisplaySpend: tripReport.tripData.payload.tripPaymentInfo.totalFare.amount * 100,
430+
currency: tripReport.tripData.payload.tripPaymentInfo.totalFare.currencyCode,
431+
};
432+
}
433+
434+
return getMoneyRequestSpendBreakdown(tripReport);
435+
}
436+
437+
export {getTripReservationIcon, getTripEReceiptIcon, getTripReservationCode, getReservationsFromTripReport, getTripTotal};
423438
export type {ReservationData};

src/pages/home/report/TripSummary.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {useOnyx} from 'react-native-onyx';
33
import OfflineWithFeedback from '@components/OfflineWithFeedback';
44
import TripDetailsView from '@components/ReportActionItem/TripDetailsView';
55
import useTripTransactions from '@hooks/useTripTransactions';
6-
import CONST from '@src/CONST';
76
import ONYXKEYS from '@src/ONYXKEYS';
87

98
type TripSummaryProps = {

src/types/onyx/TripData.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22
type TripData = {
33
/** List of Passenger Name Records (PNRs) associated with the trip. */
44
pnrs: Pnr[];
5+
/**
6+
* Information about the payment for the trip, including the total fare.
7+
*/
8+
tripPaymentInfo: {
9+
/**
10+
* The total fare for the trip, including the amount and currency code.
11+
*/
12+
totalFare: {
13+
/**
14+
* The monetary amount of the total fare.
15+
*/
16+
amount: number;
17+
18+
/**
19+
* The currency code for the total fare (e.g., USD, EUR).
20+
*/
21+
currencyCode: string;
22+
};
23+
};
524
};
625

726
/** Represents a Passenger Name Record (PNR). */
@@ -533,8 +552,6 @@ type AirPnr = {
533552
number: number;
534553
}>;
535554
};
536-
/** Created MCOs for the traveler. */
537-
createdMcos: unknown[];
538555
/** Passenger type for the traveler. */
539556
paxType: string;
540557
/** Special service request information for the traveler. */
@@ -1643,7 +1660,7 @@ type CarPnr = {
16431660

16441661
/** Rebook reference information for the car booking. */
16451662
rebookReference: {
1646-
/** List of cancelled PNR IDs for rebooking. */
1663+
/** List of cancelled PNR IDs for re-booking. */
16471664
cancelledPnrIds: Array<Record<string, unknown>>;
16481665

16491666
/** Rebooked PNR ID. */

0 commit comments

Comments
 (0)