Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Travel] Create Trip Receipt for newDot #44086

Merged
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};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to remove tripBGColor and calculate the color combos using the same methods in https://github.com/Expensify/App/blob/main/src/components/EReceipt.tsx#L35-L36

case CONST.RESERVATION_TYPE.HOTEL:
return {tripIcon: Expensicons.Bed, tripBGColor: CONST.ERECEIPT_COLORS.YELLOW};
default:
return {};
}
}

export {getTripReservationIcon, getReservationsFromTripTransactions, getTripEReceiptData};
Loading