diff --git a/src/components/DistanceRequest/DistanceRequestFooter.js b/src/components/DistanceRequest/DistanceRequestFooter.js
index e476b2fa6d34..4d4335781b72 100644
--- a/src/components/DistanceRequest/DistanceRequestFooter.js
+++ b/src/components/DistanceRequest/DistanceRequestFooter.js
@@ -59,6 +59,7 @@ function DistanceRequestFooter({waypoints, transaction, mapboxAccessToken, navig
const {translate} = useLocalize();
const numberOfWaypoints = _.size(waypoints);
+ const numberOfFilledWaypoints = _.size(_.filter(waypoints, (waypoint) => !_.isEmpty(waypoint)));
const lastWaypointIndex = numberOfWaypoints - 1;
const waypointMarkers = useMemo(
@@ -98,16 +99,18 @@ function DistanceRequestFooter({waypoints, transaction, mapboxAccessToken, navig
return (
<>
-
-
+ {numberOfFilledWaypoints >= 2 && (
+
+
+ )}
{!isOffline && Boolean(mapboxAccessToken.token) ? (
{
+ const waypointCount = _.size(allWaypoints);
+ const filledWaypointCount = _.size(_.filter(allWaypoints, (waypoint) => !_.isEmpty(waypoint)));
+
+ const waypointDescriptionKey = useMemo(() => {
switch (parsedWaypointIndex) {
case 0:
return 'distance.waypointDescription.start';
@@ -102,9 +104,11 @@ function WaypointEditor({route: {params: {iouType = '', transactionID = '', wayp
const waypointAddress = lodashGet(currentWaypoint, 'address', '');
const isEditingWaypoint = Boolean(threadReportID);
- const totalWaypoints = _.size(lodashGet(transaction, 'comment.waypoints', {}));
// Hide the menu when there is only start and finish waypoint
- const shouldShowThreeDotsButton = totalWaypoints > 2;
+ const shouldShowThreeDotsButton = waypointCount > 2;
+ const shouldDisableEditor =
+ isFocused &&
+ (Number.isNaN(parsedWaypointIndex) || parsedWaypointIndex < 0 || parsedWaypointIndex > waypointCount || (filledWaypointCount < 2 && parsedWaypointIndex >= waypointCount));
const validate = (values) => {
const errors = {};
@@ -113,7 +117,7 @@ function WaypointEditor({route: {params: {iouType = '', transactionID = '', wayp
ErrorUtils.addErrorMessage(errors, `waypoint${waypointIndex}`, 'bankAccount.error.address');
}
- // If the user is online and they are trying to save a value without using the autocomplete, show an error message instructing them to use a selected address instead.
+ // If the user is online, and they are trying to save a value without using the autocomplete, show an error message instructing them to use a selected address instead.
// That enables us to save the address with coordinates when it is selected
if (!isOffline && waypointValue !== '' && waypointAddress !== waypointValue) {
ErrorUtils.addErrorMessage(errors, `waypoint${waypointIndex}`, 'distance.errors.selectSuggestedAddress');
@@ -122,15 +126,7 @@ function WaypointEditor({route: {params: {iouType = '', transactionID = '', wayp
return errors;
};
- const saveWaypoint = (waypoint) => {
- if (parsedWaypointIndex < _.size(allWaypoints)) {
- Transaction.saveWaypoint(transactionID, waypointIndex, waypoint);
- } else {
- const finishWaypoint = lodashGet(allWaypoints, `waypoint${_.size(allWaypoints) - 1}`, {});
- Transaction.saveWaypoint(transactionID, waypointIndex, finishWaypoint);
- Transaction.saveWaypoint(transactionID, waypointIndex - 1, waypoint);
- }
- };
+ const saveWaypoint = (waypoint) => Transaction.saveWaypoint(transactionID, waypointIndex, waypoint, isEditingWaypoint);
const submit = (values) => {
const waypointValue = values[`waypoint${waypointIndex}`] || '';
@@ -168,7 +164,7 @@ function WaypointEditor({route: {params: {iouType = '', transactionID = '', wayp
address: values.address,
name: values.name,
};
- Transaction.saveWaypoint(transactionID, waypointIndex, waypoint, isEditingWaypoint);
+ saveWaypoint(waypoint);
if (isEditingWaypoint) {
Navigation.goBack(ROUTES.REPORT_WITH_ID.getRoute(threadReportID));
@@ -184,9 +180,9 @@ function WaypointEditor({route: {params: {iouType = '', transactionID = '', wayp
shouldEnableMaxHeight
testID={WaypointEditor.displayName}
>
- waypointCount) && isFocused}>
+
{
Navigation.goBack(ROUTES.MONEY_REQUEST_DISTANCE_TAB.getRoute(iouType));