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 4 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(waypoint.lng) || lodashIsNil(waypoint.lat)) {
return;
}

Expand Down
8 changes: 5 additions & 3 deletions src/components/DistanceRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@ 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 = !lodashIsNull(lodashGet(transaction, 'errorFields.route'));
const haveWaypointsChanged = !_.isEqual(previousWaypoints, waypoints);
const doesRouteExist = lodashHas(transaction, 'routes.route0.geometry.coordinates');
const doesRouteExist = TransactionUtils.doesRouteExist(transaction)
paultsimura marked this conversation as resolved.
Show resolved Hide resolved
const validatedWaypoints = TransactionUtils.getValidWaypoints(waypoints);
const shouldFetchRoute = (!doesRouteExist || haveWaypointsChanged) && !isLoadingRoute && _.size(validatedWaypoints) > 1;
const hasMultipleValidWaypoints = _.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 && hasMultipleValidWaypoints;
paultsimura marked this conversation as resolved.
Show resolved Hide resolved
const waypointMarkers = useMemo(
() =>
_.filter(
Expand Down
6 changes: 4 additions & 2 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,7 +174,8 @@ function MoneyRequestConfirmationList(props) {
const shouldCalculateDistanceAmount = props.isDistanceRequest && props.iouAmount === 0;
const shouldCategoryEditable = !_.isEmpty(props.policyCategories) && !props.isDistanceRequest;

const formattedAmount = CurrencyUtils.convertToDisplayString(
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,
);
Expand Down Expand Up @@ -466,7 +468,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: 'A definir'
},
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