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

fix: BUG: [distance] request confirmation offline doesn't show TBD #26836

Merged
merged 33 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
9d9cc6f
- Implement map route re-fetch on going online
paultsimura Sep 5, 2023
05908dd
Handle null waypoint coordinates correctly
paultsimura Sep 6, 2023
7afdf80
Add hasRouteError check for route re-fetch
paultsimura Sep 6, 2023
0b9596d
Make the shouldFetchRoute condition more readable
paultsimura Sep 6, 2023
af2c13f
Some refactoring
paultsimura Sep 6, 2023
9ce8d13
Translation change
paultsimura Sep 7, 2023
5dc1d8e
Formatting
paultsimura Sep 8, 2023
6d4592f
Fix missing workspace rate
paultsimura Sep 8, 2023
6d35789
Fix missing workspace distance rate
paultsimura Sep 8, 2023
2687882
Merge branch 'main' into fix-26537
paultsimura Sep 11, 2023
7078c52
Merge branch 'main' into fix-26537
paultsimura Sep 11, 2023
6574808
Render map's BlockingView without text
paultsimura Sep 11, 2023
6b0ecd3
Refactoring
paultsimura Sep 11, 2023
034fb4e
Refactoring
paultsimura Sep 11, 2023
7f24db2
Use lodashIsNil
paultsimura Sep 12, 2023
02bfdac
Use lodashIsNil
paultsimura Sep 12, 2023
3a139d4
Merge branch 'main' into fix-26537
paultsimura Sep 12, 2023
b0b2ea2
Add PendingMapView component
paultsimura Sep 12, 2023
59d174c
Polish the distance merchant logic
paultsimura Sep 13, 2023
b0ec8ad
Refactor
paultsimura Sep 13, 2023
29b3b9c
Increase icon dimensions
paultsimura Sep 13, 2023
b89f277
Merge branch 'main' into fix-26537
paultsimura Sep 13, 2023
3ab3c0e
Use icon size variable
paultsimura Sep 13, 2023
40585d5
Merge branch 'main' into fix-26537
paultsimura Sep 15, 2023
c3117fc
Hide "TBD" on the Request button
paultsimura Sep 15, 2023
383f2dd
Fix useMemo deps
paultsimura Sep 15, 2023
d64b0f3
Merge branch 'main' into fix-26537
paultsimura Sep 18, 2023
0644152
Change the request button text logic
paultsimura Sep 18, 2023
9442b59
Merge branch 'main' into fix-26537
paultsimura Sep 18, 2023
3c8d3a9
Remove redundant useNetwork
paultsimura Sep 18, 2023
e0bd72d
Revert "Remove redundant useNetwork"
paultsimura Sep 18, 2023
764bc16
Revert distance rate fix
paultsimura Sep 18, 2023
38014f7
Lint
paultsimura Sep 18, 2023
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
3 changes: 2 additions & 1 deletion src/components/ConfirmedRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {View} from 'react-native';

