From 6364ee97a9b52a3edd970134a2d9a786e5477459 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 5 Feb 2024 16:58:36 +0700 Subject: [PATCH 01/17] remove NewRequestAmountPage --- src/ROUTES.ts | 20 ++++++------ src/SCREENS.ts | 1 - .../MoneyRequestConfirmationList.js | 10 +++++- ...oraryForRefactorRequestConfirmationList.js | 7 ++--- .../ReportActionItem/MoneyRequestView.tsx | 4 ++- src/libs/IOUUtils.ts | 2 +- .../AppNavigator/ModalStackNavigators.tsx | 1 - src/libs/Navigation/linkingConfig/config.ts | 1 - src/libs/Navigation/types.ts | 1 - .../AttachmentPickerWithMenuItems.js | 6 ++-- .../FloatingActionButtonAndPopover.js | 7 ++++- .../request/IOURequestRedirectToStartPage.js | 2 +- .../iou/request/step/IOURequestStepAmount.js | 31 ++++++++++++++++--- .../step/withFullTransactionOrNotFound.js | 11 ++++++- 14 files changed, 71 insertions(+), 33 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index a84dc9c8f9ae..7156ecdfd2fb 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -265,10 +265,6 @@ const ROUTES = { route: ':iouType/new/:reportID?', getRoute: (iouType: string, reportID = '') => `${iouType}/new/${reportID}` as const, }, - MONEY_REQUEST_AMOUNT: { - route: ':iouType/new/amount/:reportID?', - getRoute: (iouType: string, reportID = '') => `${iouType}/new/amount/${reportID}` as const, - }, MONEY_REQUEST_PARTICIPANTS: { route: ':iouType/new/participants/:reportID?', getRoute: (iouType: string, reportID = '') => `${iouType}/new/participants/${reportID}` as const, @@ -317,17 +313,18 @@ const ROUTES = { MONEY_REQUEST_SCAN_TAB: ':iouType/new/:reportID?/scan', MONEY_REQUEST_CREATE: { - route: 'create/:iouType/start/:transactionID/:reportID', - getRoute: (iouType: ValueOf, transactionID: string, reportID: string) => `create/${iouType}/start/${transactionID}/${reportID}` as const, + route: ':action/:iouType/start/:transactionID/:reportID', + getRoute: (action: ValueOf, iouType: ValueOf, transactionID: string, reportID: string) => + `${action}/${iouType}/start/${transactionID}/${reportID}` as const, }, MONEY_REQUEST_STEP_CONFIRMATION: { route: 'create/:iouType/confirmation/:transactionID/:reportID', getRoute: (iouType: ValueOf, transactionID: string, reportID: string) => `create/${iouType}/confirmation/${transactionID}/${reportID}` as const, }, MONEY_REQUEST_STEP_AMOUNT: { - route: 'create/:iouType/amount/:transactionID/:reportID', - getRoute: (iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => - getUrlWithBackToParam(`create/${iouType}/amount/${transactionID}/${reportID}`, backTo), + route: ':action/:iouType/amount/:transactionID/:reportID', + getRoute: (action: ValueOf, iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => + getUrlWithBackToParam(`${action}/${iouType}/amount/${transactionID}/${reportID}`, backTo), }, MONEY_REQUEST_STEP_TAX_RATE: { route: 'create/:iouType/taxRate/:transactionID/:reportID?', @@ -400,8 +397,9 @@ const ROUTES = { getRoute: (iouType: ValueOf, transactionID: string, reportID: string) => `create/${iouType}/start/${transactionID}/${reportID}/distance` as const, }, MONEY_REQUEST_CREATE_TAB_MANUAL: { - route: 'create/:iouType/start/:transactionID/:reportID/manual', - getRoute: (iouType: ValueOf, transactionID: string, reportID: string) => `create/${iouType}/start/${transactionID}/${reportID}/manual` as const, + route: ':action/:iouType/start/:transactionID/:reportID/manual', + getRoute: (action: ValueOf, iouType: ValueOf, transactionID: string, reportID: string) => + `${action}/${iouType}/start/${transactionID}/${reportID}/manual` as const, }, MONEY_REQUEST_CREATE_TAB_SCAN: { route: 'create/:iouType/start/:transactionID/:reportID/scan', diff --git a/src/SCREENS.ts b/src/SCREENS.ts index 96b284dbea2f..8fc25571c9d9 100644 --- a/src/SCREENS.ts +++ b/src/SCREENS.ts @@ -145,7 +145,6 @@ const SCREENS = { STEP_TAX_AMOUNT: 'Money_Request_Step_Tax_Amount', STEP_TAX_RATE: 'Money_Request_Step_Tax_Rate', ROOT: 'Money_Request', - AMOUNT: 'Money_Request_Amount', PARTICIPANTS: 'Money_Request_Participants', CONFIRMATION: 'Money_Request_Confirmation', CURRENCY: 'Money_Request_Currency', diff --git a/src/components/MoneyRequestConfirmationList.js b/src/components/MoneyRequestConfirmationList.js index afabb40fd9f4..4f4861bdc2e5 100755 --- a/src/components/MoneyRequestConfirmationList.js +++ b/src/components/MoneyRequestConfirmationList.js @@ -645,7 +645,15 @@ function MoneyRequestConfirmationList(props) { return; } if (props.isEditingSplitBill) { - Navigation.navigate(ROUTES.EDIT_SPLIT_BILL.getRoute(props.reportID, props.reportActionID, CONST.EDIT_REQUEST_FIELD.AMOUNT)); + Navigation.navigate( + ROUTES.MONEY_REQUEST_STEP_AMOUNT.getRoute( + CONST.IOU.ACTION.EDIT, + CONST.IOU.TYPE.SPLIT, + props.transaction.transactionID, + props.reportID, + Navigation.getActiveRouteWithoutParams(), + ), + ); return; } Navigation.navigate(ROUTES.MONEY_REQUEST_AMOUNT.getRoute(props.iouType, props.reportID)); diff --git a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js index 2aff0444a59e..34212facfdc4 100755 --- a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js +++ b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js @@ -672,11 +672,8 @@ function MoneyTemporaryForRefactorRequestConfirmationList({ if (isDistanceRequest) { return; } - if (isEditingSplitBill) { - Navigation.navigate(ROUTES.EDIT_SPLIT_BILL.getRoute(reportID, reportActionID, CONST.EDIT_REQUEST_FIELD.AMOUNT)); - return; - } - Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_AMOUNT.getRoute(iouType, transaction.transactionID, reportID, Navigation.getActiveRouteWithoutParams())); + const action = isEditingSplitBill ? CONST.IOU.ACTION.EDIT : CONST.IOU.ACTION.CREATE; + Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_AMOUNT.getRoute(action, iouType, transaction.transactionID, reportID, Navigation.getActiveRouteWithoutParams())); }} style={[styles.moneyRequestMenuItem, styles.mt2]} titleStyle={styles.moneyRequestConfirmationAmount} diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 3533506797bb..1d9267f09a91 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -254,7 +254,9 @@ function MoneyRequestView({ titleStyle={styles.newKansasLarge} interactive={canEditAmount} shouldShowRightIcon={canEditAmount} - onPress={() => Navigation.navigate(ROUTES.EDIT_REQUEST.getRoute(report.reportID, CONST.EDIT_REQUEST_FIELD.AMOUNT))} + onPress={() => + Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_AMOUNT.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.REQUEST, transaction?.transactionID ?? '', report.reportID)) + } brickRoadIndicator={hasViolations('amount') || (hasErrors && transactionAmount === 0) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined} error={hasErrors && transactionAmount === 0 ? translate('common.error.enterAmount') : ''} /> diff --git a/src/libs/IOUUtils.ts b/src/libs/IOUUtils.ts index c0fb4c6195b1..fcaafd961950 100644 --- a/src/libs/IOUUtils.ts +++ b/src/libs/IOUUtils.ts @@ -17,7 +17,7 @@ function navigateToStartMoneyRequestStep(requestType: ValueOf require('../../../pages/iou/request/step/IOURequestStepTag').default as React.ComponentType, [SCREENS.MONEY_REQUEST.STEP_WAYPOINT]: () => require('../../../pages/iou/request/step/IOURequestStepWaypoint').default as React.ComponentType, [SCREENS.MONEY_REQUEST.ROOT]: () => require('../../../pages/iou/MoneyRequestSelectorPage').default as React.ComponentType, - [SCREENS.MONEY_REQUEST.AMOUNT]: () => require('../../../pages/iou/steps/NewRequestAmountPage').default as React.ComponentType, [SCREENS.MONEY_REQUEST.PARTICIPANTS]: () => require('../../../pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage').default as React.ComponentType, [SCREENS.MONEY_REQUEST.CONFIRMATION]: () => require('../../../pages/iou/steps/MoneyRequestConfirmPage').default as React.ComponentType, [SCREENS.MONEY_REQUEST.CURRENCY]: () => require('../../../pages/iou/IOUCurrencySelection').default as React.ComponentType, diff --git a/src/libs/Navigation/linkingConfig/config.ts b/src/libs/Navigation/linkingConfig/config.ts index f1c9c316fe93..7cdf9c3679fa 100644 --- a/src/libs/Navigation/linkingConfig/config.ts +++ b/src/libs/Navigation/linkingConfig/config.ts @@ -397,7 +397,6 @@ const config: LinkingOptions['config'] = { }, }, }, - [SCREENS.MONEY_REQUEST.AMOUNT]: ROUTES.MONEY_REQUEST_AMOUNT.route, [SCREENS.MONEY_REQUEST.STEP_TAX_AMOUNT]: ROUTES.MONEY_REQUEST_STEP_TAX_AMOUNT.route, [SCREENS.MONEY_REQUEST.STEP_TAX_RATE]: ROUTES.MONEY_REQUEST_STEP_TAX_RATE.route, [SCREENS.MONEY_REQUEST.PARTICIPANTS]: ROUTES.MONEY_REQUEST_PARTICIPANTS.route, diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 3c4cf17853f1..077ebd4caaac 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -194,7 +194,6 @@ type RoomInviteNavigatorParamList = { type MoneyRequestNavigatorParamList = { [SCREENS.MONEY_REQUEST.ROOT]: undefined; - [SCREENS.MONEY_REQUEST.AMOUNT]: undefined; [SCREENS.MONEY_REQUEST.PARTICIPANTS]: { iouType: string; reportID: string; diff --git a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.js b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.js index df5645ae61ad..7f10e7fa96bd 100644 --- a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.js +++ b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.js @@ -145,12 +145,14 @@ function AttachmentPickerWithMenuItems({ [CONST.IOU.TYPE.SPLIT]: { icon: Expensicons.Receipt, text: translate('iou.splitBill'), - onSelected: () => Navigation.navigate(ROUTES.MONEY_REQUEST_CREATE.getRoute(CONST.IOU.TYPE.SPLIT, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, report.reportID)), + onSelected: () => + Navigation.navigate(ROUTES.MONEY_REQUEST_CREATE.getRoute(CONST.IOU.ACTION.CREATE, CONST.IOU.TYPE.SPLIT, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, report.reportID)), }, [CONST.IOU.TYPE.REQUEST]: { icon: Expensicons.MoneyCircle, text: translate('iou.requestMoney'), - onSelected: () => Navigation.navigate(ROUTES.MONEY_REQUEST_CREATE.getRoute(CONST.IOU.TYPE.REQUEST, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, report.reportID)), + onSelected: () => + Navigation.navigate(ROUTES.MONEY_REQUEST_CREATE.getRoute(CONST.IOU.ACTION.CREATE, CONST.IOU.TYPE.REQUEST, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, report.reportID)), }, [CONST.IOU.TYPE.SEND]: { icon: Expensicons.Send, diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js index 0df490fa4466..0dc290f53f2a 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js @@ -169,7 +169,12 @@ function FloatingActionButtonAndPopover(props) { Navigation.navigate( // When starting to create a money request from the global FAB, there is not an existing report yet. A random optimistic reportID is generated and used // for all of the routes in the creation flow. - ROUTES.MONEY_REQUEST_CREATE.getRoute(CONST.IOU.TYPE.REQUEST, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, ReportUtils.generateReportID()), + ROUTES.MONEY_REQUEST_CREATE.getRoute( + CONST.IOU.ACTION.CREATE, + CONST.IOU.TYPE.REQUEST, + CONST.IOU.OPTIMISTIC_TRANSACTION_ID, + ReportUtils.generateReportID(), + ), ), ), }, diff --git a/src/pages/iou/request/IOURequestRedirectToStartPage.js b/src/pages/iou/request/IOURequestRedirectToStartPage.js index ee98c8006cdb..e4091c48f1b8 100644 --- a/src/pages/iou/request/IOURequestRedirectToStartPage.js +++ b/src/pages/iou/request/IOURequestRedirectToStartPage.js @@ -43,7 +43,7 @@ function IOURequestRedirectToStartPage({ if (iouRequestType === CONST.IOU.REQUEST_TYPE.DISTANCE) { Navigation.navigate(ROUTES.MONEY_REQUEST_CREATE_TAB_DISTANCE.getRoute(iouType, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, optimisticReportID)); } else if (iouRequestType === CONST.IOU.REQUEST_TYPE.MANUAL) { - Navigation.navigate(ROUTES.MONEY_REQUEST_CREATE_TAB_MANUAL.getRoute(iouType, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, optimisticReportID)); + Navigation.navigate(ROUTES.MONEY_REQUEST_CREATE_TAB_MANUAL.getRoute(CONST.IOU.ACTION.CREATE, iouType, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, optimisticReportID)); } else if (iouRequestType === CONST.IOU.REQUEST_TYPE.SCAN) { Navigation.navigate(ROUTES.MONEY_REQUEST_CREATE_TAB_SCAN.getRoute(iouType, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, optimisticReportID)); } diff --git a/src/pages/iou/request/step/IOURequestStepAmount.js b/src/pages/iou/request/step/IOURequestStepAmount.js index 84e0ac8533c5..4c2b24c87be2 100644 --- a/src/pages/iou/request/step/IOURequestStepAmount.js +++ b/src/pages/iou/request/step/IOURequestStepAmount.js @@ -59,7 +59,7 @@ const getTaxAmount = (transaction, defaultTaxValue, amount) => { function IOURequestStepAmount({ report, route: { - params: {iouType, reportID, transactionID, backTo, currency: selectedCurrency}, + params: {iouType, reportID, transactionID, backTo, currency: selectedCurrency, action}, }, transaction, transaction: {currency: originalCurrency}, @@ -71,6 +71,8 @@ function IOURequestStepAmount({ const focusTimeoutRef = useRef(null); const iouRequestType = getRequestType(transaction); const currency = selectedCurrency || originalCurrency; + const isEditing = action === CONST.IOU.ACTION.EDIT; + const isSplitBill = iouType === CONST.IOU.TYPE.SPLIT; const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(ReportUtils.getRootParentReport(report)); const isTaxTrackingEnabled = isPolicyExpenseChat && policy.isTaxTrackingEnabled; @@ -128,21 +130,40 @@ function IOURequestStepAmount({ Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_PARTICIPANTS.getRoute(iouType, transactionID, reportID)); }; + const saveAmountAndCurrency = ({amount}) => { + const newAmount = CurrencyUtils.convertToBackendAmount(Number.parseFloat(amount)); + + // If the value hasn't changed, don't request to save changes on the server and just close the modal + if (newAmount === TransactionUtils.getAmount(transaction) && currency === TransactionUtils.getCurrency(transaction)) { + Navigation.dismissModal(); + return; + } + + if (isSplitBill) { + IOU.setDraftSplitTransaction(transactionID, {amount: newAmount, currency}); + Navigation.goBack(backTo); + return; + } + + IOU.updateMoneyRequestAmountAndCurrency(transactionID, reportID, currency, newAmount); + Navigation.dismissModal(); + }; + return ( (textInput.current = e)} onCurrencyButtonPress={navigateToCurrencySelectionPage} - onSubmitButtonPress={navigateToNextPage} + onSubmitButtonPress={isEditing ? saveAmountAndCurrency : navigateToNextPage} selectedTab={iouRequestType} /> diff --git a/src/pages/iou/request/step/withFullTransactionOrNotFound.js b/src/pages/iou/request/step/withFullTransactionOrNotFound.js index 7cdbb3484999..801ad403af2a 100644 --- a/src/pages/iou/request/step/withFullTransactionOrNotFound.js +++ b/src/pages/iou/request/step/withFullTransactionOrNotFound.js @@ -71,7 +71,16 @@ export default function (WrappedComponent) { key: ({route}) => { const transactionID = lodashGet(route, 'params.transactionID', 0); const userAction = lodashGet(route, 'params.action', CONST.IOU.ACTION.CREATE); - return `${userAction === CONST.IOU.ACTION.CREATE ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`; + const isSplitBill = lodashGet(route, 'params.iouType', CONST.IOU.TYPE.REQUEST) === CONST.IOU.TYPE.SPLIT; + let transactionCollectionKey = ONYXKEYS.COLLECTION.TRANSACTION_DRAFT; + if (userAction === CONST.IOU.ACTION.EDIT) { + if (isSplitBill) { + transactionCollectionKey = ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT; + } else { + transactionCollectionKey = ONYXKEYS.COLLECTION.TRANSACTION; + } + } + return `${transactionCollectionKey}${transactionID}`; }, }, })(WithFullTransactionOrNotFoundWithRef); From 02a8a1897982b3d356a8541246c2545be55a5c6d Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 5 Feb 2024 17:20:20 +0700 Subject: [PATCH 02/17] fix negative amount case --- src/libs/TransactionUtils.ts | 4 ++-- src/pages/iou/request/step/IOURequestStepAmount.js | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libs/TransactionUtils.ts b/src/libs/TransactionUtils.ts index 8e48eddea0ac..6f55eb961b14 100644 --- a/src/libs/TransactionUtils.ts +++ b/src/libs/TransactionUtils.ts @@ -281,12 +281,12 @@ function getAmount(transaction: OnyxEntry, isFromExpenseReport?: bo // we need to return an opposite sign than is saved in the transaction object let amount = transaction?.modifiedAmount ?? 0; if (amount) { - return -amount; + return Math.abs(amount); } // To avoid -0 being shown, lets only change the sign if the value is other than 0. amount = transaction?.amount ?? 0; - return amount ? -amount : 0; + return amount ? Math.abs(amount) : 0; } /** diff --git a/src/pages/iou/request/step/IOURequestStepAmount.js b/src/pages/iou/request/step/IOURequestStepAmount.js index 4c2b24c87be2..fdc07f38eed6 100644 --- a/src/pages/iou/request/step/IOURequestStepAmount.js +++ b/src/pages/iou/request/step/IOURequestStepAmount.js @@ -71,9 +71,12 @@ function IOURequestStepAmount({ const focusTimeoutRef = useRef(null); const iouRequestType = getRequestType(transaction); const currency = selectedCurrency || originalCurrency; + const {amount: transactionAmount} = ReportUtils.getTransactionDetails(transaction); const isEditing = action === CONST.IOU.ACTION.EDIT; const isSplitBill = iouType === CONST.IOU.TYPE.SPLIT; + console.log(transaction); + const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(ReportUtils.getRootParentReport(report)); const isTaxTrackingEnabled = isPolicyExpenseChat && policy.isTaxTrackingEnabled; @@ -160,7 +163,7 @@ function IOURequestStepAmount({ (textInput.current = e)} onCurrencyButtonPress={navigateToCurrencySelectionPage} onSubmitButtonPress={isEditing ? saveAmountAndCurrency : navigateToNextPage} From a719511f5f925628405cb595599cf2fcb2f444d2 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 5 Feb 2024 22:57:09 +0700 Subject: [PATCH 03/17] fix the case edit split --- .../iou/request/step/IOURequestStepAmount.js | 10 ++++--- .../step/withFullTransactionOrNotFound.js | 26 +++++++++++-------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepAmount.js b/src/pages/iou/request/step/IOURequestStepAmount.js index fdc07f38eed6..63cf19299a80 100644 --- a/src/pages/iou/request/step/IOURequestStepAmount.js +++ b/src/pages/iou/request/step/IOURequestStepAmount.js @@ -2,6 +2,7 @@ import {useFocusEffect} from '@react-navigation/native'; import PropTypes from 'prop-types'; import React, {useCallback, useRef} from 'react'; import {withOnyx} from 'react-native-onyx'; +import _ from 'underscore'; import taxPropTypes from '@components/taxPropTypes'; import transactionPropTypes from '@components/transactionPropTypes'; import useLocalize from '@hooks/useLocalize'; @@ -33,6 +34,9 @@ const propTypes = { /** The transaction object being modified in Onyx */ transaction: transactionPropTypes, + /** The draft transaction of scan split bill */ + splitTransactionDraft: transactionPropTypes, + /* Onyx Props */ /** Collection of tax rates attached to a policy */ policyTaxRates: taxPropTypes, @@ -49,6 +53,7 @@ const defaultProps = { transaction: {}, policyTaxRates: {}, policy: {}, + splitTransactionDraft: {}, }; const getTaxAmount = (transaction, defaultTaxValue, amount) => { @@ -62,6 +67,7 @@ function IOURequestStepAmount({ params: {iouType, reportID, transactionID, backTo, currency: selectedCurrency, action}, }, transaction, + splitTransactionDraft, transaction: {currency: originalCurrency}, policyTaxRates, policy, @@ -71,12 +77,10 @@ function IOURequestStepAmount({ const focusTimeoutRef = useRef(null); const iouRequestType = getRequestType(transaction); const currency = selectedCurrency || originalCurrency; - const {amount: transactionAmount} = ReportUtils.getTransactionDetails(transaction); + const {amount: transactionAmount} = ReportUtils.getTransactionDetails(_.isEmpty(splitTransactionDraft) ? transaction : splitTransactionDraft); const isEditing = action === CONST.IOU.ACTION.EDIT; const isSplitBill = iouType === CONST.IOU.TYPE.SPLIT; - console.log(transaction); - const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(ReportUtils.getRootParentReport(report)); const isTaxTrackingEnabled = isPolicyExpenseChat && policy.isTaxTrackingEnabled; diff --git a/src/pages/iou/request/step/withFullTransactionOrNotFound.js b/src/pages/iou/request/step/withFullTransactionOrNotFound.js index 801ad403af2a..1999b3a90574 100644 --- a/src/pages/iou/request/step/withFullTransactionOrNotFound.js +++ b/src/pages/iou/request/step/withFullTransactionOrNotFound.js @@ -18,12 +18,16 @@ const propTypes = { /** The report corresponding to the reportID in the route params */ transaction: transactionPropTypes, + /** The draft transaction of scan split bill */ + splitTransactionDraft: transactionPropTypes, + route: IOURequestStepRoutePropTypes.isRequired, }; const defaultProps = { forwardedRef: () => {}, transaction: {}, + splitTransactionDraft: {}, }; export default function (WrappedComponent) { @@ -31,6 +35,7 @@ export default function (WrappedComponent) { function WithFullTransactionOrNotFound({forwardedRef, ...props}) { const { transaction: {transactionID}, + splitTransactionDraft: {transactionID: splitTransactionDraftID}, } = props; const isFocused = useIsFocused(); @@ -38,7 +43,7 @@ export default function (WrappedComponent) { // If the transaction does not have a transactionID, then the transaction no longer exists in Onyx as a full transaction and the not-found page should be shown. // In addition, the not-found page should be shown only if the component screen's route is active (i.e. is focused). // This is to prevent it from showing when the modal is being dismissed while navigating to a different route (e.g. on requesting money). - if (!transactionID) { + if (!transactionID && !splitTransactionDraftID) { return ; } @@ -71,16 +76,15 @@ export default function (WrappedComponent) { key: ({route}) => { const transactionID = lodashGet(route, 'params.transactionID', 0); const userAction = lodashGet(route, 'params.action', CONST.IOU.ACTION.CREATE); - const isSplitBill = lodashGet(route, 'params.iouType', CONST.IOU.TYPE.REQUEST) === CONST.IOU.TYPE.SPLIT; - let transactionCollectionKey = ONYXKEYS.COLLECTION.TRANSACTION_DRAFT; - if (userAction === CONST.IOU.ACTION.EDIT) { - if (isSplitBill) { - transactionCollectionKey = ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT; - } else { - transactionCollectionKey = ONYXKEYS.COLLECTION.TRANSACTION; - } - } - return `${transactionCollectionKey}${transactionID}`; + return `${userAction === CONST.IOU.ACTION.CREATE ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`; + }, + }, + splitTransactionDraft: { + key: ({route}) => { + const transactionID = lodashGet(route, 'params.transactionID', 0); + const userAction = lodashGet(route, 'params.action', CONST.IOU.ACTION.CREATE); + const isEditingSplitBill = userAction === CONST.IOU.ACTION.EDIT && lodashGet(route, 'params.iouType', CONST.IOU.TYPE.REQUEST) === CONST.IOU.TYPE.SPLIT; + return `${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${isEditingSplitBill ? transactionID : '0'}`; }, }, })(WithFullTransactionOrNotFoundWithRef); From ae15fd56fb9fbfb41f4ca201e0e1fb3ed1f232fa Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 5 Feb 2024 23:03:08 +0700 Subject: [PATCH 04/17] delete old page --- src/pages/iou/MoneyRequestSelectorPage.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/pages/iou/MoneyRequestSelectorPage.js b/src/pages/iou/MoneyRequestSelectorPage.js index 0a0efc38313a..b8b81a904499 100644 --- a/src/pages/iou/MoneyRequestSelectorPage.js +++ b/src/pages/iou/MoneyRequestSelectorPage.js @@ -25,7 +25,6 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import NewDistanceRequestPage from './NewDistanceRequestPage'; import IOURequestStepScan from './request/step/IOURequestStepScan'; -import NewRequestAmountPage from './steps/NewRequestAmountPage'; const propTypes = { /** React Navigation route */ @@ -127,11 +126,6 @@ function MoneyRequestSelectorPage(props) { /> )} > - {() => } {shouldDisplayDistanceRequest && ( ) : ( - + null )} From 8b9ff58d8d120f31934862eaa5a39420472b5245 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 19 Feb 2024 15:13:58 +0700 Subject: [PATCH 05/17] fix ts check --- src/libs/Navigation/Navigation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index 8009c963ade7..4e56586bf1f5 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -94,7 +94,7 @@ function getActiveRouteIndex(stateOrRoute: StateOrRoute, index?: number): number function parseHybridAppUrl(url: HybridAppRoute | Route): Route { switch (url) { case HYBRID_APP_ROUTES.MONEY_REQUEST_CREATE: - return ROUTES.MONEY_REQUEST_CREATE.getRoute(CONST.IOU.TYPE.REQUEST, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, ReportUtils.generateReportID()); + return ROUTES.MONEY_REQUEST_CREATE.getRoute(CONST.IOU.ACTION.CREATE, CONST.IOU.TYPE.REQUEST, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, ReportUtils.generateReportID()); default: return url; } From b10eb48614466d94b0bed878b37baad4ab841a2a Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 20 Mar 2024 11:00:38 +0700 Subject: [PATCH 06/17] resolve another conflict --- .../SidebarScreen/FloatingActionButtonAndPopover.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js index 0673f22a7261..ec27112ab4b7 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js @@ -170,16 +170,7 @@ function FloatingActionButtonAndPopover(props) { CONST.IOU.TYPE.REQUEST, // When starting to create a money request from the global FAB, there is not an existing report yet. A random optimistic reportID is generated and used // for all of the routes in the creation flow. -<<<<<<< HEAD - ROUTES.MONEY_REQUEST_CREATE.getRoute( - CONST.IOU.ACTION.CREATE, - CONST.IOU.TYPE.REQUEST, - CONST.IOU.OPTIMISTIC_TRANSACTION_ID, - ReportUtils.generateReportID(), - ), -======= ReportUtils.generateReportID(), ->>>>>>> main ), ), }, From 15d6a41e79d5688c1789d82b659c567b62311319 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 20 Mar 2024 11:15:47 +0700 Subject: [PATCH 07/17] fix ts check --- src/components/MoneyRequestConfirmationList.tsx | 6 ++---- src/libs/actions/IOU.ts | 2 +- src/pages/iou/request/step/IOURequestStepAmount.js | 4 +++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/MoneyRequestConfirmationList.tsx b/src/components/MoneyRequestConfirmationList.tsx index d54636c56c6e..d3ff5f974e6b 100755 --- a/src/components/MoneyRequestConfirmationList.tsx +++ b/src/components/MoneyRequestConfirmationList.tsx @@ -645,10 +645,8 @@ function MoneyRequestConfirmationList({ if (isDistanceRequest) { return; } - const action = props.isEditingSplitBill ? CONST.IOU.ACTION.EDIT : CONST.IOU.ACTION.CREATE; - Navigation.navigate( - ROUTES.MONEY_REQUEST_STEP_AMOUNT.getRoute(action, props.iouType, props.transaction.transactionID, props.reportID, Navigation.getActiveRouteWithoutParams()), - ); + const action = isEditingSplitBill ? CONST.IOU.ACTION.EDIT : CONST.IOU.ACTION.CREATE; + Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_AMOUNT.getRoute(action, iouType, transaction?.transactionID ?? '', reportID, Navigation.getActiveRouteWithoutParams())); }} style={[styles.moneyRequestMenuItem, styles.mt2]} titleStyle={styles.moneyRequestConfirmationAmount} diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 91a74c593926..7a9e9989652e 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -312,7 +312,7 @@ function updateMoneyRequestTypeParams(routes: StackNavigationState, reportID: string) { clearMoneyRequest(CONST.IOU.OPTIMISTIC_TRANSACTION_ID); - Navigation.navigate(ROUTES.MONEY_REQUEST_CREATE.getRoute(iouType, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, reportID)); + Navigation.navigate(ROUTES.MONEY_REQUEST_CREATE.getRoute(CONST.IOU.ACTION.CREATE, iouType, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, reportID)); } // eslint-disable-next-line @typescript-eslint/naming-convention diff --git a/src/pages/iou/request/step/IOURequestStepAmount.js b/src/pages/iou/request/step/IOURequestStepAmount.js index 6fc6b433d2fb..44944d41e2c9 100644 --- a/src/pages/iou/request/step/IOURequestStepAmount.js +++ b/src/pages/iou/request/step/IOURequestStepAmount.js @@ -1,5 +1,6 @@ import {useFocusEffect} from '@react-navigation/native'; import lodashGet from 'lodash/get'; +import lodashIsEmpty from 'lodash/isEmpty'; import PropTypes from 'prop-types'; import React, {useCallback, useEffect, useRef} from 'react'; import {withOnyx} from 'react-native-onyx'; @@ -86,7 +87,8 @@ function IOURequestStepAmount({ const iouRequestType = getRequestType(transaction); const isEditing = action === CONST.IOU.ACTION.EDIT; const isSplitBill = iouType === CONST.IOU.TYPE.SPLIT; - const {amount: transactionAmount} = ReportUtils.getTransactionDetails(isEditing && isSplitBill ? splitDraftTransaction : transaction); + const isEditingSplitBill = isEditing && isSplitBill; + const {amount: transactionAmount} = ReportUtils.getTransactionDetails(isEditingSplitBill && !lodashIsEmpty(splitDraftTransaction) ? splitDraftTransaction : transaction); const taxRates = lodashGet(policy, 'taxRates', {}); const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(ReportUtils.getRootParentReport(report)); From fe2e60c9fd70f8de3b27a6192f5f2a5d2d05260c Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 21 Mar 2024 17:06:54 +0700 Subject: [PATCH 08/17] remove unnecessary code --- src/ROUTES.ts | 4 - src/SCREENS.ts | 1 - .../MoneyRequestConfirmationList.tsx | 5 +- .../AppNavigator/ModalStackNavigators.tsx | 1 - src/libs/Navigation/linkingConfig/config.ts | 1 - src/libs/Navigation/types.ts | 1 - src/pages/EditRequestPage.js | 37 +--- src/pages/EditSplitBillPage.tsx | 28 +-- src/pages/iou/steps/NewRequestAmountPage.js | 195 ------------------ 9 files changed, 6 insertions(+), 267 deletions(-) delete mode 100644 src/pages/iou/steps/NewRequestAmountPage.js diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 6868773a8290..7a7cb8d3e3ef 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -276,10 +276,6 @@ const ROUTES = { route: 'r/:reportID/invite', getRoute: (reportID: string) => `r/${reportID}/invite` as const, }, - MONEY_REQUEST_AMOUNT: { - route: ':iouType/new/amount/:reportID?', - getRoute: (iouType: string, reportID = '') => `${iouType}/new/amount/${reportID}` as const, - }, MONEY_REQUEST_PARTICIPANTS: { route: ':iouType/new/participants/:reportID?', getRoute: (iouType: string, reportID = '') => `${iouType}/new/participants/${reportID}` as const, diff --git a/src/SCREENS.ts b/src/SCREENS.ts index 4d4e9ea327c6..84739d2da010 100644 --- a/src/SCREENS.ts +++ b/src/SCREENS.ts @@ -149,7 +149,6 @@ const SCREENS = { STEP_WAYPOINT: 'Money_Request_Step_Waypoint', STEP_TAX_AMOUNT: 'Money_Request_Step_Tax_Amount', STEP_TAX_RATE: 'Money_Request_Step_Tax_Rate', - AMOUNT: 'Money_Request_Amount', PARTICIPANTS: 'Money_Request_Participants', CONFIRMATION: 'Money_Request_Confirmation', CURRENCY: 'Money_Request_Currency', diff --git a/src/components/MoneyRequestConfirmationList.tsx b/src/components/MoneyRequestConfirmationList.tsx index 63ca7c016bfc..7d5a0527fc10 100755 --- a/src/components/MoneyRequestConfirmationList.tsx +++ b/src/components/MoneyRequestConfirmationList.tsx @@ -645,8 +645,9 @@ function MoneyRequestConfirmationList({ if (isDistanceRequest) { return; } - const action = isEditingSplitBill ? CONST.IOU.ACTION.EDIT : CONST.IOU.ACTION.CREATE; - Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_AMOUNT.getRoute(action, iouType, transaction?.transactionID ?? '', reportID, Navigation.getActiveRouteWithoutParams())); + Navigation.navigate( + ROUTES.MONEY_REQUEST_STEP_AMOUNT.getRoute(CONST.IOU.ACTION.EDIT, iouType, transaction?.transactionID ?? '', reportID, Navigation.getActiveRouteWithoutParams()), + ); }} style={[styles.moneyRequestMenuItem, styles.mt2]} titleStyle={styles.moneyRequestConfirmationAmount} diff --git a/src/libs/Navigation/AppNavigator/ModalStackNavigators.tsx b/src/libs/Navigation/AppNavigator/ModalStackNavigators.tsx index bd5bfc46134a..22f06089ab05 100644 --- a/src/libs/Navigation/AppNavigator/ModalStackNavigators.tsx +++ b/src/libs/Navigation/AppNavigator/ModalStackNavigators.tsx @@ -94,7 +94,6 @@ const MoneyRequestModalStackNavigator = createModalStackNavigator require('../../../pages/iou/request/step/IOURequestStepScan').default as React.ComponentType, [SCREENS.MONEY_REQUEST.STEP_TAG]: () => require('../../../pages/iou/request/step/IOURequestStepTag').default as React.ComponentType, [SCREENS.MONEY_REQUEST.STEP_WAYPOINT]: () => require('../../../pages/iou/request/step/IOURequestStepWaypoint').default as React.ComponentType, - [SCREENS.MONEY_REQUEST.AMOUNT]: () => require('../../../pages/iou/steps/NewRequestAmountPage').default as React.ComponentType, [SCREENS.MONEY_REQUEST.PARTICIPANTS]: () => require('../../../pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage').default as React.ComponentType, [SCREENS.MONEY_REQUEST.CONFIRMATION]: () => require('../../../pages/iou/steps/MoneyRequestConfirmPage').default as React.ComponentType, [SCREENS.MONEY_REQUEST.CURRENCY]: () => require('../../../pages/iou/IOUCurrencySelection').default as React.ComponentType, diff --git a/src/libs/Navigation/linkingConfig/config.ts b/src/libs/Navigation/linkingConfig/config.ts index 130fdf23732f..bc9143dfacc3 100644 --- a/src/libs/Navigation/linkingConfig/config.ts +++ b/src/libs/Navigation/linkingConfig/config.ts @@ -503,7 +503,6 @@ const config: LinkingOptions['config'] = { [SCREENS.MONEY_REQUEST.STEP_SCAN]: ROUTES.MONEY_REQUEST_STEP_SCAN.route, [SCREENS.MONEY_REQUEST.STEP_TAG]: ROUTES.MONEY_REQUEST_STEP_TAG.route, [SCREENS.MONEY_REQUEST.STEP_WAYPOINT]: ROUTES.MONEY_REQUEST_STEP_WAYPOINT.route, - [SCREENS.MONEY_REQUEST.AMOUNT]: ROUTES.MONEY_REQUEST_AMOUNT.route, [SCREENS.MONEY_REQUEST.STEP_TAX_AMOUNT]: ROUTES.MONEY_REQUEST_STEP_TAX_AMOUNT.route, [SCREENS.MONEY_REQUEST.STEP_TAX_RATE]: ROUTES.MONEY_REQUEST_STEP_TAX_RATE.route, [SCREENS.MONEY_REQUEST.PARTICIPANTS]: ROUTES.MONEY_REQUEST_PARTICIPANTS.route, diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 9b0d9ce4decc..5a12b2168d9e 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -315,7 +315,6 @@ type RoomInviteNavigatorParamList = { }; type MoneyRequestNavigatorParamList = { - [SCREENS.MONEY_REQUEST.AMOUNT]: undefined; [SCREENS.MONEY_REQUEST.PARTICIPANTS]: { iouType: string; reportID: string; diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index de17d16a7c38..ab0fd6b1a609 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -8,7 +8,6 @@ import ScreenWrapper from '@components/ScreenWrapper'; import tagPropTypes from '@components/tagPropTypes'; import transactionPropTypes from '@components/transactionPropTypes'; import compose from '@libs/compose'; -import * as CurrencyUtils from '@libs/CurrencyUtils'; import * as IOUUtils from '@libs/IOUUtils'; import Navigation from '@libs/Navigation/Navigation'; import * as OptionsListUtils from '@libs/OptionsListUtils'; @@ -18,8 +17,6 @@ import * as TransactionUtils from '@libs/TransactionUtils'; import * as IOU from '@userActions/IOU'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import ROUTES from '@src/ROUTES'; -import EditRequestAmountPage from './EditRequestAmountPage'; import EditRequestDistancePage from './EditRequestDistancePage'; import EditRequestReceiptPage from './EditRequestReceiptPage'; import EditRequestTagPage from './EditRequestTagPage'; @@ -75,9 +72,8 @@ const defaultProps = { function EditRequestPage({report, route, policy, policyCategories, policyTags, parentReportActions, transaction}) { const parentReportActionID = lodashGet(report, 'parentReportActionID', '0'); const parentReportAction = lodashGet(parentReportActions, parentReportActionID, {}); - const {amount: transactionAmount, currency: transactionCurrency, tag: transactionTag} = ReportUtils.getTransactionDetails(transaction); + const {tag: transactionTag} = ReportUtils.getTransactionDetails(transaction); - const defaultCurrency = lodashGet(route, 'params.currency', '') || transactionCurrency; const fieldToEdit = lodashGet(route, ['params', 'field'], ''); const tagIndex = Number(lodashGet(route, ['params', 'tagIndex'], undefined)); @@ -104,22 +100,6 @@ function EditRequestPage({report, route, policy, policyCategories, policyTags, p }); }, [parentReportAction, fieldToEdit]); - const saveAmountAndCurrency = useCallback( - ({amount, currency: newCurrency}) => { - const newAmount = CurrencyUtils.convertToBackendAmount(Number.parseFloat(amount)); - - // If the value hasn't changed, don't request to save changes on the server and just close the modal - if (newAmount === TransactionUtils.getAmount(transaction) && newCurrency === TransactionUtils.getCurrency(transaction)) { - Navigation.dismissModal(); - return; - } - - IOU.updateMoneyRequestAmountAndCurrency(transaction.transactionID, report.reportID, newCurrency, newAmount, policy, policyTags, policyCategories); - Navigation.dismissModal(); - }, - [transaction, report, policy, policyTags, policyCategories], - ); - const saveTag = useCallback( ({tag: newTag}) => { let updatedTag = newTag; @@ -140,21 +120,6 @@ function EditRequestPage({report, route, policy, policyCategories, policyTags, p [tag, transaction.transactionID, report.reportID, transactionTag, tagIndex, policy, policyTags, policyCategories], ); - if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.AMOUNT) { - return ( - { - const activeRoute = encodeURIComponent(Navigation.getActiveRouteWithoutParams()); - Navigation.navigate(ROUTES.EDIT_CURRENCY_REQUEST.getRoute(report.reportID, defaultCurrency, activeRoute)); - }} - /> - ); - } - if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.TAG && shouldShowTags) { return ( ; function EditSplitBillPage({route, transaction, draftTransaction, report}: EditSplitBillProps) { - const {field: fieldToEdit, reportID, reportActionID, currency, tagIndex} = route.params; + const {field: fieldToEdit, reportID, reportActionID, tagIndex} = route.params; - const {amount: transactionAmount, currency: transactionCurrency, tag: transactionTag} = ReportUtils.getTransactionDetails(draftTransaction ?? transaction) ?? {}; + const {tag: transactionTag} = ReportUtils.getTransactionDetails(draftTransaction ?? transaction) ?? {}; - const defaultCurrency = currency ?? transactionCurrency; function navigateBackToSplitDetails() { Navigation.navigate(ROUTES.SPLIT_BILL_DETAILS.getRoute(reportID, reportActionID)); } @@ -53,27 +50,6 @@ function EditSplitBillPage({route, transaction, draftTransaction, report}: EditS navigateBackToSplitDetails(); }; - if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.AMOUNT) { - return ( - { - const amount = CurrencyUtils.convertToBackendAmount(Number.parseFloat(transactionChanges.amount)); - - setDraftSplitTransaction({ - amount, - currency: transactionChanges.currency, - }); - }} - onNavigateToCurrency={() => { - const activeRoute = encodeURIComponent(Navigation.getActiveRouteWithoutParams()); - Navigation.navigate(ROUTES.EDIT_SPLIT_BILL_CURRENCY.getRoute(reportID, reportActionID, defaultCurrency, activeRoute)); - }} - /> - ); - } - if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.TAG) { return ( { - focusTimeoutRef.current = setTimeout(() => textInput.current && textInput.current.focus(), CONST.ANIMATED_TRANSITION); - return () => { - if (!focusTimeoutRef.current) { - return; - } - clearTimeout(focusTimeoutRef.current); - }; - }, []), - ); - - // Because we use Onyx to store IOU info, when we try to make two different money requests from different tabs, - // it can result in an IOU sent with improper values. In such cases we want to reset the flow and redirect the user to the first step of the IOU. - useEffect(() => { - if (isEditing) { - // 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) { - return; - } - Navigation.goBack(ROUTES.MONEY_REQUEST.getRoute(iouType, reportID), true); - return; - } - const moneyRequestID = `${iouType}${reportID}`; - const shouldReset = iou.id !== moneyRequestID; - if (shouldReset) { - IOU.resetMoneyRequestInfo(moneyRequestID); - } - - if (!isDistanceRequestTab && (_.isEmpty(iou.participants) || iou.amount === 0 || shouldReset)) { - Navigation.goBack(ROUTES.MONEY_REQUEST.getRoute(iouType, reportID), true); - } - } - - return () => { - prevMoneyRequestID.current = iou.id; - }; - }, [iou.participants, iou.amount, iou.id, isEditing, iouType, reportID, isDistanceRequestTab]); - - const navigateBack = () => { - Navigation.goBack(isEditing ? ROUTES.MONEY_REQUEST_CONFIRMATION.getRoute(iouType, reportID) : ROUTES.HOME); - }; - - const navigateToCurrencySelectionPage = () => { - // If the money request being created is a distance request, don't allow the user to choose the currency. - // Only USD is allowed for distance requests. - if (isDistanceRequestTab) { - return; - } - - // Remove query from the route and encode it. - const activeRoute = encodeURIComponent(Navigation.getActiveRouteWithoutParams()); - Navigation.navigate(ROUTES.MONEY_REQUEST_CURRENCY.getRoute(iouType, reportID, currency, activeRoute)); - }; - - const navigateToNextPage = ({amount}) => { - const amountInSmallestCurrencyUnits = CurrencyUtils.convertToBackendAmount(Number.parseFloat(amount)); - IOU.setMoneyRequestAmount(amountInSmallestCurrencyUnits); - IOU.setMoneyRequestCurrency(currency); - - if (isEditing) { - Navigation.goBack(ROUTES.MONEY_REQUEST_CONFIRMATION.getRoute(iouType, reportID)); - return; - } - - IOU.navigateToNextPage(iou, iouType, report); - }; - - const content = ( - (textInput.current = e)} - onCurrencyButtonPress={navigateToCurrencySelectionPage} - onSubmitButtonPress={navigateToNextPage} - selectedTab={selectedTab} - /> - ); - - // ScreenWrapper is only needed in edit mode because we have a dedicated route for the edit amount page (MoneyRequestEditAmountPage). - // The rest of the cases this component is rendered through which has it's own ScreenWrapper - if (!isEditing) { - return content; - } - - return ( - - {({safeAreaPaddingBottomStyle}) => ( - - - - {content} - - - )} - - ); -} - -NewRequestAmountPage.propTypes = propTypes; -NewRequestAmountPage.defaultProps = defaultProps; -NewRequestAmountPage.displayName = 'NewRequestAmountPage'; - -export default withOnyx({ - iou: {key: ONYXKEYS.IOU}, - report: { - key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${lodashGet(route, 'params.reportID', '')}`, - }, - selectedTab: { - key: `${ONYXKEYS.COLLECTION.SELECTED_TAB}${CONST.TAB.RECEIPT_TAB_ID}`, - }, -})(NewRequestAmountPage); From d11cf7364741cfe6fb8e60a0097fc1a002749557 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 22 Mar 2024 16:27:01 +0700 Subject: [PATCH 09/17] add type for step amount page --- src/libs/Navigation/types.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 210c1fd006b4..80021e92a0fd 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -323,6 +323,13 @@ type RoomInviteNavigatorParamList = { }; type MoneyRequestNavigatorParamList = { + [SCREENS.MONEY_REQUEST.STEP_AMOUNT]: { + action: ValueOf; + iouType: ValueOf; + transactionID: string; + reportID: string; + backTo: string; + }; [SCREENS.MONEY_REQUEST.PARTICIPANTS]: { iouType: string; reportID: string; From a20a9e59b5658dbe34341248525620910c8cb973 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 22 Mar 2024 22:30:52 +0700 Subject: [PATCH 10/17] update route of currency page --- src/ROUTES.ts | 6 +++--- src/pages/iou/request/step/IOURequestStepAmount.js | 2 +- src/pages/iou/request/step/IOURequestStepTaxAmountPage.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 7b4b8a97bdc9..8c912d80f14b 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -334,9 +334,9 @@ const ROUTES = { getUrlWithBackToParam(`${action}/${iouType}/category/${transactionID}/${reportID}${reportActionID ? `/${reportActionID}` : ''}`, backTo), }, MONEY_REQUEST_STEP_CURRENCY: { - route: 'create/:iouType/currency/:transactionID/:reportID/:pageIndex?', - getRoute: (iouType: ValueOf, transactionID: string, reportID: string, pageIndex = '', backTo = '') => - getUrlWithBackToParam(`create/${iouType}/currency/${transactionID}/${reportID}/${pageIndex}`, backTo), + route: ':action/:iouType/currency/:transactionID/:reportID/:pageIndex?', + getRoute: (action: ValueOf, iouType: ValueOf, transactionID: string, reportID: string, pageIndex = '', backTo = '') => + getUrlWithBackToParam(`${action}/${iouType}/currency/${transactionID}/${reportID}/${pageIndex}`, backTo), }, MONEY_REQUEST_STEP_DATE: { route: ':action/:iouType/date/:transactionID/:reportID', diff --git a/src/pages/iou/request/step/IOURequestStepAmount.js b/src/pages/iou/request/step/IOURequestStepAmount.js index 44944d41e2c9..bf664ace5c6d 100644 --- a/src/pages/iou/request/step/IOURequestStepAmount.js +++ b/src/pages/iou/request/step/IOURequestStepAmount.js @@ -127,7 +127,7 @@ function IOURequestStepAmount({ }; const navigateToCurrencySelectionPage = () => { - Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CURRENCY.getRoute(iouType, transactionID, reportID, backTo ? 'confirm' : '', Navigation.getActiveRouteWithoutParams())); + Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CURRENCY.getRoute(action, iouType, transactionID, reportID, backTo ? 'confirm' : '', Navigation.getActiveRouteWithoutParams())); }; /** diff --git a/src/pages/iou/request/step/IOURequestStepTaxAmountPage.js b/src/pages/iou/request/step/IOURequestStepTaxAmountPage.js index 7a75e9f48805..e568cf917781 100644 --- a/src/pages/iou/request/step/IOURequestStepTaxAmountPage.js +++ b/src/pages/iou/request/step/IOURequestStepTaxAmountPage.js @@ -112,7 +112,7 @@ function IOURequestStepTaxAmountPage({ // If the money request being created is a distance request, don't allow the user to choose the currency. // Only USD is allowed for distance requests. // Remove query from the route and encode it. - Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CURRENCY.getRoute(iouType, transactionID, reportID, backTo ? 'confirm' : '', Navigation.getActiveRouteWithoutParams())); + Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CURRENCY.getRoute(CONST.IOU.ACTION.CREATE, iouType, transactionID, reportID, backTo ? 'confirm' : '', Navigation.getActiveRouteWithoutParams())); }; const updateTaxAmount = (currentAmount) => { From 78195aeb07046692812b17ee619e4944c3d14510 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 25 Mar 2024 14:10:14 +0700 Subject: [PATCH 11/17] add temporary solution for edit currency --- src/libs/actions/IOU.ts | 7 ++--- src/libs/actions/TransactionEdit.ts | 1 - .../iou/request/step/IOURequestStepAmount.js | 27 ++++++++++++++++++- .../request/step/IOURequestStepCurrency.js | 22 ++++++++++----- .../step/IOURequestStepTaxAmountPage.js | 4 ++- 5 files changed, 49 insertions(+), 12 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 5632268ef6ca..24786321b5eb 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -343,12 +343,13 @@ function setMoneyRequestCreated(transactionID: string, created: string, isDraft: } // eslint-disable-next-line @typescript-eslint/naming-convention -function setMoneyRequestCurrency_temporaryForRefactor(transactionID: string, currency: string, removeOriginalCurrency = false) { +function setMoneyRequestCurrency_temporaryForRefactor(transactionID: string, currency: string, removeOriginalCurrency = false, isEditing = false) { + const fieldToUpdate = isEditing ? 'modifiedCurrency' : 'currency'; if (removeOriginalCurrency) { - Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {currency, originalCurrency: null}); + Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {[fieldToUpdate]: currency, originalCurrency: null}); return; } - Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {currency}); + Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {[fieldToUpdate]: currency}); } // eslint-disable-next-line @typescript-eslint/naming-convention diff --git a/src/libs/actions/TransactionEdit.ts b/src/libs/actions/TransactionEdit.ts index b1710aa72cbb..9d5ebcd1ec88 100644 --- a/src/libs/actions/TransactionEdit.ts +++ b/src/libs/actions/TransactionEdit.ts @@ -38,5 +38,4 @@ function restoreOriginalTransactionFromBackup(transactionID: string) { }, }); } - export {createBackupTransaction, removeBackupTransaction, restoreOriginalTransactionFromBackup}; diff --git a/src/pages/iou/request/step/IOURequestStepAmount.js b/src/pages/iou/request/step/IOURequestStepAmount.js index bf664ace5c6d..f61bab102d2a 100644 --- a/src/pages/iou/request/step/IOURequestStepAmount.js +++ b/src/pages/iou/request/step/IOURequestStepAmount.js @@ -7,6 +7,7 @@ import {withOnyx} from 'react-native-onyx'; import taxPropTypes from '@components/taxPropTypes'; import transactionPropTypes from '@components/transactionPropTypes'; import useLocalize from '@hooks/useLocalize'; +import * as TransactionEdit from '@libs/actions/TransactionEdit'; import compose from '@libs/compose'; import * as CurrencyUtils from '@libs/CurrencyUtils'; import Navigation from '@libs/Navigation/Navigation'; @@ -38,6 +39,9 @@ const propTypes = { /** The draft transaction that holds data to be persisted on the current transaction */ splitDraftTransaction: transactionPropTypes, + /** The draft transaction object being modified in Onyx */ + draftTransaction: transactionPropTypes, + /** The policy of the report */ policy: PropTypes.shape({ /** @@ -61,6 +65,7 @@ const defaultProps = { report: {}, transaction: {}, splitDraftTransaction: {}, + draftTransaction: {}, policy: {}, }; @@ -76,7 +81,7 @@ function IOURequestStepAmount({ }, transaction, splitDraftTransaction, - transaction: {currency}, + draftTransaction, policy, }) { const {translate} = useLocalize(); @@ -89,6 +94,7 @@ function IOURequestStepAmount({ const isSplitBill = iouType === CONST.IOU.TYPE.SPLIT; const isEditingSplitBill = isEditing && isSplitBill; const {amount: transactionAmount} = ReportUtils.getTransactionDetails(isEditingSplitBill && !lodashIsEmpty(splitDraftTransaction) ? splitDraftTransaction : transaction); + const {currency} = ReportUtils.getTransactionDetails(isEditing ? draftTransaction : transaction); const taxRates = lodashGet(policy, 'taxRates', {}); const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(ReportUtils.getRootParentReport(report)); @@ -107,6 +113,19 @@ function IOURequestStepAmount({ ); useEffect(() => { + if (isEditing) { + // A temporary solution to not prevent users from editing the currency + // We create a backup transaction and use it to save the currency and remove this transaction backup if we don't save the amount + // It should be removed after this issue https://github.com/Expensify/App/issues/34607 is fixed + TransactionEdit.createBackupTransaction(isEditingSplitBill && !lodashIsEmpty(splitDraftTransaction) ? splitDraftTransaction : transaction); + + return () => { + if (isSaveButtonPressed.current) { + return; + } + TransactionEdit.removeBackupTransaction(transaction.transactionID || ''); + }; + } if (transaction.originalCurrency) { originalCurrency.current = transaction.originalCurrency; } else { @@ -221,5 +240,11 @@ export default compose( policy: { key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`, }, + draftTransaction: { + key: ({route}) => { + const transactionID = lodashGet(route, 'params.transactionID', 0); + return `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`; + }, + }, }), )(IOURequestStepAmount); diff --git a/src/pages/iou/request/step/IOURequestStepCurrency.js b/src/pages/iou/request/step/IOURequestStepCurrency.js index 43e4e9bf0eaa..ec8803937da0 100644 --- a/src/pages/iou/request/step/IOURequestStepCurrency.js +++ b/src/pages/iou/request/step/IOURequestStepCurrency.js @@ -1,4 +1,5 @@ import Str from 'expensify-common/lib/str'; +import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; import React, {useMemo, useRef, useState} from 'react'; import {Keyboard} from 'react-native'; @@ -11,7 +12,9 @@ import useLocalize from '@hooks/useLocalize'; import compose from '@libs/compose'; import * as CurrencyUtils from '@libs/CurrencyUtils'; import Navigation from '@libs/Navigation/Navigation'; +import * as ReportUtils from '@libs/ReportUtils'; import * as IOU from '@userActions/IOU'; +import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES, {getUrlWithBackToParam} from '@src/ROUTES'; import IOURequestStepRoutePropTypes from './IOURequestStepRoutePropTypes'; @@ -40,25 +43,26 @@ const propTypes = { ), /* Onyx Props */ - /** The transaction being modified */ - transaction: transactionPropTypes, + /** The draft transaction object being modified in Onyx */ + draftTransaction: transactionPropTypes, }; const defaultProps = { currencyList: {}, - transaction: {}, + draftTransaction: {}, }; function IOURequestStepCurrency({ currencyList, route: { - params: {backTo, iouType, pageIndex, reportID, transactionID}, + params: {backTo, iouType, pageIndex, reportID, transactionID, action}, }, - transaction: {currency}, + draftTransaction, }) { const {translate} = useLocalize(); const [searchValue, setSearchValue] = useState(''); const optionsSelectorRef = useRef(); + const {currency} = ReportUtils.getTransactionDetails(draftTransaction); const navigateBack = () => { // If the currency selection was done from the confirmation step (eg. + > request money > manual > confirm > amount > currency) @@ -79,7 +83,7 @@ function IOURequestStepCurrency({ */ const confirmCurrencySelection = (option) => { Keyboard.dismiss(); - IOU.setMoneyRequestCurrency_temporaryForRefactor(transactionID, option.currencyCode); + IOU.setMoneyRequestCurrency_temporaryForRefactor(transactionID, option.currencyCode, false, action === CONST.IOU.ACTION.EDIT); navigateBack(); }; @@ -154,5 +158,11 @@ export default compose( withFullTransactionOrNotFound, withOnyx({ currencyList: {key: ONYXKEYS.CURRENCY_LIST}, + draftTransaction: { + key: ({route}) => { + const transactionID = lodashGet(route, 'params.transactionID', 0); + return `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`; + }, + }, }), )(IOURequestStepCurrency); diff --git a/src/pages/iou/request/step/IOURequestStepTaxAmountPage.js b/src/pages/iou/request/step/IOURequestStepTaxAmountPage.js index e568cf917781..a45263d8bee1 100644 --- a/src/pages/iou/request/step/IOURequestStepTaxAmountPage.js +++ b/src/pages/iou/request/step/IOURequestStepTaxAmountPage.js @@ -112,7 +112,9 @@ function IOURequestStepTaxAmountPage({ // If the money request being created is a distance request, don't allow the user to choose the currency. // Only USD is allowed for distance requests. // Remove query from the route and encode it. - Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CURRENCY.getRoute(CONST.IOU.ACTION.CREATE, iouType, transactionID, reportID, backTo ? 'confirm' : '', Navigation.getActiveRouteWithoutParams())); + Navigation.navigate( + ROUTES.MONEY_REQUEST_STEP_CURRENCY.getRoute(CONST.IOU.ACTION.CREATE, iouType, transactionID, reportID, backTo ? 'confirm' : '', Navigation.getActiveRouteWithoutParams()), + ); }; const updateTaxAmount = (currentAmount) => { From db1aa3f0812072464195367ab8f5b58fd9cd299a Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 25 Mar 2024 14:11:29 +0700 Subject: [PATCH 12/17] remove un-use function --- src/libs/actions/IOU.ts | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 24786321b5eb..a71a7a640e79 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -4978,41 +4978,6 @@ function setShownHoldUseExplanation() { Onyx.set(ONYXKEYS.NVP_HOLD_USE_EXPLAINED, true); } -/** Navigates to the next IOU page based on where the IOU request was started */ -function navigateToNextPage(iou: OnyxEntry, iouType: string, report?: OnyxTypes.Report, path = '') { - const moneyRequestID = `${iouType}${report?.reportID ?? ''}`; - const shouldReset = iou?.id !== moneyRequestID && !!report?.reportID; - - // If the money request ID in Onyx does not match the ID from params, we want to start a new request - // with the ID from params. We need to clear the participants in case the new request is initiated from FAB. - if (shouldReset) { - resetMoneyRequestInfo(moneyRequestID); - } - - // If we're adding a receipt, that means the user came from the confirmation page and we need to navigate back to it. - if (path.slice(1) === ROUTES.MONEY_REQUEST_RECEIPT.getRoute(iouType, report?.reportID)) { - Navigation.navigate(ROUTES.MONEY_REQUEST_CONFIRMATION.getRoute(iouType, report?.reportID)); - return; - } - - // If a request is initiated on a report, skip the participants selection step and navigate to the confirmation page. - if (report?.reportID) { - // If the report is iou or expense report, we should get the chat report to set participant for request money - const chatReport = ReportUtils.isMoneyRequestReport(report) ? ReportUtils.getReport(report.chatReportID) : report; - // Reinitialize the participants when the money request ID in Onyx does not match the ID from params - if (!iou?.participants?.length || shouldReset) { - const currentUserAccountID = currentUserPersonalDetails.accountID; - const participants: Participant[] = ReportUtils.isPolicyExpenseChat(chatReport) - ? [{reportID: chatReport?.reportID, isPolicyExpenseChat: true, selected: true}] - : (chatReport?.participantAccountIDs ?? []).filter((accountID) => currentUserAccountID !== accountID).map((accountID) => ({accountID, selected: true})); - setMoneyRequestParticipants(participants); - } - Navigation.navigate(ROUTES.MONEY_REQUEST_CONFIRMATION.getRoute(iouType, report.reportID)); - return; - } - Navigation.navigate(ROUTES.MONEY_REQUEST_PARTICIPANTS.getRoute(iouType)); -} - /** * When the money request or split bill creation flow is initialized via FAB, the reportID is not passed as a navigation * parameter. @@ -5195,7 +5160,6 @@ export { setMoneyRequestTaxAmount, setMoneyRequestTaxRate, setShownHoldUseExplanation, - navigateToNextPage, updateMoneyRequestDate, updateMoneyRequestBillable, updateMoneyRequestMerchant, From 8982f33cf8be5360430efef653fba6507a3a65b3 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 25 Mar 2024 16:27:20 +0700 Subject: [PATCH 13/17] remove edit amount page and revert the unnecessary change --- src/libs/actions/TransactionEdit.ts | 1 + src/pages/EditRequestAmountPage.js | 66 ----------------------------- 2 files changed, 1 insertion(+), 66 deletions(-) delete mode 100644 src/pages/EditRequestAmountPage.js diff --git a/src/libs/actions/TransactionEdit.ts b/src/libs/actions/TransactionEdit.ts index 9d5ebcd1ec88..b1710aa72cbb 100644 --- a/src/libs/actions/TransactionEdit.ts +++ b/src/libs/actions/TransactionEdit.ts @@ -38,4 +38,5 @@ function restoreOriginalTransactionFromBackup(transactionID: string) { }, }); } + export {createBackupTransaction, removeBackupTransaction, restoreOriginalTransactionFromBackup}; diff --git a/src/pages/EditRequestAmountPage.js b/src/pages/EditRequestAmountPage.js deleted file mode 100644 index bc77b9ecca75..000000000000 --- a/src/pages/EditRequestAmountPage.js +++ /dev/null @@ -1,66 +0,0 @@ -import {useFocusEffect} from '@react-navigation/native'; -import PropTypes from 'prop-types'; -import React, {useCallback, useRef} from 'react'; -import HeaderWithBackButton from '@components/HeaderWithBackButton'; -import ScreenWrapper from '@components/ScreenWrapper'; -import useLocalize from '@hooks/useLocalize'; -import * as DeviceCapabilities from '@libs/DeviceCapabilities'; -import CONST from '@src/CONST'; -import MoneyRequestAmountForm from './iou/steps/MoneyRequestAmountForm'; - -const propTypes = { - /** Transaction default amount value */ - defaultAmount: PropTypes.number.isRequired, - - /** Transaction default currency value */ - defaultCurrency: PropTypes.string.isRequired, - - /** Callback to fire when the Save button is pressed */ - onSubmit: PropTypes.func.isRequired, - - /** Callback to fire when we press on the currency */ - onNavigateToCurrency: PropTypes.func.isRequired, -}; - -function EditRequestAmountPage({defaultAmount, defaultCurrency, onNavigateToCurrency, onSubmit}) { - const {translate} = useLocalize(); - - const textInput = useRef(null); - const focusTimeoutRef = useRef(null); - - useFocusEffect( - useCallback(() => { - focusTimeoutRef.current = setTimeout(() => textInput.current && textInput.current.focus(), CONST.ANIMATED_TRANSITION); - return () => { - if (!focusTimeoutRef.current) { - return; - } - clearTimeout(focusTimeoutRef.current); - }; - }, []), - ); - - return ( - - - (textInput.current = e)} - onCurrencyButtonPress={onNavigateToCurrency} - onSubmitButtonPress={onSubmit} - isEditing - /> - - ); -} - -EditRequestAmountPage.propTypes = propTypes; -EditRequestAmountPage.displayName = 'EditRequestAmountPage'; - -export default EditRequestAmountPage; From 11da8b2af1da2c32c181cb85f68a4f614b4c1d25 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 25 Mar 2024 16:40:47 +0700 Subject: [PATCH 14/17] update saveAmountAndCurrency function to include the create case --- src/pages/iou/request/step/IOURequestStepAmount.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pages/iou/request/step/IOURequestStepAmount.js b/src/pages/iou/request/step/IOURequestStepAmount.js index f61bab102d2a..b0e013d85f16 100644 --- a/src/pages/iou/request/step/IOURequestStepAmount.js +++ b/src/pages/iou/request/step/IOURequestStepAmount.js @@ -184,6 +184,11 @@ function IOURequestStepAmount({ }; const saveAmountAndCurrency = ({amount}) => { + if (!isEditing) { + navigateToNextPage({amount}); + return; + } + const newAmount = CurrencyUtils.convertToBackendAmount(Number.parseFloat(amount)); // If the value hasn't changed, don't request to save changes on the server and just close the modal @@ -216,7 +221,7 @@ function IOURequestStepAmount({ amount={Math.abs(transactionAmount)} ref={(e) => (textInput.current = e)} onCurrencyButtonPress={navigateToCurrencySelectionPage} - onSubmitButtonPress={isEditing ? saveAmountAndCurrency : navigateToNextPage} + onSubmitButtonPress={saveAmountAndCurrency} selectedTab={iouRequestType} /> From 313524685bde1b8916b33e63ef385932f9d99dbd Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 28 Mar 2024 17:38:10 +0700 Subject: [PATCH 15/17] fix lint --- src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx index ef1fc3c2dfb0..de3552199626 100644 --- a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx +++ b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx @@ -86,7 +86,6 @@ const MoneyRequestModalStackNavigator = createModalStackNavigator require('../../../../pages/iou/request/step/IOURequestStepScan').default as React.ComponentType, [SCREENS.MONEY_REQUEST.STEP_TAG]: () => require('../../../../pages/iou/request/step/IOURequestStepTag').default as React.ComponentType, [SCREENS.MONEY_REQUEST.STEP_WAYPOINT]: () => require('../../../../pages/iou/request/step/IOURequestStepWaypoint').default as React.ComponentType, - [SCREENS.MONEY_REQUEST.AMOUNT]: () => require('../../../../pages/iou/steps/NewRequestAmountPage').default as React.ComponentType, [SCREENS.MONEY_REQUEST.PARTICIPANTS]: () => require('../../../../pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage').default as React.ComponentType, [SCREENS.MONEY_REQUEST.CONFIRMATION]: () => require('../../../../pages/iou/steps/MoneyRequestConfirmPage').default as React.ComponentType, [SCREENS.MONEY_REQUEST.CURRENCY]: () => require('../../../../pages/iou/IOUCurrencySelection').default as React.ComponentType, From 744f3fbf7ee2c88579fd4f95e5fab5699eb44b0f Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 1 Apr 2024 11:51:52 +0700 Subject: [PATCH 16/17] resolve conflict --- src/libs/actions/IOU.ts | 38 -------------------------------------- 1 file changed, 38 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 0a57dd15489b..a4f1efeeb8c6 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -5051,44 +5051,6 @@ function setShownHoldUseExplanation() { Onyx.set(ONYXKEYS.NVP_HOLD_USE_EXPLAINED, true); } -<<<<<<< HEAD -======= -/** Navigates to the next IOU page based on where the IOU request was started */ -function navigateToNextPage(iou: OnyxEntry, iouType: string, report?: OnyxEntry, path = '') { - const moneyRequestID = `${iouType}${report?.reportID ?? ''}`; - const shouldReset = iou?.id !== moneyRequestID && !!report?.reportID; - - // If the money request ID in Onyx does not match the ID from params, we want to start a new request - // with the ID from params. We need to clear the participants in case the new request is initiated from FAB. - if (shouldReset) { - resetMoneyRequestInfo(moneyRequestID); - } - - // If we're adding a receipt, that means the user came from the confirmation page and we need to navigate back to it. - if (path.slice(1) === ROUTES.MONEY_REQUEST_RECEIPT.getRoute(iouType, report?.reportID)) { - Navigation.navigate(ROUTES.MONEY_REQUEST_CONFIRMATION.getRoute(iouType, report?.reportID)); - return; - } - - // If a request is initiated on a report, skip the participants selection step and navigate to the confirmation page. - if (report?.reportID) { - // If the report is iou or expense report, we should get the chat report to set participant for request money - const chatReport = ReportUtils.isMoneyRequestReport(report) ? ReportUtils.getReport(report.chatReportID) : report; - // Reinitialize the participants when the money request ID in Onyx does not match the ID from params - if (!iou?.participants?.length || shouldReset) { - const currentUserAccountID = currentUserPersonalDetails.accountID; - const participants: Participant[] = ReportUtils.isPolicyExpenseChat(chatReport) - ? [{reportID: chatReport?.reportID, isPolicyExpenseChat: true, selected: true}] - : (chatReport?.participantAccountIDs ?? []).filter((accountID) => currentUserAccountID !== accountID).map((accountID) => ({accountID, selected: true})); - setMoneyRequestParticipants(participants); - } - Navigation.navigate(ROUTES.MONEY_REQUEST_CONFIRMATION.getRoute(iouType, report.reportID)); - return; - } - Navigation.navigate(ROUTES.MONEY_REQUEST_PARTICIPANTS.getRoute(iouType)); -} - ->>>>>>> main /** * When the money request or split bill creation flow is initialized via FAB, the reportID is not passed as a navigation * parameter. From a5888426fcdd95a1efefbf1a9a41b0caaeb55267 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 2 Apr 2024 02:41:11 +0700 Subject: [PATCH 17/17] complete resolve conflict --- src/libs/actions/IOU.ts | 42 ----------------------------------------- 1 file changed, 42 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 8393982c6b33..f99942a3d7a8 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -5064,48 +5064,6 @@ function setShownHoldUseExplanation() { Onyx.set(ONYXKEYS.NVP_HOLD_USE_EXPLAINED, true); } -<<<<<<< HEAD -======= -/** Navigates to the next IOU page based on where the IOU request was started */ -function navigateToNextPage(iou: OnyxEntry, iouType: string, report?: OnyxEntry, path = '') { - const moneyRequestID = `${iouType}${report?.reportID ?? ''}`; - const shouldReset = iou?.id !== moneyRequestID && !!report?.reportID; - - // If the money request ID in Onyx does not match the ID from params, we want to start a new request - // with the ID from params. We need to clear the participants in case the new request is initiated from FAB. - if (shouldReset) { - resetMoneyRequestInfo(moneyRequestID); - } - - // If we're adding a receipt, that means the user came from the confirmation page and we need to navigate back to it. - if (path.slice(1) === ROUTES.MONEY_REQUEST_RECEIPT.getRoute(iouType, report?.reportID)) { - Navigation.navigate( - ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(CONST.IOU.ACTION.CREATE, iouType as ValueOf, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, report?.reportID ?? '1'), - ); - return; - } - - // If a request is initiated on a report, skip the participants selection step and navigate to the confirmation page. - if (report?.reportID) { - // If the report is iou or expense report, we should get the chat report to set participant for request money - const chatReport = ReportUtils.isMoneyRequestReport(report) ? ReportUtils.getReport(report.chatReportID) : report; - // Reinitialize the participants when the money request ID in Onyx does not match the ID from params - if (!iou?.participants?.length || shouldReset) { - const currentUserAccountID = currentUserPersonalDetails.accountID; - const participants: Participant[] = ReportUtils.isPolicyExpenseChat(chatReport) - ? [{reportID: chatReport?.reportID, isPolicyExpenseChat: true, selected: true}] - : (chatReport?.participantAccountIDs ?? []).filter((accountID) => currentUserAccountID !== accountID).map((accountID) => ({accountID, selected: true})); - setMoneyRequestParticipants(participants); - } - Navigation.navigate( - ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(CONST.IOU.ACTION.CREATE, iouType as ValueOf, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, report.reportID), - ); - return; - } - Navigation.navigate(ROUTES.MONEY_REQUEST_PARTICIPANTS.getRoute(iouType)); -} - ->>>>>>> main /** * Put money request on HOLD */