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 50 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
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/TripDetailsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function ReservationView({reservation}: ReservationViewProps) {
onSecondaryInteraction={() => {}}
iconHeight={20}
iconWidth={20}
iconStyles={[styles.tripReservationIconContainer, styles.mr3]}
iconStyles={[styles.tripReservationIconContainer(false), styles.mr3]}
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps this style should go in StyleUtils, I don't think we use many functions in the styles file. WDYT?

secondaryIconFill={theme.icon}
hoverAndPressStyle={styles.hoveredComponentBG}
/>
Expand Down
204 changes: 204 additions & 0 deletions src/components/ReportActionItem/TripRoomPreview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
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 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 a message is a whisper */
isWhisper?: boolean;

/** 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 {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.tripReservationTitleGap}
secondaryIcon={reservationIcon}
shouldShowRightIcon={false}
Copy link
Contributor

Choose a reason for hiding this comment

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

A few of these should___ probs are false by default and are redundant / could be removed

wrapperStyle={[styles.taskDescriptionMenuItem, styles.p0]}
shouldGreyOutWhenDisabled={false}
numberOfLinesTitle={0}
interactive={false}
shouldStackHorizontally={false}
hoverAndPressStyle={false}
iconHeight={variables.iconSizeSmall}
iconWidth={variables.iconSizeSmall}
iconStyles={[styles.tripReservationIconContainer(true), styles.mr3]}
secondaryIconFill={theme.icon}
isSmallAvatarSubscriptMenu
/>
);
}

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

function TripRoomPreview({action, chatReportID, containerStyles, contextMenuAnchor, isHovered = false, isWhisper = 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 || isWhisper ? styles.reportPreviewBoxHoverBorder : undefined]}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we using the whisper pattern here? Could you show me the case for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, we don't have this case in the app, I removed that

<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;
7 changes: 6 additions & 1 deletion src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,12 @@ function shouldReportActionBeVisible(reportAction: OnyxEntry<ReportAction>, key:
// 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);

// @TODO: isTripRoomPreview condition has been added to make the TripRoomPreview component visible.
// Remove it when the reportAction.message array is not empty for this type, then !isDeleted will be true.
Copy link
Contributor

Choose a reason for hiding this comment

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

What issue will fix this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are there any conditions when TripRoomPreview should be visible and when not? If it should be always visible, I'll refactor this code and remove the comment

cc: @stitesExpensify

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that it should always be visible

const isTripRoomPreview = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.TRIPPREVIEW;

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

/**
Expand Down
4 changes: 2 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6694,9 +6694,9 @@ function shouldCreateNewMoneyRequestReport(existingIOUReport: OnyxEntry<Report>
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
15 changes: 15 additions & 0 deletions src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ 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';
import UnreadActionIndicator from '@components/UnreadActionIndicator';
import useLocalize from '@hooks/useLocalize';
import usePermissions from '@hooks/usePermissions';
import usePrevious from '@hooks/usePrevious';
import useReportScrollManager from '@hooks/useReportScrollManager';
import useStyleUtils from '@hooks/useStyleUtils';
Expand Down Expand Up @@ -200,6 +202,7 @@ function ReportActionItem({
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const personalDetails = usePersonalDetails() || CONST.EMPTY_OBJECT;
const {canUseSpotnanaTravel} = usePermissions();
const [isContextMenuActive, setIsContextMenuActive] = useState(() => ReportActionContextMenu.isActiveReportAction(action.reportActionID));
const [isEmojiPickerActive, setIsEmojiPickerActive] = useState<boolean | undefined>();

Expand Down Expand Up @@ -540,6 +543,18 @@ function ReportActionItem({
isWhisper={isWhisper}
/>
);
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.TRIPPREVIEW && canUseSpotnanaTravel) {
children = (
<TripRoomPreview
action={action}
chatReportID={action.originalMessage.linkedReportID}
isHovered={hovered}
contextMenuAnchor={popoverAnchorRef.current}
containerStyles={displayAsGroup ? [] : [styles.mt2]}
checkIfContextMenuActive={toggleContextMenuFromActiveReportAction}
isWhisper={isWhisper}
/>
);
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW) {
children = ReportUtils.isClosedExpenseReportWithNoExpenses(iouReport) ? (
<RenderHTML html={`<comment>${translate('parentReportAction.deletedReport')}</comment>`} />
Expand Down
12 changes: 8 additions & 4 deletions src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4971,13 +4971,17 @@ const styles = (theme: ThemeColors) =>
flex: 1,
},

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

tripReservationTitleGap: {
gap: 2,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you share a quick screenshot of where this is used again? I vaguely recall a quick conversation where we decided that maybe it's better to use 4.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

It's used here. You're right, it should be 4, I've adjusted it :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Sweet, thanks!

},

textLineThrough: {
Expand Down
6 changes: 6 additions & 0 deletions src/types/onyx/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ type Report = OnyxCommon.OnyxValueWithOfflineFeedback<
fieldList?: Record<string, PolicyReportField>;

permissions?: Array<ValueOf<typeof CONST.REPORT.PERMISSIONS>>;

tripData?: {
startDate: string;
endDate: string;
tripId: string;
};
},
PolicyReportField['fieldID']
>;
Expand Down
Loading