import {withOnyx} from 'react-native-onyx';
import lodashGet from 'lodash/get';
import lodashIsNil from 'lodash/isNil';
import _ from 'underscore';
import ONYXKEYS from '../ONYXKEYS';
import CONST from '../CONST';
Expand Down Expand Up @@ -43,7 +44,7 @@ const getWaypointMarkers = (waypoints) => {
const lastWaypointIndex = numberOfWaypoints - 1;
return _.filter(
_.map(waypoints, (waypoint, key) => {
if (!waypoint || waypoint.lng === undefined || waypoint.lat === undefined) {
if (!waypoint || lodashIsNil(lodashGet(waypoint, 'lng')) || lodashIsNil(lodashGet(waypoint, 'lat'))) {
neil-marcellini marked this conversation as resolved.
Show resolved Hide resolved
return;
}

Expand Down
12 changes: 6 additions & 6 deletions src/components/DistanceRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import React, {useEffect, useMemo, useState, useRef} from 'react';
import {ScrollView, View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import lodashGet from 'lodash/get';
import lodashHas from 'lodash/has';
import lodashIsNull from 'lodash/isNull';
import lodashIsNil from 'lodash/isNil';
import PropTypes from 'prop-types';
import _ from 'underscore';

Expand Down Expand Up @@ -90,16 +89,17 @@ function DistanceRequest({iou, iouType, report, transaction, mapboxAccessToken})

const lastWaypointIndex = numberOfWaypoints - 1;
const isLoadingRoute = lodashGet(transaction, 'comment.isLoading', false);
const hasRouteError = lodashHas(transaction, 'errorFields.route');
const hasRouteError = !lodashIsNil(lodashGet(transaction, 'errorFields.route'));
const haveWaypointsChanged = !_.isEqual(previousWaypoints, waypoints);
const doesRouteExist = lodashHas(transaction, 'routes.route0.geometry.coordinates');
const doesRouteExist = TransactionUtils.doesRouteExist(transaction);
const validatedWaypoints = TransactionUtils.getValidWaypoints(waypoints);
const shouldFetchRoute = (!doesRouteExist || haveWaypointsChanged) && !isLoadingRoute && _.size(validatedWaypoints) > 1;
const isRouteAbsentWithNoErrors = !hasRouteError && !doesRouteExist;
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB: I prefer isRouteAbsentWithoutErrors

Copy link
Contributor

Choose a reason for hiding this comment

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

However, we also tend to prefer to name variables without negations so maybe you can refactor this a bit.

const shouldFetchRoute = (haveWaypointsChanged || isRouteAbsentWithNoErrors) && !isLoadingRoute && _.size(validatedWaypoints) > 1;
const waypointMarkers = useMemo(
() =>
_.filter(
_.map(waypoints, (waypoint, key) => {
if (!waypoint || !lodashHas(waypoint, 'lat') || !lodashHas(waypoint, 'lng') || lodashIsNull(waypoint.lat) || lodashIsNull(waypoint.lng)) {
if (!waypoint || lodashIsNil(lodashGet(waypoint, 'lng')) || lodashIsNil(lodashGet(waypoint, 'lat'))) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This specific change is only for cosmetic purposes to reflect my changes in here:

if (!waypoint || lodashIsNil(lodashGet(waypoint, 'lng')) || lodashIsNil(lodashGet(waypoint, 'lat'))) {

And that fix was related not only to non-existing address. Without my change, going back online on the confirmation screen after entering any address points would crash the mobile app.

mobile_crash.mp4

Copy link
Contributor

@Ollyws Ollyws Sep 8, 2023

Choose a reason for hiding this comment

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

Thanks for the clarifiction. It does also seem to have the benefit of an early return when the waypoint lat/lng is set to 'null' which stops the map from navigating to the middle of the ocean when you select an incorrect address. (The incorrect address needs to be added offline to be accessible from the address list)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this particular case we still did return early in the null cases – 4th and 5th checks: ... || lodashIsNull(waypoint.lat) || lodashIsNull(waypoint.lng).
However, maybe the fact that I've changed isNull to isNil now handles this case, because it covers undefined as well, not only null.

Copy link
Contributor

@Ollyws Ollyws Sep 8, 2023

Choose a reason for hiding this comment

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

Ah so we did, sorry must have been getting confused with the changes in confirmedRoute where we didn't check for null.

return;
}

Expand Down
15 changes: 10 additions & 5 deletions src/components/MoneyRequestConfirmationList.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import ConfirmedRoute from './ConfirmedRoute';
import transactionPropTypes from './transactionPropTypes';
import DistanceRequestUtils from '../libs/DistanceRequestUtils';
import * as IOU from '../libs/actions/IOU';
import * as TransactionUtils from '../libs/TransactionUtils';

const propTypes = {
/** Callback to inform parent modal of success */
Expand Down Expand Up @@ -173,10 +174,14 @@ function MoneyRequestConfirmationList(props) {
const shouldCalculateDistanceAmount = props.isDistanceRequest && props.iouAmount === 0;
const shouldCategoryEditable = !_.isEmpty(props.policyCategories) && !props.isDistanceRequest;

const formattedAmount = CurrencyUtils.convertToDisplayString(
shouldCalculateDistanceAmount ? DistanceRequestUtils.getDistanceRequestAmount(distance, unit, rate) : props.iouAmount,
props.isDistanceRequest ? currency : props.iouCurrencyCode,
);
const doesRouteExist = TransactionUtils.doesRouteExist(transaction);
const formattedAmount =
props.isDistanceRequest && !doesRouteExist
? translate('common.tbd')
: CurrencyUtils.convertToDisplayString(
shouldCalculateDistanceAmount ? DistanceRequestUtils.getDistanceRequestAmount(distance, unit, rate) : props.iouAmount,
props.isDistanceRequest ? currency : props.iouCurrencyCode,
);

useEffect(() => {
if (!shouldCalculateDistanceAmount) {
Expand Down Expand Up @@ -466,7 +471,7 @@ function MoneyRequestConfirmationList(props) {
{props.isDistanceRequest ? (
<MenuItemWithTopDescription
shouldShowRightIcon={!props.isReadOnly && isTypeRequest}
title={props.iouMerchant}
title={doesRouteExist ? props.iouMerchant : translate('common.tbd')}
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead let's update where we get the distance request merchant to set only the amount to TBD.

const distanceMerchant = DistanceRequestUtils.getDistanceMerchant(distance, unit, rate, currency, translate);

description={translate('common.distance')}
style={[styles.moneyRequestMenuItem, styles.mb2]}
titleStyle={styles.flex1}
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ export default {
kilometers: 'kilometers',
recent: 'Recent',
all: 'All',
tbd: 'TBD',
},
anonymousReportFooter: {
logoTagline: 'Join the discussion.',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ export default {
kilometers: 'kilómetros',
recent: 'Reciente',
all: 'Todo',
tbd: 'Por determinar',
},
anonymousReportFooter: {
logoTagline: 'Únete a la discusión.',
Expand Down
12 changes: 12 additions & 0 deletions src/libs/TransactionUtils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Onyx from 'react-native-onyx';
import {format, parseISO, isValid} from 'date-fns';
import lodashGet from 'lodash/get';
import lodashIsNil from 'lodash/isNil';
import _ from 'underscore';
import CONST from '../CONST';
import ONYXKEYS from '../ONYXKEYS';
Expand Down Expand Up @@ -271,6 +272,16 @@ function hasMissingSmartscanFields(transaction) {
return hasReceipt(transaction) && !isDistanceRequest(transaction) && !isReceiptBeingScanned(transaction) && areRequiredFieldsEmpty(transaction);
}

/**
* Check if the transaction has a defined route
*
* @param {Object} transaction
* @returns {Boolean}
*/
function doesRouteExist(transaction) {
return !lodashIsNil(lodashGet(transaction, 'routes.route0.geometry.coordinates'));
}

/**
* Get the transactions related to a report preview with receipts
* Get the details linked to the IOU reportAction
Expand Down Expand Up @@ -345,6 +356,7 @@ function getValidWaypoints(waypoints, reArrangeIndexes = false) {

export {
buildOptimisticTransaction,
doesRouteExist,
getUpdatedTransaction,
getTransaction,
getDescription,
Expand Down
5 changes: 3 additions & 2 deletions src/pages/iou/steps/MoneyRequestConfirmPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import reportPropTypes from '../../reportPropTypes';
import personalDetailsPropType from '../../personalDetailsPropType';
import * as FileUtils from '../../../libs/fileDownload/FileUtils';
import * as Policy from '../../../libs/actions/Policy';
import useNetwork from '../../../hooks/useNetwork';
import useWindowDimensions from '../../../hooks/useWindowDimensions';
import * as StyleUtils from '../../../styles/StyleUtils';
import {iouPropTypes, iouDefaultProps} from '../propTypes';
Expand Down Expand Up @@ -59,6 +60,7 @@ const defaultProps = {
};

function MoneyRequestConfirmPage(props) {
const {isOffline} = useNetwork();
const {windowHeight} = useWindowDimensions();
const prevMoneyRequestId = useRef(props.iou.id);
const iouType = useRef(lodashGet(props.route, 'params.iouType', ''));
Expand All @@ -77,8 +79,7 @@ function MoneyRequestConfirmPage(props) {
if (policyExpenseChat) {
Policy.openDraftWorkspaceRequest(policyExpenseChat.policyID);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [isOffline, participants]);

useEffect(() => {
// ID in Onyx could change by initiating a new request in a separate browser tab or completing a request
Expand Down