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

[VIP-Travel] Create Trip Room Preview #38808

Merged
merged 67 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
1279f0f
Initial config for TripRoomPreview
WojtekBoman Mar 11, 2024
370d8a8
Add template of ReservationRow component
WojtekBoman Mar 12, 2024
102ffb8
Add car to ReservationType, add utility functions for trip transactions
WojtekBoman Mar 12, 2024
489720b
Merge branch 'main' into travel/trip-room-preview
WojtekBoman Mar 19, 2024
5d16a01
Refactor TripRoomPreview styles
WojtekBoman Mar 19, 2024
7036238
Get reservations from trip transactions
WojtekBoman Mar 19, 2024
20caa2f
Merge branch 'main' into travel/trip-room-preview
WojtekBoman Mar 21, 2024
b8b20ee
Handle showing context menu in TripRoomPreview
WojtekBoman Mar 21, 2024
a9c5370
Add OriginalMessageTripRoomPreview type
WojtekBoman Mar 21, 2024
b4b3730
Add type TripDetails
WojtekBoman Mar 21, 2024
71419d4
Add getFormattedDateRange method to DateUtils
WojtekBoman Mar 22, 2024
8b25ebc
Merge branch 'main' into travel/trip-room-preview
WojtekBoman Mar 22, 2024
18c8503
Handle new reservation types, add ui fixes, add docs
WojtekBoman Mar 22, 2024
9eb79a2
Add canUseSpotnanaTravel
WojtekBoman Mar 22, 2024
56e19f7
Merge branch 'main' into travel/trip-room-preview
WojtekBoman Mar 25, 2024
993f684
Add TripReservationUtils
WojtekBoman Mar 25, 2024
f88bec0
Use MenuItemWithTopDescription to display reservations
WojtekBoman Mar 25, 2024
3cbb84c
Merge branch 'main' into travel/trip-room-preview
WojtekBoman Mar 26, 2024
c53d977
Remove luggage with lines icon
WojtekBoman Mar 26, 2024
f8d3f34
Adjust MenuItem to display titleComponent
WojtekBoman Mar 26, 2024
e8390c5
Use translateLocal in getFormattedDateRange
WojtekBoman Mar 26, 2024
6eef035
Add fixes to TripRoomPreview
WojtekBoman Mar 29, 2024
01a7e2d
Refactor getDisplayAmount in TripRoomPreview
WojtekBoman Mar 29, 2024
3a85f3d
Merge branch 'main' into travel/trip-room-preview
WojtekBoman Mar 29, 2024
05a7613
Merge branch 'main' into travel/trip-room-preview
WojtekBoman Apr 25, 2024
fd6418c
Add template of SpotnanaPayload type
WojtekBoman Apr 26, 2024
8219de2
Merge branch 'main' into travel/trip-room-preview
WojtekBoman Apr 30, 2024
3262a35
Merge branch 'main' into travel/trip-room-preview
WojtekBoman May 29, 2024
5e1d9b9
Fix trip types
WojtekBoman May 29, 2024
658d003
Refactor TripRoomPreview
WojtekBoman May 29, 2024
1776dcc
Add docs and fix ts
WojtekBoman May 29, 2024
70204a0
Add comment to TripRoomPreview
WojtekBoman May 29, 2024
4720a06
Refactor displaying total amount in TripRoomPreview
WojtekBoman May 29, 2024
cc1a8e3
Refactor displaying total amount in TripRoomPreview
WojtekBoman May 29, 2024
d753bb4
Refactor tripReservationIconContainer style
WojtekBoman Jun 3, 2024
faeadcc
Remove textSupportingSmallSize style
WojtekBoman Jun 3, 2024
ca0b2e7
Remove styles.lh14
WojtekBoman Jun 3, 2024
bfc8b82
Merge branch 'main' into travel/trip-room-preview
WojtekBoman Jun 5, 2024
19ce931
Merge branch 'main' into travel/trip-room-preview
WojtekBoman Jun 5, 2024
af036c8
Fix trip translations
WojtekBoman Jun 5, 2024
545b1d8
Adjust TripRoomPreview
WojtekBoman Jun 5, 2024
24e9d8f
Remove train.svg
WojtekBoman Jun 5, 2024
ad04386
Cleanup CONST.ts
WojtekBoman Jun 5, 2024
deeb5c1
Refactor export order in Transaction.ts
WojtekBoman Jun 5, 2024
7ea02b9
Remove duplicated OriginalMessageDismissedViolation
WojtekBoman Jun 5, 2024
9cbffe5
Merge branch 'main' into travel/trip-room-preview
WojtekBoman Jun 6, 2024
9b12b07
Merge branch 'main' into travel/trip-room-preview
WojtekBoman Jun 7, 2024
bc12893
Replace withOnyx with useOnyx in TripRoomPreview
WojtekBoman Jun 7, 2024
cddd0ae
Merge branch 'main' into travel/trip-room-preview
WojtekBoman Jun 7, 2024
6c6078b
Remove textSupportingNormalSize style
WojtekBoman Jun 7, 2024
109530a
Remove tripReservationTitleGap style
WojtekBoman Jun 7, 2024
6b81aa4
Merge branch 'main' into travel/trip-room-preview
WojtekBoman Jun 10, 2024
2ca5697
Merge branch 'main' into travel/trip-room-preview
WojtekBoman Jun 11, 2024
9259a3a
Hide copy to clipboard option for trip preview
WojtekBoman Jun 11, 2024
26230ca
Add missing docs to Report.ts
WojtekBoman Jun 11, 2024
d5c0016
Remove shouldUseNarrowLayout && styles.flex1 from flight text in Trip…
WojtekBoman Jun 11, 2024
89ed40b
Fix lint in TripDetailsView
WojtekBoman Jun 11, 2024
7f88ab2
Revert style changes in TripDetailsView
WojtekBoman Jun 11, 2024
d723732
Merge branch 'main' into travel/trip-room-preview
WojtekBoman Jun 13, 2024
fad5159
Remove isWhisper prop from TripRoomPreview
WojtekBoman Jun 13, 2024
7e89f2d
Move tripReservationIconContainer to StyleUtils
WojtekBoman Jun 13, 2024
6ed35e5
Fix lint
WojtekBoman Jun 13, 2024
89c4d18
Merge branch 'main' into travel/trip-room-preview
WojtekBoman Jun 13, 2024
7118a42
Remove checking beta to display TripRoomPreview
WojtekBoman Jun 13, 2024
4b60448
Merge branch 'main' into travel/trip-room-preview
WojtekBoman Jun 14, 2024
42b5f3f
Add isTripPreview check in shouldReportActionBeVisible
WojtekBoman Jun 14, 2024
46f7bbe
Merge branch 'main' into travel/trip-room-preview
WojtekBoman Jun 18, 2024
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
4 changes: 3 additions & 1 deletion src/components/ReportActionItem/TripDetailsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import SpacerView from '@components/SpacerView';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import DateUtils from '@libs/DateUtils';
Expand All @@ -32,6 +33,7 @@ type ReservationViewProps = {
function ReservationView({reservation}: ReservationViewProps) {
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {shouldUseNarrowLayout} = useResponsiveLayout();

const reservationIcon = TripReservationUtils.getTripReservationIcon(reservation.type);
Expand Down Expand Up @@ -125,7 +127,7 @@ function ReservationView({reservation}: ReservationViewProps) {
onSecondaryInteraction={() => {}}
iconHeight={20}
iconWidth={20}
iconStyles={[styles.tripReservationIconContainer, styles.mr3]}
iconStyles={[StyleUtils.getTripReservationIconContainer(false), styles.mr3]}
secondaryIconFill={theme.icon}
hoverAndPressStyle={styles.hoveredComponentBG}
/>
Expand Down
200 changes: 200 additions & 0 deletions src/components/ReportActionItem/TripRoomPreview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
import React, {useMemo} from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import {FlatList, View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import Button from '@components/Button';
import Icon from '@components/Icon';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import {PressableWithoutFeedback} from '@components/Pressable';
import {showContextMenuForReport} from '@components/ShowContextMenuContext';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import ControlSelection from '@libs/ControlSelection';
import * as CurrencyUtils from '@libs/CurrencyUtils';
import DateUtils from '@libs/DateUtils';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import Navigation from '@libs/Navigation/Navigation';
import * as ReportUtils from '@libs/ReportUtils';
import * as TripReservationUtils from '@libs/TripReservationUtils';
import type {ContextMenuAnchor} from '@pages/home/report/ContextMenu/ReportActionContextMenu';
import variables from '@styles/variables';
import * as Expensicons from '@src/components/Icon/Expensicons';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {ReportAction} from '@src/types/onyx';
import type {Reservation} from '@src/types/onyx/Transaction';

type TripRoomPreviewProps = {
/** All the data of the action */
action: ReportAction;

/** The associated chatReport */
chatReportID: string;

/** Extra styles to pass to View wrapper */
containerStyles?: StyleProp<ViewStyle>;

/** Popover context menu anchor, used for showing context menu */
contextMenuAnchor?: ContextMenuAnchor;

/** Callback for updating context menu active state, used for showing context menu */
checkIfContextMenuActive?: () => void;

/** Whether the corresponding report action item is hovered */
isHovered?: boolean;
};

type ReservationViewProps = {
reservation: Reservation;
};

function ReservationView({reservation}: ReservationViewProps) {
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {translate} = useLocalize();

const reservationIcon = TripReservationUtils.getTripReservationIcon(reservation.type);
const title = reservation.type === CONST.RESERVATION_TYPE.CAR ? reservation.carInfo?.name : reservation.start.longName;

const titleComponent =
reservation.type === CONST.RESERVATION_TYPE.FLIGHT ? (
<View style={[styles.flexRow, styles.alignItemsCenter, styles.gap2]}>
<Text style={styles.labelStrong}>{reservation.start.shortName}</Text>
<Icon
src={Expensicons.ArrowRightLong}
width={variables.iconSizeSmall}
height={variables.iconSizeSmall}
fill={theme.icon}
/>
<Text style={styles.labelStrong}>{reservation.end.shortName}</Text>
</View>
) : (
<Text
numberOfLines={1}
style={styles.labelStrong}
>
{title}
</Text>
);

return (
<MenuItemWithTopDescription
description={translate(`travel.${reservation.type}`)}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a default here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

type is a mandatory field in the reservation, I am not sure if it's necessary to provide here a default value

descriptionTextStyle={styles.textMicro}
titleComponent={titleComponent}
titleContainerStyle={styles.gap1}
secondaryIcon={reservationIcon}
secondaryIconFill={theme.icon}
wrapperStyle={[styles.taskDescriptionMenuItem, styles.p0]}
shouldGreyOutWhenDisabled={false}
numberOfLinesTitle={0}
interactive={false}
iconHeight={variables.iconSizeSmall}
iconWidth={variables.iconSizeSmall}
iconStyles={[StyleUtils.getTripReservationIconContainer(true), styles.mr3]}
isSmallAvatarSubscriptMenu
/>
);
}

const renderItem = ({item}: {item: Reservation}) => <ReservationView reservation={item} />;

function TripRoomPreview({action, chatReportID, containerStyles, contextMenuAnchor, isHovered = false, checkIfContextMenuActive = () => {}}: TripRoomPreviewProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`);
const [iouReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${chatReport?.iouReportID}`);

const tripTransactions = ReportUtils.getTripTransactions(chatReport?.iouReportID, 'reportID');
const reservations: Reservation[] = TripReservationUtils.getReservationsFromTripTransactions(tripTransactions);
const dateInfo = chatReport?.tripData ? DateUtils.getFormattedDateRange(new Date(chatReport.tripData.startDate), new Date(chatReport.tripData.endDate)) : '';
const {totalDisplaySpend} = ReportUtils.getMoneyRequestSpendBreakdown(chatReport);

const displayAmount = useMemo(() => {
if (totalDisplaySpend) {
return CurrencyUtils.convertToDisplayString(totalDisplaySpend, iouReport?.currency);
}

// If iouReport is not available, get amount from the action message (Ex: "Domain20821's Workspace owes $33.00" or "paid ₫60" or "paid -₫60 elsewhere")
let displayAmountValue = '';
const actionMessage = action.message?.[0]?.text ?? '';
const splits = actionMessage.split(' ');

splits.forEach((split) => {
if (!/\d/.test(split)) {
return;
}

displayAmountValue = split;
});

return displayAmountValue;
}, [action.message, iouReport?.currency, totalDisplaySpend]);

return (
<OfflineWithFeedback
pendingAction={action?.pendingAction}
shouldDisableOpacity={!!(action.pendingAction ?? action.isOptimisticAction)}
needsOffscreenAlphaCompositing
>
<View style={[styles.chatItemMessage, containerStyles]}>
<PressableWithoutFeedback
onPressIn={() => DeviceCapabilities.canUseTouchScreen() && ControlSelection.block()}
onPressOut={() => ControlSelection.unblock()}
onLongPress={(event) => showContextMenuForReport(event, contextMenuAnchor, chatReportID, action, checkIfContextMenuActive)}
shouldUseHapticsOnLongPress
style={[styles.flexRow, styles.justifyContentBetween, styles.reportPreviewBox, styles.cursorDefault]}
role={CONST.ROLE.BUTTON}
accessibilityLabel={translate('iou.viewDetails')}
>
<View style={[styles.moneyRequestPreviewBox, styles.p4, styles.gap5, isHovered ? styles.reportPreviewBoxHoverBorder : undefined]}>
<View style={styles.expenseAndReportPreviewTextContainer}>
<View style={styles.reportPreviewAmountSubtitleContainer}>
<View style={styles.flexRow}>
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter]}>
<Text style={[styles.textLabelSupporting, styles.lh16]}>
{translate('travel.trip')} • {dateInfo}
</Text>
</View>
</View>
</View>
<View style={styles.reportPreviewAmountSubtitleContainer}>
<View style={styles.flexRow}>
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter]}>
<Text style={styles.textHeadlineH2}>{displayAmount}</Text>
</View>
</View>
<View style={styles.flexRow}>
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter]}>
<Text style={[styles.textLabelSupporting, styles.textNormal, styles.lh20]}>{chatReport?.reportName}</Text>
</View>
</View>
</View>
</View>
<FlatList
data={reservations}
style={styles.gap3}
renderItem={renderItem}
/>
<Button
medium
success
text={translate('travel.viewTrip')}
onPress={() => Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(chatReportID))}
/>
</View>
</PressableWithoutFeedback>
</View>
</OfflineWithFeedback>
);
}

