Skip to content

Commit

Permalink
Merge pull request #27657 from DylanDylann/fix/26888
Browse files Browse the repository at this point in the history
  • Loading branch information
thienlnam authored Sep 21, 2023
2 parents 673bc48 + 59ec789 commit 04215cb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/components/DistanceRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,10 @@ function DistanceRequest({iou, iouType, report, transaction, mapboxAccessToken,
<Button
small
icon={Expensicons.Plus}
onPress={() => Transaction.addStop(iou.transactionID)}
onPress={() => {
const newIndex = _.size(lodashGet(transaction, 'comment.waypoints', {}));
Navigation.navigate(ROUTES.getMoneyRequestWaypointRoute('request', newIndex));
}}
text={translate('distance.addStop')}
isDisabled={numberOfWaypoints === MAX_WAYPOINTS}
innerStyles={[styles.ph10]}
Expand Down
18 changes: 13 additions & 5 deletions src/pages/iou/WaypointEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ function WaypointEditor({transactionID, route: {params: {iouType = '', waypointI
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 onSubmit = (values) => {
const waypointValue = values[`waypoint${waypointIndex}`] || '';

Expand All @@ -133,8 +143,7 @@ function WaypointEditor({transactionID, route: {params: {iouType = '', waypointI
lng: null,
address: waypointValue,
};

Transaction.saveWaypoint(transactionID, waypointIndex, waypoint);
saveWaypoint(waypoint);
}

// Other flows will be handled by selecting a waypoint with selectWaypoint as this is mainly for the offline flow
Expand All @@ -153,8 +162,7 @@ function WaypointEditor({transactionID, route: {params: {iouType = '', waypointI
lng: values.lng,
address: values.address,
};

Transaction.saveWaypoint(transactionID, waypointIndex, waypoint);
saveWaypoint(waypoint);
Navigation.goBack(ROUTES.getMoneyRequestDistanceTabRoute(iouType));
};

Expand All @@ -164,7 +172,7 @@ function WaypointEditor({transactionID, route: {params: {iouType = '', waypointI
onEntryTransitionEnd={() => textInput.current && textInput.current.focus()}
shouldEnableMaxHeight
>
<FullPageNotFoundView shouldShow={(Number.isNaN(parsedWaypointIndex) || parsedWaypointIndex < 0 || parsedWaypointIndex > waypointCount - 1) && isFocused}>
<FullPageNotFoundView shouldShow={(Number.isNaN(parsedWaypointIndex) || parsedWaypointIndex < 0 || parsedWaypointIndex > waypointCount) && isFocused}>
<HeaderWithBackButton
title={translate(wayPointDescriptionKey)}
shouldShowBackButton
Expand Down

0 comments on commit 04215cb

Please sign in to comment.