From 33de55eddc79cab682d3c4a1b0fb561cef269244 Mon Sep 17 00:00:00 2001 From: Dylan Date: Thu, 5 Oct 2023 13:54:35 +0700 Subject: [PATCH 01/12] navaigate back when reloading --- .../iou/steps/MoneyRequestConfirmPage.js | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index 3881221d5c52..9cbf169f78d0 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -1,4 +1,4 @@ -import React, {useCallback, useEffect, useMemo, useRef} from 'react'; +import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; import {ScrollView, View} from 'react-native'; import PropTypes from 'prop-types'; import {withOnyx} from 'react-native-onyx'; @@ -67,6 +67,7 @@ function MoneyRequestConfirmPage(props) { const iouType = useRef(lodashGet(props.route, 'params.iouType', '')); const isDistanceRequest = MoneyRequestUtils.isDistanceRequest(iouType.current, props.selectedTab); const reportID = useRef(lodashGet(props.route, 'params.reportID', '')); + const [receiptFile, setReceiptFile] = useState(); const participants = useMemo( () => _.map(props.iou.participants, (participant) => { @@ -77,7 +78,27 @@ function MoneyRequestConfirmPage(props) { ); const isManualRequestDM = props.selectedTab === CONST.TAB.MANUAL && iouType.current === CONST.IOU.MONEY_REQUEST_TYPE.REQUEST; + const navigateBack = () => { + let fallback; + if (reportID.current) { + fallback = ROUTES.MONEY_REQUEST.getRoute(iouType.current, reportID.current); + } else { + fallback = ROUTES.MONEY_REQUEST_PARTICIPANTS.getRoute(iouType.current); + } + Navigation.goBack(fallback); + }; + useEffect(() => { + if (props.iou.receiptPath && props.iou.receiptSource) { + FileUtils.readFileAsync(props.iou.receiptPath, props.iou.receiptSource).then((receipt) => { + if (!receipt) { + navigateBack(); + } else { + setReceiptFile(receipt); + } + }); + } + const policyExpenseChat = _.find(participants, (participant) => participant.isPolicyExpenseChat); if (policyExpenseChat) { Policy.openDraftWorkspaceRequest(policyExpenseChat.policyID); @@ -86,7 +107,7 @@ function MoneyRequestConfirmPage(props) { if (typeof props.iou.billable !== 'boolean') { IOU.setMoneyRequestBillable(lodashGet(props.policy, 'defaultBillable', false)); } - }, [isOffline, participants, props.iou.billable, props.policy]); + }, [isOffline, participants, props.iou.billable, props.iou.receiptPath, props.iou.receiptSource, props.policy]); useEffect(() => { // ID in Onyx could change by initiating a new request in a separate browser tab or completing a request @@ -114,16 +135,6 @@ function MoneyRequestConfirmPage(props) { }; }, [props.iou.participants, props.iou.amount, props.iou.id, props.iou.receiptPath, isDistanceRequest]); - const navigateBack = () => { - let fallback; - if (reportID.current) { - fallback = ROUTES.MONEY_REQUEST.getRoute(iouType.current, reportID.current); - } else { - fallback = ROUTES.MONEY_REQUEST_PARTICIPANTS.getRoute(iouType.current); - } - Navigation.goBack(fallback); - }; - /** * @param {Array} selectedParticipants * @param {String} trimmedComment @@ -216,12 +227,8 @@ function MoneyRequestConfirmPage(props) { return; } - if (props.iou.receiptPath && props.iou.receiptSource) { - FileUtils.readFileAsync(props.iou.receiptPath, props.iou.receiptSource).then((file) => { - const receipt = file; - receipt.state = file && isManualRequestDM ? CONST.IOU.RECEIPT_STATE.OPEN : CONST.IOU.RECEIPT_STATE.SCANREADY; - requestMoney(selectedParticipants, trimmedComment, receipt); - }); + if (receiptFile) { + requestMoney(selectedParticipants, trimmedComment, receiptFile); return; } @@ -238,12 +245,10 @@ function MoneyRequestConfirmPage(props) { props.currentUserPersonalDetails.login, props.currentUserPersonalDetails.accountID, props.iou.currency, - props.iou.receiptPath, - props.iou.receiptSource, isDistanceRequest, requestMoney, createDistanceRequest, - isManualRequestDM, + receiptFile, ], ); From 70c2da4340113a70706d983acccc16c9bf5c9b69 Mon Sep 17 00:00:00 2001 From: Dylan Date: Fri, 6 Oct 2023 10:14:36 +0700 Subject: [PATCH 02/12] update state of receipt --- src/pages/iou/steps/MoneyRequestConfirmPage.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index 9cbf169f78d0..5575caaf1f9d 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -90,10 +90,12 @@ function MoneyRequestConfirmPage(props) { useEffect(() => { if (props.iou.receiptPath && props.iou.receiptSource) { - FileUtils.readFileAsync(props.iou.receiptPath, props.iou.receiptSource).then((receipt) => { - if (!receipt) { + FileUtils.readFileAsync(props.iou.receiptPath, props.iou.receiptSource).then((file) => { + if (!file) { navigateBack(); } else { + const receipt = file; + receipt.state = file && isManualRequestDM ? CONST.IOU.RECEIPT_STATE.OPEN : CONST.IOU.RECEIPT_STATE.SCANREADY; setReceiptFile(receipt); } }); @@ -107,7 +109,7 @@ function MoneyRequestConfirmPage(props) { if (typeof props.iou.billable !== 'boolean') { IOU.setMoneyRequestBillable(lodashGet(props.policy, 'defaultBillable', false)); } - }, [isOffline, participants, props.iou.billable, props.iou.receiptPath, props.iou.receiptSource, props.policy]); + }, [isOffline, participants, props.iou.billable, props.iou.receiptPath, props.iou.receiptSource, props.policy, isManualRequestDM]); useEffect(() => { // ID in Onyx could change by initiating a new request in a separate browser tab or completing a request From 968e56479ef92ea03d9c444ab63601e6abbaf5f2 Mon Sep 17 00:00:00 2001 From: Dylan Date: Mon, 9 Oct 2023 23:36:55 +0700 Subject: [PATCH 03/12] using goback instead of navigate back --- .../iou/steps/MoneyRequestConfirmPage.js | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index ca9ab16f1580..3b1f857d1b14 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -79,16 +79,6 @@ function MoneyRequestConfirmPage(props) { const isPolicyExpenseChat = useMemo(() => ReportUtils.isPolicyExpenseChat(ReportUtils.getRootParentReport(props.report)), [props.report]); const isManualRequestDM = props.selectedTab === CONST.TAB.MANUAL && iouType.current === CONST.IOU.MONEY_REQUEST_TYPE.REQUEST; - const navigateBack = () => { - let fallback; - if (reportID.current) { - fallback = ROUTES.MONEY_REQUEST.getRoute(iouType.current, reportID.current); - } else { - fallback = ROUTES.MONEY_REQUEST_PARTICIPANTS.getRoute(iouType.current); - } - Navigation.goBack(fallback); - }; - useEffect(() => { IOU.resetMoneyRequestCategory(); IOU.resetMoneyRequestTag(); @@ -98,7 +88,7 @@ function MoneyRequestConfirmPage(props) { if (props.iou.receiptPath && props.iou.receiptSource) { FileUtils.readFileAsync(props.iou.receiptPath, props.iou.receiptSource).then((file) => { if (!file) { - navigateBack(); + Navigation.goBack(ROUTES.MONEY_REQUEST.getRoute(iouType.current, reportID.current)); } else { const receipt = file; receipt.state = file && isManualRequestDM ? CONST.IOU.RECEIPT_STATE.OPEN : CONST.IOU.RECEIPT_STATE.SCANREADY; @@ -142,6 +132,16 @@ function MoneyRequestConfirmPage(props) { }; }, [props.iou.participants, props.iou.amount, props.iou.id, props.iou.receiptPath, isDistanceRequest]); + const navigateBack = () => { + let fallback; + if (reportID.current) { + fallback = ROUTES.MONEY_REQUEST.getRoute(iouType.current, reportID.current); + } else { + fallback = ROUTES.MONEY_REQUEST_PARTICIPANTS.getRoute(iouType.current); + } + Navigation.goBack(fallback); + }; + /** * @param {Array} selectedParticipants * @param {String} trimmedComment From c370c1ce37d0edcfebde7afc0ecfb3bd2cfbfe3b Mon Sep 17 00:00:00 2001 From: Dylan Date: Mon, 9 Oct 2023 23:40:37 +0700 Subject: [PATCH 04/12] fix lint --- src/pages/iou/steps/MoneyRequestConfirmPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index 3b1f857d1b14..8009004e71e8 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -141,7 +141,7 @@ function MoneyRequestConfirmPage(props) { } Navigation.goBack(fallback); }; - + /** * @param {Array} selectedParticipants * @param {String} trimmedComment From 26e8fd9afa6d81b4685783e38e6b1f742ccd93c0 Mon Sep 17 00:00:00 2001 From: Dylan Date: Mon, 9 Oct 2023 23:47:25 +0700 Subject: [PATCH 05/12] fix lint --- src/pages/iou/steps/MoneyRequestConfirmPage.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index 8009004e71e8..9cbaa55ccc1e 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -255,8 +255,6 @@ function MoneyRequestConfirmPage(props) { props.currentUserPersonalDetails.accountID, props.iou.currency, props.iou.category, - props.iou.receiptPath, - props.iou.receiptSource, isDistanceRequest, requestMoney, createDistanceRequest, From 1a5b0e9c33ca7dc3875b7056bb211bc4c1809d70 Mon Sep 17 00:00:00 2001 From: Dylan Date: Wed, 11 Oct 2023 00:47:07 +0700 Subject: [PATCH 06/12] use a new useEffect --- .../iou/steps/MoneyRequestConfirmPage.js | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index 9cbaa55ccc1e..e2f13833c00f 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -85,17 +85,6 @@ function MoneyRequestConfirmPage(props) { }, []); useEffect(() => { - if (props.iou.receiptPath && props.iou.receiptSource) { - FileUtils.readFileAsync(props.iou.receiptPath, props.iou.receiptSource).then((file) => { - if (!file) { - Navigation.goBack(ROUTES.MONEY_REQUEST.getRoute(iouType.current, reportID.current)); - } else { - const receipt = file; - receipt.state = file && isManualRequestDM ? CONST.IOU.RECEIPT_STATE.OPEN : CONST.IOU.RECEIPT_STATE.SCANREADY; - setReceiptFile(receipt); - } - }); - } const policyExpenseChat = _.find(participants, (participant) => participant.isPolicyExpenseChat); if (policyExpenseChat) { Policy.openDraftWorkspaceRequest(policyExpenseChat.policyID); @@ -104,13 +93,29 @@ function MoneyRequestConfirmPage(props) { if (typeof props.iou.billable !== 'boolean') { IOU.setMoneyRequestBillable(lodashGet(props.policy, 'defaultBillable', false)); } - }, [isOffline, participants, props.iou.billable, props.iou.receiptPath, props.iou.receiptSource, props.policy, isManualRequestDM]); + }, [isOffline, participants, props.iou.billable, props.policy]); + + useEffect(() => { + if (!props.iou.receiptPath || !props.iou.receiptSource) { + return; + } + FileUtils.readFileAsync(props.iou.receiptPath, props.iou.receiptSource).then((file) => { + if (!file) { + Navigation.goBack(ROUTES.MONEY_REQUEST.getRoute(iouType.current, reportID.current)); + } else { + const receipt = file; + receipt.state = file && isManualRequestDM ? CONST.IOU.RECEIPT_STATE.OPEN : CONST.IOU.RECEIPT_STATE.SCANREADY; + setReceiptFile(receipt); + } + }); + }, [props.iou.receiptPath, props.iou.receiptSource, isManualRequestDM]); useEffect(() => { // ID in Onyx could change by initiating a new request in a separate browser tab or completing a request if (!isDistanceRequest && prevMoneyRequestId.current !== props.iou.id) { // The ID is cleared on completing a request. In that case, we will do nothing. if (props.iou.id) { + console.log('navigate 2'); Navigation.goBack(ROUTES.MONEY_REQUEST.getRoute(iouType.current, reportID.current), true); } return; @@ -124,6 +129,7 @@ function MoneyRequestConfirmPage(props) { } if (_.isEmpty(props.iou.participants) || (props.iou.amount === 0 && !props.iou.receiptPath && !isDistanceRequest) || shouldReset) { + console.log('navigate 3'); Navigation.goBack(ROUTES.MONEY_REQUEST.getRoute(iouType.current, reportID.current), true); } From ab55516f71c7cda8b5137f18300acb2a4c85afd1 Mon Sep 17 00:00:00 2001 From: Dylan Date: Wed, 11 Oct 2023 00:47:39 +0700 Subject: [PATCH 07/12] fix lint --- src/pages/iou/steps/MoneyRequestConfirmPage.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index e2f13833c00f..bd1e6ed55a7f 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -115,7 +115,6 @@ function MoneyRequestConfirmPage(props) { if (!isDistanceRequest && prevMoneyRequestId.current !== props.iou.id) { // The ID is cleared on completing a request. In that case, we will do nothing. if (props.iou.id) { - console.log('navigate 2'); Navigation.goBack(ROUTES.MONEY_REQUEST.getRoute(iouType.current, reportID.current), true); } return; @@ -129,7 +128,6 @@ function MoneyRequestConfirmPage(props) { } if (_.isEmpty(props.iou.participants) || (props.iou.amount === 0 && !props.iou.receiptPath && !isDistanceRequest) || shouldReset) { - console.log('navigate 3'); Navigation.goBack(ROUTES.MONEY_REQUEST.getRoute(iouType.current, reportID.current), true); } From af8f7f606e4d40a8fb4840c7b73a9584f08a7604 Mon Sep 17 00:00:00 2001 From: Dylan Date: Wed, 11 Oct 2023 01:01:43 +0700 Subject: [PATCH 08/12] fix lint --- src/pages/iou/steps/MoneyRequestConfirmPage.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index 286e087a9b65..5f6784ec1510 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -275,6 +275,8 @@ function MoneyRequestConfirmPage(props) { props.currentUserPersonalDetails.accountID, props.iou.currency, props.iou.category, + props.iou.receiptPath, + props.iou.receiptFilename, isDistanceRequest, requestMoney, createDistanceRequest, From b3977ca8ac895af6351850bc7e4da40172982db4 Mon Sep 17 00:00:00 2001 From: Dylan Date: Mon, 16 Oct 2023 17:15:46 +0700 Subject: [PATCH 09/12] fix lint --- src/pages/iou/steps/MoneyRequestConfirmPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index f4d4732cbd34..dc9caa990f5a 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -1,5 +1,5 @@ import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; -import {ScrollView, View} from 'react-native'; +import {View} from 'react-native'; import PropTypes from 'prop-types'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; From c376c4984809683cebd3270d959f790bf8f07d18 Mon Sep 17 00:00:00 2001 From: Dylan Date: Mon, 16 Oct 2023 22:50:57 +0700 Subject: [PATCH 10/12] fix wrong condition --- src/pages/iou/steps/MoneyRequestConfirmPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index dc9caa990f5a..c211d6f7c5ff 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -96,7 +96,7 @@ function MoneyRequestConfirmPage(props) { }, [isOffline, participants, props.iou.billable, props.policy]); useEffect(() => { - if (!props.iou.receiptPath || !props.iou.receiptSource) { + if (!props.iou.receiptPath || !props.iou.receiptFilename) { return; } FileUtils.readFileAsync(props.iou.receiptPath, props.iou.receiptSource).then((file) => { From 1fbc45b9693baccc2d39384c5231507b936c172b Mon Sep 17 00:00:00 2001 From: Dylan Date: Mon, 16 Oct 2023 23:01:25 +0700 Subject: [PATCH 11/12] fix wrong condition --- src/pages/iou/steps/MoneyRequestConfirmPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index c211d6f7c5ff..5ac28003f9ee 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -99,7 +99,7 @@ function MoneyRequestConfirmPage(props) { if (!props.iou.receiptPath || !props.iou.receiptFilename) { return; } - FileUtils.readFileAsync(props.iou.receiptPath, props.iou.receiptSource).then((file) => { + FileUtils.readFileAsync(props.iou.receiptPath, props.iou.receiptFilename).then((file) => { if (!file) { Navigation.goBack(ROUTES.MONEY_REQUEST.getRoute(iouType.current, reportID.current)); } else { From 6c9c98f84daa0dc31ea023bc5b19efbfc706dd52 Mon Sep 17 00:00:00 2001 From: Dylan Date: Mon, 16 Oct 2023 23:09:04 +0700 Subject: [PATCH 12/12] fix wrong condition --- src/pages/iou/steps/MoneyRequestConfirmPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index 5ac28003f9ee..9061d4b1193c 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -108,7 +108,7 @@ function MoneyRequestConfirmPage(props) { setReceiptFile(receipt); } }); - }, [props.iou.receiptPath, props.iou.receiptSource, isManualRequestDM]); + }, [props.iou.receiptPath, props.iou.receiptFilename, isManualRequestDM]); useEffect(() => { // ID in Onyx could change by initiating a new request in a separate browser tab or completing a request