From 2e9cf17bfee27560f4a979fbf4815e3924f360c8 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 5 Dec 2023 16:15:57 -0700 Subject: [PATCH 01/12] create updateMoneyRequestAmountOrCurrency --- src/libs/actions/IOU.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index ed43569c360a..2786ad5e48ce 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1977,6 +1977,23 @@ function editMoneyRequest(transaction, transactionThreadReportID, transactionCha } } +/** + * Updates the created date of a money request + * + * @param {String} transactionID + * @param {Number} transactionThreadReportID + * @param {String} currency + * @param {Number} amount + */ +function updateMoneyRequestAmountOrCurrency(transactionID, transactionThreadReportID, currency, amount) { + const transactionChanges = { + amount, + currency, + }; + const {params, onyxData} = getUpdateMoneyRequestParams(transactionID, transactionThreadReportID, transactionChanges, true); + API.write('UpdateMoneyRequestAmountOrCurrency', params, onyxData); +} + /** * @param {String} transactionID * @param {Object} reportAction - the money request reportAction we are deleting From 7c455d902420e5fefa99ba5c6ce8a6be8dc70d0b Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 6 Dec 2023 13:37:55 -0700 Subject: [PATCH 02/12] rename command --- src/libs/actions/IOU.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 2786ad5e48ce..c50708061337 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1985,13 +1985,13 @@ function editMoneyRequest(transaction, transactionThreadReportID, transactionCha * @param {String} currency * @param {Number} amount */ -function updateMoneyRequestAmountOrCurrency(transactionID, transactionThreadReportID, currency, amount) { +function updateMoneyRequestAmountAndCurrency(transactionID, transactionThreadReportID, currency, amount) { const transactionChanges = { amount, currency, }; const {params, onyxData} = getUpdateMoneyRequestParams(transactionID, transactionThreadReportID, transactionChanges, true); - API.write('UpdateMoneyRequestAmountOrCurrency', params, onyxData); + API.write('UpdateMoneyRequestAmountAndCurrency', params, onyxData); } /** @@ -3033,4 +3033,5 @@ export { detachReceipt, getIOUReportID, editMoneyRequest, + updateMoneyRequestAmountAndCurrency, }; From 41ec24440b1f96f6161b9adca6df60cb6a5a4ea2 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 6 Dec 2023 13:50:56 -0700 Subject: [PATCH 03/12] create saveAmountAndCurrency --- src/pages/EditRequestPage.js | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index 95313bea142d..da0e2592ac88 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -1,7 +1,7 @@ import lodashGet from 'lodash/get'; import lodashValues from 'lodash/values'; import PropTypes from 'prop-types'; -import React, {useEffect, useMemo} from 'react'; +import React, {useCallback, useEffect, useMemo} from 'react'; import {withOnyx} from 'react-native-onyx'; import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; import categoryPropTypes from '@components/categoryPropTypes'; @@ -18,7 +18,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 EditRequestCategoryPage from './EditRequestCategoryPage'; import EditRequestCreatedPage from './EditRequestCreatedPage'; @@ -123,6 +122,17 @@ function EditRequestPage({report, route, parentReport, policyCategories, policyT Navigation.dismissModal(report.reportID); } + const saveAmountAndCurrency = useCallback((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 && transactionCurrency === defaultCurrency) { + Navigation.dismissModal(); + return; + } + // Temporarily disabling currency editing and it will be enabled as a quick follow up + IOU.updateMoneyRequestAmountAndCurrency(transaction.transactionID, report.reportID, defaultCurrency, transactionChanges.amount); + }, [transaction.transactionID, report.reportID, transactionAmount, transactionCurrency, defaultCurrency]) + if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.DESCRIPTION) { return ( { - const amount = CurrencyUtils.convertToBackendAmount(Number.parseFloat(transactionChanges)); - // In case the amount hasn't been changed, do not make the API request. - 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: defaultCurrency, - }); - }} - onNavigateToCurrency={() => { - const activeRoute = encodeURIComponent(Navigation.getActiveRouteWithoutParams()); - Navigation.navigate(ROUTES.EDIT_CURRENCY_REQUEST.getRoute(report.reportID, defaultCurrency, activeRoute)); - }} + onSubmit={saveAmountAndCurrency} /> ); } From 326fc797d118dd7b23550a2d7710ed3f3b2fda02 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Fri, 8 Dec 2023 12:06:31 -0700 Subject: [PATCH 04/12] fix style --- src/pages/EditRequestPage.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index da0e2592ac88..26244d1346ff 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -122,16 +122,19 @@ function EditRequestPage({report, route, parentReport, policyCategories, policyT Navigation.dismissModal(report.reportID); } - const saveAmountAndCurrency = useCallback((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 && transactionCurrency === defaultCurrency) { - Navigation.dismissModal(); - return; - } - // Temporarily disabling currency editing and it will be enabled as a quick follow up - IOU.updateMoneyRequestAmountAndCurrency(transaction.transactionID, report.reportID, defaultCurrency, transactionChanges.amount); - }, [transaction.transactionID, report.reportID, transactionAmount, transactionCurrency, defaultCurrency]) + const saveAmountAndCurrency = useCallback( + (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 && transactionCurrency === defaultCurrency) { + Navigation.dismissModal(); + return; + } + // Temporarily disabling currency editing and it will be enabled as a quick follow up + IOU.updateMoneyRequestAmountAndCurrency(transaction.transactionID, report.reportID, defaultCurrency, transactionChanges.amount); + }, + [transaction.transactionID, report.reportID, transactionAmount, transactionCurrency, defaultCurrency], + ); if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.DESCRIPTION) { return ( From efd552c7f5a881550d9ac05103c2cb0628d3acdc Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 18 Dec 2023 17:12:27 +0400 Subject: [PATCH 05/12] implement method; --- src/libs/actions/IOU.js | 2 +- src/pages/EditRequestPage.js | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 328be6a6ec00..888e4ff12ad6 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -3420,9 +3420,9 @@ export { setUpDistanceTransaction, navigateToNextPage, updateMoneyRequestDate, + updateMoneyRequestAmountAndCurrency, replaceReceipt, detachReceipt, getIOUReportID, editMoneyRequest, - updateMoneyRequestAmountAndCurrency, }; diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index 853600b0f696..8e6c5217bc2d 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -9,7 +9,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 Navigation from '@libs/Navigation/Navigation'; import * as OptionsListUtils from '@libs/OptionsListUtils'; import * as PolicyUtils from '@libs/PolicyUtils'; @@ -120,17 +119,17 @@ function EditRequestPage({report, route, parentReport, policyCategories, policyT } const saveAmountAndCurrency = useCallback( - (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 && transactionCurrency === defaultCurrency) { + ({amount: newAmount, currency: newCurrency}) => { + // 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; } // Temporarily disabling currency editing and it will be enabled as a quick follow up - IOU.updateMoneyRequestAmountAndCurrency(transaction.transactionID, report.reportID, defaultCurrency, transactionChanges.amount); + IOU.updateMoneyRequestAmountAndCurrency(transaction.transactionID, report.reportID, newCurrency, newAmount); + Navigation.dismissModal(); }, - [transaction.transactionID, report.reportID, transactionAmount, transactionCurrency, defaultCurrency], + [transaction, report], ); const saveCreated = useCallback( From d2cab61561d153f5811730f743f0a054424c58d1 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 18 Dec 2023 17:35:33 +0400 Subject: [PATCH 06/12] convert to backend amount --- src/pages/EditRequestPage.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index 8e6c5217bc2d..10a548e68f28 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -13,6 +13,7 @@ import Navigation from '@libs/Navigation/Navigation'; import * as OptionsListUtils from '@libs/OptionsListUtils'; import * as PolicyUtils from '@libs/PolicyUtils'; import * as ReportUtils from '@libs/ReportUtils'; +import * as CurrencyUtils from '@libs/CurrencyUtils'; import * as TransactionUtils from '@libs/TransactionUtils'; import * as IOU from '@userActions/IOU'; import CONST from '@src/CONST'; @@ -119,7 +120,9 @@ function EditRequestPage({report, route, parentReport, policyCategories, policyT } const saveAmountAndCurrency = useCallback( - ({amount: newAmount, currency: newCurrency}) => { + ({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(); From e49973346289eb5ac154093212c2c7e29f2f4f62 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 19 Dec 2023 12:28:39 +0400 Subject: [PATCH 07/12] add onNavigateToCurrency back --- src/pages/EditRequestPage.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index 10a548e68f28..6bdeb4e38354 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -18,6 +18,7 @@ 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 EditRequestCategoryPage from './EditRequestCategoryPage'; import EditRequestCreatedPage from './EditRequestCreatedPage'; @@ -180,6 +181,10 @@ function EditRequestPage({report, route, parentReport, policyCategories, policyT defaultCurrency={defaultCurrency} reportID={report.reportID} onSubmit={saveAmountAndCurrency} + onNavigateToCurrency={() => { + const activeRoute = encodeURIComponent(Navigation.getActiveRouteWithoutParams()); + Navigation.navigate(ROUTES.EDIT_CURRENCY_REQUEST.getRoute(report.reportID, defaultCurrency, activeRoute)); + }} /> ); } From 8838be351f3071ba43350925311d1ef8247970d0 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 19 Dec 2023 12:35:01 +0400 Subject: [PATCH 08/12] pass amount and currency --- src/pages/iou/steps/MoneyRequestAmountForm.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/iou/steps/MoneyRequestAmountForm.js b/src/pages/iou/steps/MoneyRequestAmountForm.js index c9075d896deb..414e942aa384 100644 --- a/src/pages/iou/steps/MoneyRequestAmountForm.js +++ b/src/pages/iou/steps/MoneyRequestAmountForm.js @@ -228,8 +228,8 @@ function MoneyRequestAmountForm({amount, currency, isEditing, forwardedRef, onCu const backendAmount = CurrencyUtils.convertToBackendAmount(Number.parseFloat(currentAmount)); initializeAmount(backendAmount); - onSubmitButtonPress(currentAmount); - }, [onSubmitButtonPress, currentAmount, initializeAmount]); + onSubmitButtonPress({amount: currentAmount, currency}); + }, [onSubmitButtonPress, currentAmount, currency, initializeAmount]); /** * Input handler to check for a forward-delete key (or keyboard shortcut) press. From f1a462179a99c5a1f2287fa620a7c91b47092844 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 19 Dec 2023 12:36:46 +0400 Subject: [PATCH 09/12] fix styles, update comment --- src/libs/actions/IOU.js | 2 +- src/pages/EditRequestPage.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 888e4ff12ad6..f8ade194fe80 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -2254,7 +2254,7 @@ function editMoneyRequest(transaction, transactionThreadReportID, transactionCha } /** - * Updates the created date of a money request + * Updates the amount and currency fields of a money request * * @param {String} transactionID * @param {Number} transactionThreadReportID diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index 6bdeb4e38354..4a0dce41265c 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -9,11 +9,11 @@ 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 Navigation from '@libs/Navigation/Navigation'; import * as OptionsListUtils from '@libs/OptionsListUtils'; import * as PolicyUtils from '@libs/PolicyUtils'; import * as ReportUtils from '@libs/ReportUtils'; -import * as CurrencyUtils from '@libs/CurrencyUtils'; import * as TransactionUtils from '@libs/TransactionUtils'; import * as IOU from '@userActions/IOU'; import CONST from '@src/CONST'; @@ -129,7 +129,7 @@ function EditRequestPage({report, route, parentReport, policyCategories, policyT Navigation.dismissModal(); return; } - // Temporarily disabling currency editing and it will be enabled as a quick follow up + IOU.updateMoneyRequestAmountAndCurrency(transaction.transactionID, report.reportID, newCurrency, newAmount); Navigation.dismissModal(); }, From a17fbb9cb14da6b4f406fff246e9212584afe3c5 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 20 Dec 2023 14:44:39 +0400 Subject: [PATCH 10/12] fix amount issue --- src/pages/iou/request/step/IOURequestStepAmount.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepAmount.js b/src/pages/iou/request/step/IOURequestStepAmount.js index 8f89703e6efd..b0812271c647 100644 --- a/src/pages/iou/request/step/IOURequestStepAmount.js +++ b/src/pages/iou/request/step/IOURequestStepAmount.js @@ -68,10 +68,10 @@ function IOURequestStepAmount({ }; /** - * @param {Number} currentAmount + * @param {Number} amount */ - const navigateToNextPage = (currentAmount) => { - const amountInSmallestCurrencyUnits = CurrencyUtils.convertToBackendAmount(Number.parseFloat(currentAmount)); + const navigateToNextPage = ({amount}) => { + const amountInSmallestCurrencyUnits = CurrencyUtils.convertToBackendAmount(Number.parseFloat(amount)); IOU.setMoneyRequestAmount_temporaryForRefactor(transactionID, amountInSmallestCurrencyUnits, currency || CONST.CURRENCY.USD); if (backTo) { From ffd30326401f00be54cfc6d543d6c2663919f851 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 20 Dec 2023 14:45:29 +0400 Subject: [PATCH 11/12] update NewRequestAmountPage --- src/pages/iou/steps/NewRequestAmountPage.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/iou/steps/NewRequestAmountPage.js b/src/pages/iou/steps/NewRequestAmountPage.js index 569e2ce693ee..1df74569e4c3 100644 --- a/src/pages/iou/steps/NewRequestAmountPage.js +++ b/src/pages/iou/steps/NewRequestAmountPage.js @@ -128,8 +128,8 @@ function NewRequestAmountPage({route, iou, report, selectedTab}) { Navigation.navigate(ROUTES.MONEY_REQUEST_CURRENCY.getRoute(iouType, reportID, currency, activeRoute)); }; - const navigateToNextPage = (currentAmount) => { - const amountInSmallestCurrencyUnits = CurrencyUtils.convertToBackendAmount(Number.parseFloat(currentAmount)); + const navigateToNextPage = ({amount}) => { + const amountInSmallestCurrencyUnits = CurrencyUtils.convertToBackendAmount(Number.parseFloat(amount)); IOU.setMoneyRequestAmount(amountInSmallestCurrencyUnits); IOU.setMoneyRequestCurrency(currency); From 78dae42d3bdd7d80902085195682887726c13713 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 21 Dec 2023 13:53:16 +0400 Subject: [PATCH 12/12] update param type --- src/libs/actions/IOU.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index f8ade194fe80..a21981c3e3d5 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -837,7 +837,7 @@ function createDistanceRequest(report, participant, comment, created, category, /** * @param {String} transactionID - * @param {Number} transactionThreadReportID + * @param {String} transactionThreadReportID * @param {Object} transactionChanges * @param {String} [transactionChanges.created] Present when updated the date field * @param {Boolean} onlyIncludeChangedFields @@ -1017,7 +1017,7 @@ function getUpdateMoneyRequestParams(transactionID, transactionThreadReportID, t * Updates the created date of a money request * * @param {String} transactionID - * @param {Number} transactionThreadReportID + * @param {String} transactionThreadReportID * @param {String} val */ function updateMoneyRequestDate(transactionID, transactionThreadReportID, val) { @@ -1032,7 +1032,7 @@ function updateMoneyRequestDate(transactionID, transactionThreadReportID, val) { * Edits an existing distance request * * @param {String} transactionID - * @param {Number} transactionThreadReportID + * @param {String} transactionThreadReportID * @param {Object} transactionChanges * @param {String} [transactionChanges.created] * @param {Number} [transactionChanges.amount] @@ -2242,7 +2242,7 @@ function editRegularMoneyRequest(transactionID, transactionThreadReportID, trans /** * @param {object} transaction - * @param {Number} transactionThreadReportID + * @param {String} transactionThreadReportID * @param {Object} transactionChanges */ function editMoneyRequest(transaction, transactionThreadReportID, transactionChanges) { @@ -2257,7 +2257,7 @@ function editMoneyRequest(transaction, transactionThreadReportID, transactionCha * Updates the amount and currency fields of a money request * * @param {String} transactionID - * @param {Number} transactionThreadReportID + * @param {String} transactionThreadReportID * @param {String} currency * @param {Number} amount */