Skip to content

Commit

Permalink
Merge pull request #39243 from FitseTLT/fix-distance-request-thumbnai…
Browse files Browse the repository at this point in the history
…l-mismatch

Fix - Distance request thumbnail is different in reports preview when created offline
  • Loading branch information
neil-marcellini authored Jun 6, 2024
2 parents df50d7d + b288702 commit d7e1ecf
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 54 deletions.
19 changes: 18 additions & 1 deletion assets/images/emptystate__routepending.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 7 additions & 3 deletions src/components/BlockingViews/BlockingView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {ImageContentFit} from 'expo-image';
import React, {useMemo} from 'react';
import type {ImageSourcePropType, StyleProp, ViewStyle, WebStyle} from 'react-native';
import type {ImageSourcePropType, StyleProp, TextStyle, ViewStyle, WebStyle} from 'react-native';
import {View} from 'react-native';
import type {SvgProps} from 'react-native-svg';
import type {MergeExclusive} from 'type-fest';
Expand All @@ -23,6 +23,9 @@ type BaseBlockingViewProps = {
/** Subtitle message below the title */
subtitle?: string;

/** The style of the subtitle message */
subtitleStyle?: StyleProp<TextStyle>;

/** Link message below the subtitle */
linkKey?: TranslationPaths;

Expand Down Expand Up @@ -79,6 +82,7 @@ function BlockingView({
iconColor,
title,
subtitle = '',
subtitleStyle,
linkKey = 'notFound.goBackHome',
shouldShowLink = false,
iconWidth = variables.iconSizeSuperLarge,
Expand All @@ -98,7 +102,7 @@ function BlockingView({
() => (
<>
<AutoEmailLink
style={[styles.textAlignCenter]}
style={[styles.textAlignCenter, subtitleStyle]}
text={subtitle}
/>
{shouldShowLink ? (
Expand All @@ -111,7 +115,7 @@ function BlockingView({
) : null}
</>
),
[styles, subtitle, shouldShowLink, linkKey, onLinkPress, translate],
[styles, subtitle, shouldShowLink, linkKey, onLinkPress, translate, subtitleStyle],
);

const subtitleContent = useMemo(() => {
Expand Down
25 changes: 21 additions & 4 deletions src/components/ConfirmedRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {ReactNode} from 'react';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import useNetwork from '@hooks/useNetwork';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import * as TransactionUtils from '@libs/TransactionUtils';
Expand All @@ -27,17 +28,28 @@ type ConfirmedRouteProps = ConfirmedRoutePropsOnyxProps & {
/** Transaction that stores the distance expense data */
transaction: OnyxEntry<Transaction>;

/** Whether the size of the route pending icon is smaller. */
isSmallerIcon?: boolean;

/** Whether it should have border radius */
shouldHaveBorderRadius?: boolean;

/** Whether it should display the Mapbox map only when the route/coordinates exist otherwise
* it will display pending map icon */
requireRouteToDisplayMap?: boolean;

/** Whether the map is interactable or not */
interactive?: boolean;
};

function ConfirmedRoute({mapboxAccessToken, transaction, interactive}: ConfirmedRouteProps) {
function ConfirmedRoute({mapboxAccessToken, transaction, isSmallerIcon, shouldHaveBorderRadius = true, requireRouteToDisplayMap = false, interactive}: ConfirmedRouteProps) {
const {isOffline} = useNetwork();
const {route0: route} = transaction?.routes ?? {};
const waypoints = transaction?.comment?.waypoints ?? {};
const coordinates = route?.geometry?.coordinates ?? [];
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();

const getMarkerComponent = useCallback(
(icon: IconAsset): ReactNode => (
Expand Down Expand Up @@ -90,7 +102,9 @@ function ConfirmedRoute({mapboxAccessToken, transaction, interactive}: Confirmed
return MapboxToken.stop;
}, []);

return !isOffline && Boolean(mapboxAccessToken?.token) ? (
const shouldDisplayMap = !requireRouteToDisplayMap || !!coordinates.length;

return !isOffline && Boolean(mapboxAccessToken?.token) && shouldDisplayMap ? (
<DistanceMapView
interactive={interactive}
accessToken={mapboxAccessToken?.token ?? ''}
Expand All @@ -101,12 +115,15 @@ function ConfirmedRoute({mapboxAccessToken, transaction, interactive}: Confirmed
location: waypointMarkers?.[0]?.coordinate ?? (CONST.MAPBOX.DEFAULT_COORDINATE as [number, number]),
}}
directionCoordinates={coordinates as Array<[number, number]>}
style={[styles.mapView, styles.br4]}
style={[styles.mapView, shouldHaveBorderRadius && styles.br4]}
waypoints={waypointMarkers}
styleURL={CONST.MAPBOX.STYLE_URL}
/>
) : (
<PendingMapView />
<PendingMapView
isSmallerIcon={isSmallerIcon}
style={!shouldHaveBorderRadius && StyleUtils.getBorderRadiusStyle(0)}
/>
);
}

Expand Down
3 changes: 3 additions & 0 deletions src/components/DistanceMapView/index.android.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as Expensicons from '@components/Icon/Expensicons';
import MapView from '@components/MapView';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import type DistanceMapViewProps from './types';

Expand All @@ -13,6 +14,7 @@ function DistanceMapView({overlayStyle, ...rest}: DistanceMapViewProps) {
const [isMapReady, setIsMapReady] = useState(false);
const {isOffline} = useNetwork();
const {translate} = useLocalize();
const theme = useTheme();

return (
<>
Expand All @@ -33,6 +35,7 @@ function DistanceMapView({overlayStyle, ...rest}: DistanceMapViewProps) {
title={translate('distance.mapPending.title')}
subtitle={isOffline ? translate('distance.mapPending.subtitle') : translate('distance.mapPending.onlineSubtitle')}
shouldShowLink={false}
iconColor={theme.border}
/>
</View>
)}
Expand Down
3 changes: 3 additions & 0 deletions src/components/MapView/MapViewTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type PendingMapViewProps = {

/** Style applied to PendingMapView */
style?: StyleProp<ViewStyle>;

/** Whether the size of the route pending icon is smaller. */
isSmallerIcon?: boolean;
};

// Initial state of the map
Expand Down
12 changes: 9 additions & 3 deletions src/components/MapView/PendingMapView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,34 @@ import {View} from 'react-native';
import BlockingView from '@components/BlockingViews/BlockingView';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import variables from '@styles/variables';
import type {PendingMapViewProps} from './MapViewTypes';

function PendingMapView({title = '', subtitle = '', style}: PendingMapViewProps) {
function PendingMapView({title = '', subtitle = '', style, isSmallerIcon = false}: PendingMapViewProps) {
const hasTextContent = !_.isEmpty(title) || !_.isEmpty(subtitle);
const styles = useThemeStyles();
const theme = useTheme();
const iconSize = isSmallerIcon ? variables.iconSizeSuperLarge : variables.iconSizeUltraLarge;
return (
<View style={[styles.mapPendingView, style]}>
{hasTextContent ? (
<BlockingView
icon={Expensicons.EmptyStateRoutePending}
iconColor={theme.border}
title={title}
subtitle={subtitle}
subtitleStyle={styles.textSupporting}
shouldShowLink={false}
/>
) : (
<View style={[styles.flex1, styles.alignItemsCenter, styles.justifyContentCenter, styles.ph10]}>
<Icon
src={Expensicons.EmptyStateRoutePending}
width={variables.iconSizeUltraLarge}
height={variables.iconSizeUltraLarge}
width={iconSize}
height={iconSize}
fill={theme.border}
/>
</View>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import truncate from 'lodash/truncate';
import React, {useMemo} from 'react';
import {View} from 'react-native';
import type {GestureResponderEvent} from 'react-native';
import ConfirmedRoute from '@components/ConfirmedRoute';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import {ReceiptScan} from '@components/Icon/Expensicons';
Expand Down Expand Up @@ -124,10 +123,7 @@ function MoneyRequestPreviewContent({
merchantOrDescription = description || '';
}

const receiptImages = hasReceipt ? [ReceiptUtils.getThumbnailAndImageURIs(transaction)] : [];

const hasPendingWaypoints = transaction?.pendingFields?.waypoints;
const showMapAsImage = isDistanceRequest && hasPendingWaypoints;
const receiptImages = hasReceipt ? [{...ReceiptUtils.getThumbnailAndImageURIs(transaction), transaction}] : [];

const getSettledMessage = (): string => {
if (isCardTransaction) {
Expand Down Expand Up @@ -254,15 +250,7 @@ function MoneyRequestPreviewContent({
!onPreviewPressed ? [styles.moneyRequestPreviewBox, containerStyles] : {},
]}
>
{showMapAsImage && (
<View style={styles.reportActionItemImages}>
<ConfirmedRoute
transaction={transaction}
interactive={false}
/>
</View>
)}
{!showMapAsImage && hasReceipt && (
{hasReceipt && (
<ReportActionItemImages
images={receiptImages}
isHovered={isHovered || isScanning}
Expand Down
39 changes: 14 additions & 25 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, {useCallback, useMemo} from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import ConfirmedRoute from '@components/ConfirmedRoute';
import * as Expensicons from '@components/Icon/Expensicons';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
Expand Down Expand Up @@ -120,8 +119,6 @@ function MoneyRequestView({
const isEmptyMerchant = transactionMerchant === '' || transactionMerchant === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT;
const isDistanceRequest = TransactionUtils.isDistanceRequest(transaction);
const formattedTransactionAmount = transactionAmount ? CurrencyUtils.convertToDisplayString(transactionAmount, transactionCurrency) : '';
const hasPendingWaypoints = Boolean(transaction?.pendingFields?.waypoints);
const showMapAsImage = isDistanceRequest && hasPendingWaypoints;
const formattedOriginalAmount = transactionOriginalAmount && transactionOriginalCurrency && CurrencyUtils.convertToDisplayString(transactionOriginalAmount, transactionOriginalCurrency);
const isCardTransaction = TransactionUtils.isCardTransaction(transaction);
const cardProgramName = isCardTransaction && transactionCardID !== undefined ? CardUtils.getCardDescription(transactionCardID) : '';
Expand Down Expand Up @@ -316,7 +313,6 @@ function MoneyRequestView({
</OfflineWithFeedback>
);

const shouldShowMapOrReceipt = showMapAsImage || hasReceipt;
const isReceiptAllowed = !isPaidReport && !isInvoice;
const shouldShowReceiptEmptyState =
isReceiptAllowed && !hasReceipt && !isApproved && !isSettled && (canEditReceipt || isAdmin || isApprover) && (canEditReceipt || ReportUtils.isPaidGroupPolicy(report));
Expand All @@ -330,7 +326,7 @@ function MoneyRequestView({
const receiptViolations =
transactionViolations?.filter((violation) => receiptViolationNames.includes(violation.name)).map((violation) => ViolationsUtils.getViolationTranslation(violation, translate)) ?? [];
const shouldShowNotesViolations = !isReceiptBeingScanned && canUseViolations && ReportUtils.isPaidGroupPolicy(report);
const shouldShowReceiptHeader = isReceiptAllowed && (shouldShowReceiptEmptyState || shouldShowMapOrReceipt) && canUseViolations && ReportUtils.isPaidGroupPolicy(report);
const shouldShowReceiptHeader = isReceiptAllowed && (shouldShowReceiptEmptyState || hasReceipt) && canUseViolations && ReportUtils.isPaidGroupPolicy(report);

const errors = {
...(transaction?.errorFields?.route ?? transaction?.errors),
Expand All @@ -347,7 +343,7 @@ function MoneyRequestView({
shouldShowAuditMessage={Boolean(shouldShowNotesViolations && didRceiptScanSucceed)}
/>
)}
{(shouldShowMapOrReceipt || errors) && (
{(hasReceipt || errors) && (
<OfflineWithFeedback
pendingAction={pendingAction}
errors={errors}
Expand All @@ -360,25 +356,18 @@ function MoneyRequestView({
ReportActions.clearAllRelatedReportActionErrors(report.reportID, parentReportAction);
}}
>
{shouldShowMapOrReceipt && (
{hasReceipt && (
<View style={styles.moneyRequestViewImage}>
{showMapAsImage ? (
<ConfirmedRoute
transaction={transaction}
interactive={false}
/>
) : (
<ReportActionItemImage
thumbnail={receiptURIs?.thumbnail}
fileExtension={receiptURIs?.fileExtension}
isThumbnail={receiptURIs?.isThumbnail}
image={receiptURIs?.image}
isLocalFile={receiptURIs?.isLocalFile}
filename={receiptURIs?.filename}
transaction={transaction}
enablePreviewModal
/>
)}
<ReportActionItemImage
thumbnail={receiptURIs?.thumbnail}
fileExtension={receiptURIs?.fileExtension}
isThumbnail={receiptURIs?.isThumbnail}
image={receiptURIs?.image}
isLocalFile={receiptURIs?.isLocalFile}
filename={receiptURIs?.filename}
transaction={transaction}
enablePreviewModal
/>
</View>
)}
</OfflineWithFeedback>
Expand All @@ -400,7 +389,7 @@ function MoneyRequestView({
}
/>
)}
{!shouldShowReceiptEmptyState && !shouldShowMapOrReceipt && <View style={{marginVertical: 6}} />}
{!shouldShowReceiptEmptyState && !hasReceipt && <View style={{marginVertical: 6}} />}
{shouldShowNotesViolations && <ReceiptAuditMessages notes={receiptViolations} />}
<OfflineWithFeedback pendingAction={getPendingFieldAction('amount')}>
<MenuItemWithTopDescription
Expand Down
Loading

0 comments on commit d7e1ecf

Please sign in to comment.