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 #29972: reset IOU if there's divergence between stored IOU and URL parameters #31009

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions src/pages/iou/MoneyRequestSelectorPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import * as IOU from '@userActions/IOU';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import NewDistanceRequestPage from './NewDistanceRequestPage';
import {iouDefaultProps, iouPropTypes} from './propTypes';
import ReceiptSelector from './ReceiptSelector';
import NewRequestAmountPage from './steps/NewRequestAmountPage';

Expand All @@ -43,6 +44,9 @@ const propTypes = {
/** Report on which the money request is being created */
report: reportPropTypes,

/** Holds data related to Money Request view state, rather than the underlying Money Request data. */
iou: iouPropTypes,

/** Which tab has been selected */
selectedTab: PropTypes.string,

Expand All @@ -51,6 +55,7 @@ const propTypes = {
};

const defaultProps = {
iou: iouDefaultProps,
selectedTab: CONST.TAB.SCAN,
report: {},
betas: [],
Expand Down Expand Up @@ -81,6 +86,17 @@ function MoneyRequestSelectorPage(props) {
const isAllowedToCreateRequest = _.isEmpty(props.report.reportID) || ReportUtils.canCreateRequest(props.report, props.betas, iouType);
const prevSelectedTab = usePrevious(props.selectedTab);

// Reset money request info if there's a mismatch between Onyx's IOU and the url parameters
// This is only executed when the screen is first mounted
useEffect(() => {
if (props.iou.id === `${iouType}${reportID}`) {
return;
}

resetMoneyRequestInfo();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
if (prevSelectedTab === props.selectedTab) {
return;
Expand Down Expand Up @@ -158,6 +174,7 @@ MoneyRequestSelectorPage.displayName = 'MoneyRequestSelectorPage';
export default compose(
withReportOrNotFound(false),
withOnyx({
iou: {key: ONYXKEYS.IOU},
selectedTab: {
key: `${ONYXKEYS.COLLECTION.SELECTED_TAB}${CONST.TAB.RECEIPT_TAB_ID}`,
},
Expand Down
Loading