From b5e6eb9201d2472e2a5a11b6ef63bcfe1cac4b6f Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Tue, 5 Sep 2023 16:34:34 +0200 Subject: [PATCH 1/8] attach report id --- .../MoneyRequestParticipantsPage.js | 16 ++++++++++++---- .../MoneyRequestParticipantsSelector.js | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js index 68b21189f546..918acd54f64b 100644 --- a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js +++ b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js @@ -49,10 +49,18 @@ function MoneyRequestParticipantsPage(props) { const prevMoneyRequestId = useRef(props.iou.id); const iouType = useRef(lodashGet(props.route, 'params.iouType', '')); const reportID = useRef(lodashGet(props.route, 'params.reportID', '')); + const isNewReportIDSelectedLocally = useRef(false); const isDistanceRequest = MoneyRequestUtils.isDistanceRequest(iouType.current, props.selectedTab); - const navigateToNextStep = () => { - Navigation.navigate(ROUTES.getMoneyRequestConfirmationRoute(iouType.current, reportID.current)); + const navigateToNextStep = (option) => { + if (reportID.current !== option.reportID) { + isNewReportIDSelectedLocally.current = true; + } + + const correctReportID = reportID.current || option.reportID; + + IOU.setMoneyRequestId(`${iouType.current}${correctReportID}`); + Navigation.navigate(ROUTES.getMoneyRequestConfirmationRoute(iouType.current, correctReportID)); }; const navigateBack = (forceFallback = false) => { @@ -63,7 +71,7 @@ function MoneyRequestParticipantsPage(props) { // ID in Onyx could change by initiating a new request in a separate browser tab or completing a request if (prevMoneyRequestId.current !== props.iou.id) { // The ID is cleared on completing a request. In that case, we will do nothing - if (!isDistanceRequest && props.iou.id) { + if (!isNewReportIDSelectedLocally.current && !isDistanceRequest && props.iou.id) { navigateBack(true); } return; @@ -71,7 +79,7 @@ function MoneyRequestParticipantsPage(props) { // Reset the money request Onyx if the ID in Onyx does not match the ID from params const moneyRequestId = `${iouType.current}${reportID.current}`; - const shouldReset = props.iou.id !== moneyRequestId; + const shouldReset = props.iou.id !== moneyRequestId && !isNewReportIDSelectedLocally.current; if (shouldReset) { IOU.resetMoneyRequestInfo(moneyRequestId); } diff --git a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js index ef1d6565f595..748ebe9ae72d 100755 --- a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js +++ b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js @@ -148,7 +148,7 @@ class MoneyRequestParticipantsSelector extends Component { */ addSingleParticipant(option) { this.props.onAddParticipants([{accountID: option.accountID, login: option.login, isPolicyExpenseChat: option.isPolicyExpenseChat, reportID: option.reportID, selected: true}]); - this.props.onStepComplete(); + this.props.onStepComplete(option); } render() { From 73ecba06818c2d0a53d0536e5942b4ea8d5660ba Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Tue, 5 Sep 2023 17:08:12 +0200 Subject: [PATCH 2/8] simplify report id attaching --- .../MoneyRequestParticipantsPage.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js index 918acd54f64b..3b46f885db67 100644 --- a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js +++ b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js @@ -53,14 +53,10 @@ function MoneyRequestParticipantsPage(props) { const isDistanceRequest = MoneyRequestUtils.isDistanceRequest(iouType.current, props.selectedTab); const navigateToNextStep = (option) => { - if (reportID.current !== option.reportID) { - isNewReportIDSelectedLocally.current = true; - } - - const correctReportID = reportID.current || option.reportID; + isNewReportIDSelectedLocally.current = true; - IOU.setMoneyRequestId(`${iouType.current}${correctReportID}`); - Navigation.navigate(ROUTES.getMoneyRequestConfirmationRoute(iouType.current, correctReportID)); + IOU.setMoneyRequestId(`${iouType.current}${option.reportID}`); + Navigation.navigate(ROUTES.getMoneyRequestConfirmationRoute(iouType.current, option.reportID)); }; const navigateBack = (forceFallback = false) => { From a318ffa0293c23679aa91ce48b70bbcf3f4020e6 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Mon, 11 Sep 2023 14:48:59 +0200 Subject: [PATCH 3/8] fix split bill participants selection --- .../MoneyRequestParticipantsPage.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js index 3b46f885db67..7831f383120f 100644 --- a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js +++ b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js @@ -52,7 +52,11 @@ function MoneyRequestParticipantsPage(props) { const isNewReportIDSelectedLocally = useRef(false); const isDistanceRequest = MoneyRequestUtils.isDistanceRequest(iouType.current, props.selectedTab); - const navigateToNextStep = (option) => { + const splitNavigateToNextStep = () => { + Navigation.navigate(ROUTES.getMoneyRequestConfirmationRoute(iouType.current, reportID.current)); + }; + + const moneyRequestNavigateToNextStep = (option) => { isNewReportIDSelectedLocally.current = true; IOU.setMoneyRequestId(`${iouType.current}${option.reportID}`); @@ -101,14 +105,14 @@ function MoneyRequestParticipantsPage(props) { /> {iouType.current === CONST.IOU.MONEY_REQUEST_TYPE.SPLIT ? ( ) : ( Date: Mon, 11 Sep 2023 17:08:49 +0200 Subject: [PATCH 4/8] use hook --- .../MoneyRequestParticipantsPage.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js index 7831f383120f..58e55ecb9d88 100644 --- a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js +++ b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js @@ -10,7 +10,6 @@ import MoneyRequestParticipantsSplitSelector from './MoneyRequestParticipantsSpl import MoneyRequestParticipantsSelector from './MoneyRequestParticipantsSelector'; import styles from '../../../../styles/styles'; import ScreenWrapper from '../../../../components/ScreenWrapper'; -import withLocalize, {withLocalizePropTypes} from '../../../../components/withLocalize'; import Navigation from '../../../../libs/Navigation/Navigation'; import compose from '../../../../libs/compose'; import * as DeviceCapabilities from '../../../../libs/DeviceCapabilities'; @@ -18,6 +17,7 @@ import HeaderWithBackButton from '../../../../components/HeaderWithBackButton'; import * as IOU from '../../../../libs/actions/IOU'; import * as MoneyRequestUtils from '../../../../libs/MoneyRequestUtils'; import {iouPropTypes, iouDefaultProps} from '../../propTypes'; +import useLocalize from '../../../../hooks/useLocalize'; const propTypes = { /** React Navigation route */ @@ -37,8 +37,6 @@ const propTypes = { /** The current tab we have navigated to in the request modal. String that corresponds to the request type. */ selectedTab: PropTypes.oneOf([CONST.TAB.DISTANCE, CONST.TAB.MANUAL, CONST.TAB.SCAN]).isRequired, - - ...withLocalizePropTypes, }; const defaultProps = { @@ -46,6 +44,7 @@ const defaultProps = { }; function MoneyRequestParticipantsPage(props) { + const {translate} = useLocalize(); const prevMoneyRequestId = useRef(props.iou.id); const iouType = useRef(lodashGet(props.route, 'params.iouType', '')); const reportID = useRef(lodashGet(props.route, 'params.reportID', '')); @@ -100,7 +99,7 @@ function MoneyRequestParticipantsPage(props) { {({safeAreaPaddingBottomStyle}) => ( {iouType.current === CONST.IOU.MONEY_REQUEST_TYPE.SPLIT ? ( @@ -130,7 +129,6 @@ MoneyRequestParticipantsPage.propTypes = propTypes; MoneyRequestParticipantsPage.defaultProps = defaultProps; export default compose( - withLocalize, withOnyx({ iou: {key: ONYXKEYS.IOU}, selectedTab: { From 6c09b831c07ce4f7d5963b6a745bb639ffeb6ccd Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Mon, 11 Sep 2023 17:22:54 +0200 Subject: [PATCH 5/8] simplify hocs --- .../MoneyRequestParticipantsPage.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js index 58e55ecb9d88..5a01c19ccaeb 100644 --- a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js +++ b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js @@ -128,11 +128,11 @@ MoneyRequestParticipantsPage.displayName = 'IOUParticipantsPage'; MoneyRequestParticipantsPage.propTypes = propTypes; MoneyRequestParticipantsPage.defaultProps = defaultProps; -export default compose( - withOnyx({ - iou: {key: ONYXKEYS.IOU}, - selectedTab: { - key: `${ONYXKEYS.SELECTED_TAB}_${CONST.TAB.RECEIPT_TAB_ID}`, - }, - }), -)(MoneyRequestParticipantsPage); +export default withOnyx({ + iou: { + key: ONYXKEYS.IOU, + }, + selectedTab: { + key: `${ONYXKEYS.SELECTED_TAB}_${CONST.TAB.RECEIPT_TAB_ID}`, + }, +})(MoneyRequestParticipantsPage); From 3fd333e832bcfe955ed7105c576d73055ac4c000 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Mon, 11 Sep 2023 17:28:26 +0200 Subject: [PATCH 6/8] remove redundant import --- .../MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js index 5a01c19ccaeb..1b873f775ab9 100644 --- a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js +++ b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js @@ -11,7 +11,6 @@ import MoneyRequestParticipantsSelector from './MoneyRequestParticipantsSelector import styles from '../../../../styles/styles'; import ScreenWrapper from '../../../../components/ScreenWrapper'; import Navigation from '../../../../libs/Navigation/Navigation'; -import compose from '../../../../libs/compose'; import * as DeviceCapabilities from '../../../../libs/DeviceCapabilities'; import HeaderWithBackButton from '../../../../components/HeaderWithBackButton'; import * as IOU from '../../../../libs/actions/IOU'; From 28a5ed879d9680972f6a6688c3e3ef2497d1337a Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Tue, 12 Sep 2023 17:35:37 +0200 Subject: [PATCH 7/8] handle nullable report id --- .../MoneyRequestParticipantsPage.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js index c41acea59cc0..d57bcbe2f405 100644 --- a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js +++ b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js @@ -55,6 +55,12 @@ function MoneyRequestParticipantsPage(props) { }; const moneyRequestNavigateToNextStep = (option) => { + if (!option.reportID) { + Navigation.navigate(ROUTES.getMoneyRequestConfirmationRoute(iouType.current, reportID.current)); + + return; + } + isNewReportIDSelectedLocally.current = true; IOU.setMoneyRequestId(`${iouType.current}${option.reportID}`); From 1c0e2c85090999fab318809e74a28a30546d2c59 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Tue, 12 Sep 2023 19:25:46 +0200 Subject: [PATCH 8/8] fix updating id --- .../MoneyRequestParticipantsPage.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js index d57bcbe2f405..36264761872b 100644 --- a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js +++ b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js @@ -55,14 +55,15 @@ function MoneyRequestParticipantsPage(props) { }; const moneyRequestNavigateToNextStep = (option) => { + isNewReportIDSelectedLocally.current = true; + if (!option.reportID) { + IOU.setMoneyRequestId(iouType.current); Navigation.navigate(ROUTES.getMoneyRequestConfirmationRoute(iouType.current, reportID.current)); return; } - isNewReportIDSelectedLocally.current = true; - IOU.setMoneyRequestId(`${iouType.current}${option.reportID}`); Navigation.navigate(ROUTES.getMoneyRequestConfirmationRoute(iouType.current, option.reportID)); };