Skip to content

Commit

Permalink
Merge pull request Expensify#44086 from software-mansion-labs/trip-co…
Browse files Browse the repository at this point in the history
…rrected/trip-receipt

[Travel] Create Trip Receipt for newDot
  • Loading branch information
yuwenmemon authored Jul 3, 2024
2 parents dc2a371 + d627fdd commit 2fa1734
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/components/EReceiptThumbnail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {withOnyx} from 'react-native-onyx';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ReportUtils from '@libs/ReportUtils';
import * as TripReservationUtils from '@libs/TripReservationUtils';
import colors from '@styles/theme/colors';
import variables from '@styles/variables';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -56,7 +57,8 @@ const backgroundImages = {
function EReceiptThumbnail({transaction, borderRadius, fileExtension, isReceiptThumbnail = false, centerIconV = true, iconSize = 'large'}: EReceiptThumbnailProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const colorCode = isReceiptThumbnail ? StyleUtils.getFileExtensionColorCode(fileExtension) : StyleUtils.getEReceiptColorCode(transaction);
const {tripIcon, tripBGColor} = TripReservationUtils.getTripEReceiptData(transaction);
const colorCode = tripBGColor ?? (isReceiptThumbnail ? StyleUtils.getFileExtensionColorCode(fileExtension) : StyleUtils.getEReceiptColorCode(transaction));

const backgroundImage = useMemo(() => backgroundImages[colorCode], [colorCode]);

Expand Down Expand Up @@ -141,6 +143,14 @@ function EReceiptThumbnail({transaction, borderRadius, fileExtension, isReceiptT
fill={primaryColor}
/>
) : null}
{tripIcon ? (
<Icon
src={tripIcon}
height={receiptMCCSize}
width={receiptMCCSize}
fill={primaryColor}
/>
) : null}
</View>
</View>
</View>
Expand Down
25 changes: 24 additions & 1 deletion src/libs/TripReservationUtils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type {EReceiptColorName} from '@styles/utils/types';
import * as Expensicons from '@src/components/Icon/Expensicons';
import CONST from '@src/CONST';
import type {Reservation, ReservationType} from '@src/types/onyx/Transaction';
Expand All @@ -24,4 +25,26 @@ function getReservationsFromTripTransactions(transactions: Transaction[]): Reser
.flat();
}

export {getTripReservationIcon, getReservationsFromTripTransactions};
type TripEReceiptData = {
/** Icon asset associated with the type of trip reservation */
tripIcon?: IconAsset;

/** EReceipt background color associated with the type of trip reservation */
tripBGColor?: EReceiptColorName;
};

function getTripEReceiptData(transaction?: Transaction): TripEReceiptData {
const reservationType = transaction ? transaction.receipt?.reservationList?.[0]?.type : '';

switch (reservationType) {
case CONST.RESERVATION_TYPE.FLIGHT:
case CONST.RESERVATION_TYPE.CAR:
return {tripIcon: Expensicons.Plane, tripBGColor: CONST.ERECEIPT_COLORS.PINK};
case CONST.RESERVATION_TYPE.HOTEL:
return {tripIcon: Expensicons.Bed, tripBGColor: CONST.ERECEIPT_COLORS.YELLOW};
default:
return {};
}
}

export {getTripReservationIcon, getReservationsFromTripTransactions, getTripEReceiptData};

0 comments on commit 2fa1734

Please sign in to comment.