-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
grgia
merged 67 commits into
Expensify:main
from
software-mansion-labs:travel/trip-room-preview
Jun 18, 2024
Merged
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 370d8a8
Add template of ReservationRow component
WojtekBoman 102ffb8
Add car to ReservationType, add utility functions for trip transactions
WojtekBoman 489720b
Merge branch 'main' into travel/trip-room-preview
WojtekBoman 5d16a01
Refactor TripRoomPreview styles
WojtekBoman 7036238
Get reservations from trip transactions
WojtekBoman 20caa2f
Merge branch 'main' into travel/trip-room-preview
WojtekBoman b8b20ee
Handle showing context menu in TripRoomPreview
WojtekBoman a9c5370
Add OriginalMessageTripRoomPreview type
WojtekBoman b4b3730
Add type TripDetails
WojtekBoman 71419d4
Add getFormattedDateRange method to DateUtils
WojtekBoman 8b25ebc
Merge branch 'main' into travel/trip-room-preview
WojtekBoman 18c8503
Handle new reservation types, add ui fixes, add docs
WojtekBoman 9eb79a2
Add canUseSpotnanaTravel
WojtekBoman 56e19f7
Merge branch 'main' into travel/trip-room-preview
WojtekBoman 993f684
Add TripReservationUtils
WojtekBoman f88bec0
Use MenuItemWithTopDescription to display reservations
WojtekBoman 3cbb84c
Merge branch 'main' into travel/trip-room-preview
WojtekBoman c53d977
Remove luggage with lines icon
WojtekBoman f8d3f34
Adjust MenuItem to display titleComponent
WojtekBoman e8390c5
Use translateLocal in getFormattedDateRange
WojtekBoman 6eef035
Add fixes to TripRoomPreview
WojtekBoman 01a7e2d
Refactor getDisplayAmount in TripRoomPreview
WojtekBoman 3a85f3d
Merge branch 'main' into travel/trip-room-preview
WojtekBoman 05a7613
Merge branch 'main' into travel/trip-room-preview
WojtekBoman fd6418c
Add template of SpotnanaPayload type
WojtekBoman 8219de2
Merge branch 'main' into travel/trip-room-preview
WojtekBoman 3262a35
Merge branch 'main' into travel/trip-room-preview
WojtekBoman 5e1d9b9
Fix trip types
WojtekBoman 658d003
Refactor TripRoomPreview
WojtekBoman 1776dcc
Add docs and fix ts
WojtekBoman 70204a0
Add comment to TripRoomPreview
WojtekBoman 4720a06
Refactor displaying total amount in TripRoomPreview
WojtekBoman cc1a8e3
Refactor displaying total amount in TripRoomPreview
WojtekBoman d753bb4
Refactor tripReservationIconContainer style
WojtekBoman faeadcc
Remove textSupportingSmallSize style
WojtekBoman ca0b2e7
Remove styles.lh14
WojtekBoman bfc8b82
Merge branch 'main' into travel/trip-room-preview
WojtekBoman 19ce931
Merge branch 'main' into travel/trip-room-preview
WojtekBoman af036c8
Fix trip translations
WojtekBoman 545b1d8
Adjust TripRoomPreview
WojtekBoman 24e9d8f
Remove train.svg
WojtekBoman ad04386
Cleanup CONST.ts
WojtekBoman deeb5c1
Refactor export order in Transaction.ts
WojtekBoman 7ea02b9
Remove duplicated OriginalMessageDismissedViolation
WojtekBoman 9cbffe5
Merge branch 'main' into travel/trip-room-preview
WojtekBoman 9b12b07
Merge branch 'main' into travel/trip-room-preview
WojtekBoman bc12893
Replace withOnyx with useOnyx in TripRoomPreview
WojtekBoman cddd0ae
Merge branch 'main' into travel/trip-room-preview
WojtekBoman 6c6078b
Remove textSupportingNormalSize style
WojtekBoman 109530a
Remove tripReservationTitleGap style
WojtekBoman 6b81aa4
Merge branch 'main' into travel/trip-room-preview
WojtekBoman 2ca5697
Merge branch 'main' into travel/trip-room-preview
WojtekBoman 9259a3a
Hide copy to clipboard option for trip preview
WojtekBoman 26230ca
Add missing docs to Report.ts
WojtekBoman d5c0016
Remove shouldUseNarrowLayout && styles.flex1 from flight text in Trip…
WojtekBoman 89ed40b
Fix lint in TripDetailsView
WojtekBoman 7f88ab2
Revert style changes in TripDetailsView
WojtekBoman d723732
Merge branch 'main' into travel/trip-room-preview
WojtekBoman fad5159
Remove isWhisper prop from TripRoomPreview
WojtekBoman 7e89f2d
Move tripReservationIconContainer to StyleUtils
WojtekBoman 6ed35e5
Fix lint
WojtekBoman 89c4d18
Merge branch 'main' into travel/trip-room-preview
WojtekBoman 7118a42
Remove checking beta to display TripRoomPreview
WojtekBoman 4b60448
Merge branch 'main' into travel/trip-room-preview
WojtekBoman 42b5f3f
Add isTripPreview check in shouldReportActionBeVisible
WojtekBoman 46f7bbe
Merge branch 'main' into travel/trip-room-preview
WojtekBoman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`)} | ||
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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