Skip to content

Commit

Permalink
fix: close modal simply when waypoints not changed in edit distance r…
Browse files Browse the repository at this point in the history
…equest
  • Loading branch information
sangar-1028 committed Oct 7, 2023
1 parent 389d7b0 commit 8ae8745
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/pages/EditRequestDistancePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ const propTypes = {
/* Onyx props */
/** The original transaction that is being edited */
transaction: transactionPropTypes,

/** backup version of the original transaction */
transactionBackup: transactionPropTypes,
};

const defaultProps = {
transaction: {},
transactionBackup: {},
};

function EditRequestDistancePage({report, route, transaction}) {
function EditRequestDistancePage({report, route, transaction, transactionBackup}) {
const {isOffline} = useNetwork();
const {translate} = useLocalize();
const transactionWasSaved = useRef(false);
Expand Down Expand Up @@ -87,6 +91,13 @@ function EditRequestDistancePage({report, route, transaction}) {
* @param {Object} waypoints
*/
const saveTransaction = (waypoints) => {
// If nothing was changed, simply go back
const backupWaypoints = lodashGet(transactionBackup, 'comment.waypoints', {});
if (_.isEqual(backupWaypoints, waypoints)) {
Navigation.dismissModal(report.reportID);
return;
}

transactionWasSaved.current = true;
IOU.updateDistanceRequest(transaction.transactionID, report.reportID, {waypoints});

Expand Down Expand Up @@ -125,4 +136,7 @@ export default withOnyx({
transaction: {
key: (props) => `${ONYXKEYS.COLLECTION.TRANSACTION}${props.transactionID}`,
},
transactionBackup: {
key: (props) => `${ONYXKEYS.COLLECTION.TRANSACTION}${props.transactionID}-backup`,
},
})(EditRequestDistancePage);

0 comments on commit 8ae8745

Please sign in to comment.