From ba4833019fc3ba305cdfd6d41b1ff918809bffe3 Mon Sep 17 00:00:00 2001 From: Vit Horacek <36083550+mountiny@users.noreply.github.com> Date: Thu, 17 Aug 2023 14:17:16 +0100 Subject: [PATCH] Merge pull request #24565 from koko57/followup/23961-edit-request [CP staging] Followup/23961 edit request (cherry picked from commit 2de126fc792f40b4c96d91437cd3281af8431f82) --- src/ROUTES.js | 2 ++ src/components/CurrencySymbolButton.js | 15 +++------------ src/components/TextInputWithCurrencySymbol.js | 5 ----- .../AppNavigator/ModalStackNavigators.js | 7 +++++++ src/libs/Navigation/linkingConfig.js | 1 + src/pages/EditRequestAmountPage.js | 15 ++++++++++++--- src/pages/EditRequestPage.js | 10 ++++++---- src/pages/iou/steps/MoneyRequestAmountForm.js | 7 +------ 8 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/ROUTES.js b/src/ROUTES.js index 90d08e5b13c8..2ad3cd7a5cd4 100644 --- a/src/ROUTES.js +++ b/src/ROUTES.js @@ -72,6 +72,8 @@ export default { REPORT_WITH_ID: 'r/:reportID?', EDIT_REQUEST: 'r/:threadReportID/edit/:field', getEditRequestRoute: (threadReportID, field) => `r/${threadReportID}/edit/${field}`, + EDIT_CURRENCY_REQUEST: 'r/:threadReportID/edit/currency', + getEditRequestCurrencyRoute: (threadReportID, currency, backTo) => `r/${threadReportID}/edit/currency?currency=${currency}&backTo=${backTo}`, getReportRoute: (reportID) => `r/${reportID}`, REPORT_WITH_ID_DETAILS_SHARE_CODE: 'r/:reportID/details/shareCode', getReportShareCodeRoute: (reportID) => `r/${reportID}/details/shareCode`, diff --git a/src/components/CurrencySymbolButton.js b/src/components/CurrencySymbolButton.js index 6ec50431ad87..ab4488c65f49 100644 --- a/src/components/CurrencySymbolButton.js +++ b/src/components/CurrencySymbolButton.js @@ -13,24 +13,16 @@ const propTypes = { /** Function to call when currency button is pressed */ onCurrencyButtonPress: PropTypes.func.isRequired, - - /** Flag to indicate if the button should be disabled */ - disabled: PropTypes.bool, -}; - -const defaultProps = { - disabled: false, }; -function CurrencySymbolButton({onCurrencyButtonPress, currencySymbol, disabled}) { +function CurrencySymbolButton({onCurrencyButtonPress, currencySymbol}) { const {translate} = useLocalize(); return ( - + {currencySymbol} @@ -40,6 +32,5 @@ function CurrencySymbolButton({onCurrencyButtonPress, currencySymbol, disabled}) CurrencySymbolButton.propTypes = propTypes; CurrencySymbolButton.displayName = 'CurrencySymbolButton'; -CurrencySymbolButton.defaultProps = defaultProps; export default CurrencySymbolButton; diff --git a/src/components/TextInputWithCurrencySymbol.js b/src/components/TextInputWithCurrencySymbol.js index 7bb5b911f655..c7e8804e8184 100644 --- a/src/components/TextInputWithCurrencySymbol.js +++ b/src/components/TextInputWithCurrencySymbol.js @@ -33,9 +33,6 @@ const propTypes = { /** Function to call when selection in text input is changed */ onSelectionChange: PropTypes.func, - - /** Flag to indicate if the button should be disabled */ - disabled: PropTypes.bool, }; const defaultProps = { @@ -44,7 +41,6 @@ const defaultProps = { onCurrencyButtonPress: () => {}, selection: undefined, onSelectionChange: () => {}, - disabled: false, }; function TextInputWithCurrencySymbol(props) { @@ -62,7 +58,6 @@ function TextInputWithCurrencySymbol(props) { ); diff --git a/src/libs/Navigation/AppNavigator/ModalStackNavigators.js b/src/libs/Navigation/AppNavigator/ModalStackNavigators.js index 8a489afb035e..ab9e2dcd73b2 100644 --- a/src/libs/Navigation/AppNavigator/ModalStackNavigators.js +++ b/src/libs/Navigation/AppNavigator/ModalStackNavigators.js @@ -723,6 +723,13 @@ const EditRequestStackNavigator = createModalStackNavigator([ }, name: 'EditRequest_Root', }, + { + getComponent: () => { + const IOUCurrencySelection = require('../../../pages/iou/IOUCurrencySelection').default; + return IOUCurrencySelection; + }, + name: 'EditRequest_Currency', + }, ]); export { diff --git a/src/libs/Navigation/linkingConfig.js b/src/libs/Navigation/linkingConfig.js index dcc4f77fde73..5a3f0a9abe71 100644 --- a/src/libs/Navigation/linkingConfig.js +++ b/src/libs/Navigation/linkingConfig.js @@ -361,6 +361,7 @@ export default { EditRequest: { screens: { EditRequest_Root: ROUTES.EDIT_REQUEST, + EditRequest_Currency: ROUTES.EDIT_CURRENCY_REQUEST, }, }, }, diff --git a/src/pages/EditRequestAmountPage.js b/src/pages/EditRequestAmountPage.js index b04de9ebfd5a..d087d86ebdf5 100644 --- a/src/pages/EditRequestAmountPage.js +++ b/src/pages/EditRequestAmountPage.js @@ -7,6 +7,7 @@ import HeaderWithBackButton from '../components/HeaderWithBackButton'; import Navigation from '../libs/Navigation/Navigation'; import useLocalize from '../hooks/useLocalize'; import MoneyRequestAmountForm from './iou/steps/MoneyRequestAmountForm'; +import ROUTES from '../ROUTES'; const propTypes = { /** Transaction default amount value */ @@ -17,9 +18,12 @@ const propTypes = { /** Callback to fire when the Save button is pressed */ onSubmit: PropTypes.func.isRequired, + + /** reportID for the transaction thread */ + reportID: PropTypes.string.isRequired, }; -function EditRequestAmountPage({defaultAmount, defaultCurrency, onSubmit}) { +function EditRequestAmountPage({defaultAmount, defaultCurrency, onSubmit, reportID}) { const {translate} = useLocalize(); const textInput = useRef(null); @@ -36,6 +40,12 @@ function EditRequestAmountPage({defaultAmount, defaultCurrency, onSubmit}) { }); }; + const navigateToCurrencySelectionPage = () => { + // Remove query from the route and encode it. + const activeRoute = encodeURIComponent(Navigation.getActiveRoute().replace(/\?.*/, '')); + Navigation.navigate(ROUTES.getEditRequestCurrencyRoute(reportID, defaultCurrency, activeRoute)); + }; + useFocusEffect( useCallback(() => { focusTextInput(); @@ -53,11 +63,10 @@ function EditRequestAmountPage({defaultAmount, defaultCurrency, onSubmit}) { /> (textInput.current = e)} - onCurrencyButtonPress={() => null} + onCurrencyButtonPress={navigateToCurrencySelectionPage} onSubmitButtonPress={onSubmit} /> diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index d3c2cdc1841b..2238c0cf309f 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -46,6 +46,8 @@ function EditRequestPage({report, route, parentReport}) { const transaction = TransactionUtils.getLinkedTransaction(parentReportAction); const {amount: transactionAmount, currency: transactionCurrency, comment: transactionDescription} = ReportUtils.getTransactionDetails(transaction); + const defaultCurrency = lodashGet(route, 'params.currency', '') || transactionCurrency; + // Take only the YYYY-MM-DD value const transactionCreated = TransactionUtils.getCreated(transaction); const fieldToEdit = lodashGet(route, ['params', 'field'], ''); @@ -103,19 +105,19 @@ function EditRequestPage({report, route, parentReport}) { return ( { - const amount = CurrencyUtils.convertToBackendAmount(transactionCurrency, Number.parseFloat(transactionChanges)); + const amount = CurrencyUtils.convertToBackendAmount(Number.parseFloat(transactionChanges)); // In case the amount hasn't been changed, do not make the API request. - if (amount === transactionAmount) { + if (amount === transactionAmount && transactionCurrency === defaultCurrency) { Navigation.dismissModal(); return; } // Temporarily disabling currency editing and it will be enabled as a quick follow up editMoneyRequest({ amount, - currency: transactionCurrency, + currency: defaultCurrency, }); }} /> diff --git a/src/pages/iou/steps/MoneyRequestAmountForm.js b/src/pages/iou/steps/MoneyRequestAmountForm.js index c5fe3e269fd8..99f7e982cb10 100644 --- a/src/pages/iou/steps/MoneyRequestAmountForm.js +++ b/src/pages/iou/steps/MoneyRequestAmountForm.js @@ -31,9 +31,6 @@ const propTypes = { /** Fired when submit button pressed, saves the given amount and navigates to the next page */ onSubmitButtonPress: PropTypes.func.isRequired, - - /** Flag to indicate if the button should be disabled */ - disableCurrency: PropTypes.bool, }; const defaultProps = { @@ -41,7 +38,6 @@ const defaultProps = { currency: CONST.CURRENCY.USD, forwardedRef: null, isEditing: false, - disableCurrency: false, }; /** @@ -61,7 +57,7 @@ const AMOUNT_VIEW_ID = 'amountView'; const NUM_PAD_CONTAINER_VIEW_ID = 'numPadContainerView'; const NUM_PAD_VIEW_ID = 'numPadView'; -function MoneyRequestAmountForm({amount, currency, isEditing, forwardedRef, onCurrencyButtonPress, onSubmitButtonPress, disableCurrency}) { +function MoneyRequestAmountForm({amount, currency, isEditing, forwardedRef, onCurrencyButtonPress, onSubmitButtonPress}) { const {translate, toLocaleDigit, numberFormat} = useLocalize(); const textInput = useRef(null); @@ -207,7 +203,6 @@ function MoneyRequestAmountForm({amount, currency, isEditing, forwardedRef, onCu } setSelection(e.nativeEvent.selection); }} - disabled={disableCurrency} />