Skip to content

Commit

Permalink
Merge pull request #27826 from DylanDylann/fix/27383
Browse files Browse the repository at this point in the history
Fix/27383: Prevent request money if empty waypoint
  • Loading branch information
roryabraham authored Sep 25, 2023
2 parents 21b3e64 + f50cff6 commit 2f492e4
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import * as IOU from '../../../../libs/actions/IOU';
import * as MoneyRequestUtils from '../../../../libs/MoneyRequestUtils';
import {iouPropTypes, iouDefaultProps} from '../../propTypes';
import useLocalize from '../../../../hooks/useLocalize';
import * as TransactionUtils from '../../../../libs/TransactionUtils';

const propTypes = {
/** React Navigation route */
Expand Down Expand Up @@ -53,7 +54,8 @@ function MoneyRequestParticipantsPage({iou, selectedTab, route}) {
const isScanRequest = MoneyRequestUtils.isScanRequest(selectedTab);
const isSplitRequest = iou.id === CONST.IOU.MONEY_REQUEST_TYPE.SPLIT;
const [headerTitle, setHeaderTitle] = useState();

const transaction = TransactionUtils.getTransaction(iou.transactionID);
const isEmptyWaypoint = _.isEmpty(lodashGet(transaction, 'comment.waypoint.waypoint0', {}));
useEffect(() => {
if (isDistanceRequest) {
setHeaderTitle(translate('common.distance'));
Expand Down Expand Up @@ -85,10 +87,12 @@ function MoneyRequestParticipantsPage({iou, selectedTab, route}) {
};

useEffect(() => {
const isInvalidDistanceRequest = !isDistanceRequest || isEmptyWaypoint;

// ID in Onyx could change by initiating a new request in a separate browser tab or completing a request
if (prevMoneyRequestId.current !== iou.id) {
// The ID is cleared on completing a request. In that case, we will do nothing
if (iou.id && !isDistanceRequest && !isSplitRequest && !isNewReportIDSelectedLocally.current) {
if (iou.id && isInvalidDistanceRequest && !isSplitRequest && !isNewReportIDSelectedLocally.current) {
navigateBack(true);
}
return;
Expand All @@ -100,14 +104,14 @@ function MoneyRequestParticipantsPage({iou, selectedTab, route}) {
if (shouldReset) {
IOU.resetMoneyRequestInfo(moneyRequestId);
}
if (!isDistanceRequest && ((iou.amount === 0 && !iou.receiptPath) || shouldReset)) {
if (isInvalidDistanceRequest && ((iou.amount === 0 && !iou.receiptPath) || shouldReset)) {
navigateBack(true);
}

return () => {
prevMoneyRequestId.current = iou.id;
};
}, [iou.amount, iou.id, iou.receiptPath, isDistanceRequest, isSplitRequest]);
}, [iou.amount, iou.id, iou.receiptPath, isDistanceRequest, isSplitRequest, isEmptyWaypoint]);

return (
<ScreenWrapper
Expand Down

0 comments on commit 2f492e4

Please sign in to comment.