TripRoomPreview.displayName = 'TripRoomPreview';

export default TripRoomPreview;
13 changes: 13 additions & 0 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,14 @@ function shouldReportActionBeVisible(reportAction: OnyxEntry<ReportAction>, key:
return false;
}

if (isTripPreview(reportAction)) {
return true;
}

// All other actions are displayed except thread parents, deleted, or non-pending actions
const isDeleted = isDeletedAction(reportAction);
const isPending = !!reportAction.pendingAction;

return !isDeleted || isPending || isDeletedParentAction(reportAction) || isReversedTransaction(reportAction);
}

Expand Down Expand Up @@ -1239,6 +1244,13 @@ function wasActionTakenByCurrentUser(reportAction: OnyxInputOrEntry<ReportAction
return currentUserAccountID === reportAction?.actorAccountID;
}

/**
* Check if the report action is the trip preview
*/
function isTripPreview(reportAction: OnyxEntry<ReportAction>): boolean {
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.TRIPPREVIEW;
}

export {
extractLinksFromMessageHtml,
getDismissedViolationMessageText,
Expand Down Expand Up @@ -1309,6 +1321,7 @@ export {
isLinkedTransactionHeld,
wasActionTakenByCurrentUser,
isResolvedActionTrackExpense,
isTripPreview,
};

export type {LastVisibleMessage};
4 changes: 2 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6772,9 +6772,9 @@ function shouldCreateNewMoneyRequestReport(existingIOUReport: OnyxInputOrEntry<R
return !existingIOUReport || hasIOUWaitingOnCurrentUserBankAccount(chatReport) || !canAddOrDeleteTransactions(existingIOUReport);
}

function getTripTransactions(tripRoomReportID: string | undefined): Transaction[] {
function getTripTransactions(tripRoomReportID: string | undefined, reportFieldToCompare: 'parentReportID' | 'reportID' = 'parentReportID'): Transaction[] {
const tripTransactionReportIDs = Object.values(allReports ?? {})
.filter((report) => report && report?.parentReportID === tripRoomReportID)
.filter((report) => report && report?.[reportFieldToCompare] === tripRoomReportID)
.map((report) => report?.reportID);
return tripTransactionReportIDs.flatMap((reportID) => TransactionUtils.getAllReportTransactions(reportID));
}
Expand Down
5 changes: 4 additions & 1 deletion src/pages/home/report/ContextMenu/ContextMenuActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,10 @@ const ContextMenuActions: ContextMenuAction[] = [
successTextTranslateKey: 'reportActionContextMenu.copied',
successIcon: Expensicons.Checkmark,
shouldShow: (type, reportAction) =>
type === CONST.CONTEXT_MENU_TYPES.REPORT_ACTION && !ReportActionsUtils.isReportActionAttachment(reportAction) && !ReportActionsUtils.isMessageDeleted(reportAction),
type === CONST.CONTEXT_MENU_TYPES.REPORT_ACTION &&
!ReportActionsUtils.isReportActionAttachment(reportAction) &&
!ReportActionsUtils.isMessageDeleted(reportAction) &&
!ReportActionsUtils.isTripPreview(reportAction),

// If return value is true, we switch the `text` and `icon` on
// `ContextMenuItem` with `successText` and `successIcon` which will fall back to
Expand Down
12 changes: 12 additions & 0 deletions src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import TaskAction from '@components/ReportActionItem/TaskAction';
import TaskPreview from '@components/ReportActionItem/TaskPreview';
import TaskView from '@components/ReportActionItem/TaskView';
import TripDetailsView from '@components/ReportActionItem/TripDetailsView';
import TripRoomPreview from '@components/ReportActionItem/TripRoomPreview';
import {ShowContextMenuContext} from '@components/ShowContextMenuContext';
import SpacerView from '@components/SpacerView';
import Text from '@components/Text';
Expand Down Expand Up @@ -541,6 +542,17 @@ function ReportActionItem({
isWhisper={isWhisper}
/>
);
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.TRIPPREVIEW) {
children = (
<TripRoomPreview
action={action}
chatReportID={action.originalMessage.linkedReportID}
isHovered={hovered}
contextMenuAnchor={popoverAnchorRef.current}
containerStyles={displayAsGroup ? [] : [styles.mt2]}
checkIfContextMenuActive={toggleContextMenuFromActiveReportAction}
/>
);
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW) {
children = ReportUtils.isClosedExpenseReportWithNoExpenses(iouReport) ? (
<RenderHTML html={`<comment>${translate('parentReportAction.deletedReport')}</comment>`} />
Expand Down
9 changes: 0 additions & 9 deletions src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4995,15 +4995,6 @@ const styles = (theme: ThemeColors) =>
flex: 1,
},

tripReservationIconContainer: {
width: variables.avatarSizeNormal,
height: variables.avatarSizeNormal,
backgroundColor: theme.border,
borderRadius: variables.componentBorderRadiusXLarge,
alignItems: 'center',
justifyContent: 'center',
},

textLineThrough: {
textDecorationLine: 'line-through',
},
Expand Down
9 changes: 9 additions & 0 deletions src/styles/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1684,6 +1684,15 @@ const createStyleUtils = (theme: ThemeColors, styles: ThemeStyles) => ({
...StyleSheet.flatten(descriptionTextStyle),
opacity: styles.opacitySemiTransparent.opacity,
}),

getTripReservationIconContainer: (isSmallIcon: boolean): StyleProp<ViewStyle> => ({
width: isSmallIcon ? variables.avatarSizeSmallNormal : variables.avatarSizeNormal,
height: isSmallIcon ? variables.avatarSizeSmallNormal : variables.avatarSizeNormal,
borderRadius: isSmallIcon ? variables.avatarSizeSmallNormal : variables.componentBorderRadiusXLarge,
backgroundColor: theme.border,
alignItems: 'center',
justifyContent: 'center',
}),
});

type StyleUtilsType = ReturnType<typeof createStyleUtils>;
Expand Down
Loading