From f0ff0a7921308590d9f2e4e184c477e2568d126c Mon Sep 17 00:00:00 2001 From: Ana Margarida Silva Date: Fri, 18 Aug 2023 15:39:53 +0100 Subject: [PATCH 01/12] feat: update IOU report total in optimistic data on edit money request --- src/libs/actions/IOU.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 13a9af5b42f6..5c0430afc143 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -954,7 +954,15 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC // STEP 2: Build new modified expense report action. const updatedReportAction = ReportUtils.buildOptimisticModifiedExpenseReportAction(transactionThread, transaction, transactionChanges, isFromExpenseReport); const updatedTransaction = TransactionUtils.getUpdatedTransaction(transaction, transactionChanges, isFromExpenseReport); + // STEP 3: Compute the IOU total and update the report preview message so LHN amount owed is correct + // Should only update if the transaction matches the currency of the report, else we wait for the update + // from the server with the currency conversion + const updatedIouReport = {...iouReport}; + if (updatedTransaction.currency === iouReport.currency && updatedTransaction.modifiedAmount) { + updatedIouReport.total = updatedIouReport.total - TransactionUtils.getAmount(transaction) + TransactionUtils.getAmount(updatedTransaction); + } + // STEP 4: Compose the optimistic data const optimisticData = [ { @@ -969,6 +977,11 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, value: updatedTransaction, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, + value: updatedIouReport, + }, ]; const successData = [ @@ -984,6 +997,11 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, value: {pendingAction: null}, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, + value: {pendingAction: null}, + }, ]; const failureData = [ @@ -1001,7 +1019,7 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC }, { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.report}`, + key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, value: iouReport, }, ]; From b7dc724a5fe7598565caf61472cf1ca02533f805 Mon Sep 17 00:00:00 2001 From: Ana Margarida Silva Date: Tue, 22 Aug 2023 15:00:49 +0100 Subject: [PATCH 02/12] feat: change message values of report when IOU amount changes --- src/libs/actions/IOU.js | 46 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index b91116e667bc..4a2c85cb9983 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -949,6 +949,7 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC const transactionThread = allReports[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`]; const transaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; const iouReport = allReports[`${ONYXKEYS.COLLECTION.REPORT}${transactionThread.parentReportID}`]; + const chatReport = allReports[`${ONYXKEYS.COLLECTION.REPORT}${iouReport.chatReportID}`]; const isFromExpenseReport = ReportUtils.isExpenseReport(iouReport); // STEP 2: Build new modified expense report action. @@ -958,9 +959,45 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC // STEP 3: Compute the IOU total and update the report preview message so LHN amount owed is correct // Should only update if the transaction matches the currency of the report, else we wait for the update // from the server with the currency conversion - const updatedIouReport = {...iouReport}; + let updatedIouReport = null; + const updatedChatReport = { ...chatReport}; if (updatedTransaction.currency === iouReport.currency && updatedTransaction.modifiedAmount) { - updatedIouReport.total = updatedIouReport.total - TransactionUtils.getAmount(transaction) + TransactionUtils.getAmount(updatedTransaction); + if (ReportUtils.isExpenseReport(iouReport)) { + updatedIouReport = {...iouReport}; + + // Because of the Expense reports are stored as negative values, we add the total from the amount + updatedIouReport.total += TransactionUtils.getAmount(updatedTransaction, true); + } else { + updatedIouReport = IOUUtils.updateIOUOwnerAndTotal( + iouReport, + updatedReportAction.actorAccountID, + TransactionUtils.getAmount(transaction, false), + TransactionUtils.getCurrency(transaction), + true, + ); + updatedIouReport = IOUUtils.updateIOUOwnerAndTotal( + updatedIouReport, + updatedReportAction.actorAccountID, + TransactionUtils.getAmount(updatedTransaction, false), + TransactionUtils.getCurrency(updatedTransaction), + false, + ); + } + + updatedIouReport.cachedTotal = CurrencyUtils.convertToDisplayString(updatedIouReport.total, updatedTransaction.currency); + + // Update the last message of the IOU report + const lastMessage = ReportUtils.getIOUReportActionMessage(iouReport.reportID, CONST.IOU.REPORT_ACTION_TYPE.CREATE, updatedIouReport.total, '', updatedTransaction.currency, '', false); + updatedIouReport.lastMessageText = lastMessage[0].text; + updatedIouReport.lastMessageHtml = lastMessage[0].html; + + // Update the last message of the IOU chat report + const messageText = Localize.translateLocal('iou.payerOwesAmount', { + payer: updatedIouReport.managerEmail, + amount: CurrencyUtils.convertToDisplayString(updatedIouReport.total, updatedIouReport.currency), + }); + updatedChatReport.lastMessageText = messageText; + updatedChatReport.lastMessageHtml = messageText; } // STEP 4: Compose the optimistic data @@ -982,6 +1019,11 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, value: updatedIouReport, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.chatReportID}`, + value: updatedChatReport, + }, ]; const successData = [ From 7c9706e80e8f3ebd5491e8468e15b8cff778cf21 Mon Sep 17 00:00:00 2001 From: Ana Margarida Silva Date: Tue, 22 Aug 2023 15:00:57 +0100 Subject: [PATCH 03/12] fix: typo --- src/pages/iou/steps/NewRequestAmountPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/steps/NewRequestAmountPage.js b/src/pages/iou/steps/NewRequestAmountPage.js index 6eda79654e77..5b73b28a9cd9 100644 --- a/src/pages/iou/steps/NewRequestAmountPage.js +++ b/src/pages/iou/steps/NewRequestAmountPage.js @@ -185,7 +185,7 @@ function NewRequestAmountPage({route, iou, report}) { {content} From c7a2d0649f9f365edb60448232deb9b0ab438678 Mon Sep 17 00:00:00 2001 From: Ana Margarida Silva Date: Wed, 23 Aug 2023 10:00:02 +0100 Subject: [PATCH 04/12] fix: re-render when transaction for LHN changes --- .../LHNOptionsList/OptionRowLHNData.js | 9 ++++++++- src/libs/actions/IOU.js | 17 ++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/components/LHNOptionsList/OptionRowLHNData.js b/src/components/LHNOptionsList/OptionRowLHNData.js index 5b010593f1e7..eaa87497f28f 100644 --- a/src/components/LHNOptionsList/OptionRowLHNData.js +++ b/src/components/LHNOptionsList/OptionRowLHNData.js @@ -76,6 +76,7 @@ function OptionRowLHNData({ comment, policies, parentReportActions, + transactions, ...propsToForward }) { const reportID = propsToForward.reportID; @@ -86,6 +87,8 @@ function OptionRowLHNData({ const policy = lodashGet(policies, [`${ONYXKEYS.COLLECTION.POLICY}${fullReport.policyID}`], ''); const parentReportAction = parentReportActions[fullReport.parentReportActionID]; + const transactionID = lodashGet(parentReportAction, ['originalMessage', 'IOUTransactionID'], ''); + const transaction = lodashGet(transactions, [`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`], ''); const optionItemRef = useRef(); const optionItem = useMemo(() => { @@ -97,8 +100,9 @@ function OptionRowLHNData({ optionItemRef.current = item; return item; // Listen parentReportAction to update title of thread report when parentReportAction changed + // Listen to transaction to update title of transaction report when transaction changed // eslint-disable-next-line react-hooks/exhaustive-deps - }, [fullReport, reportActions, personalDetails, preferredLocale, policy, parentReportAction]); + }, [fullReport, reportActions, personalDetails, preferredLocale, policy, parentReportAction, transaction]); useEffect(() => { if (!optionItem || optionItem.hasDraftComment || !comment || comment.length <= 0 || isFocused) { @@ -179,6 +183,9 @@ export default React.memo( policies: { key: ONYXKEYS.COLLECTION.POLICY, }, + transactions: { + key: ONYXKEYS.COLLECTION.TRANSACTION, + }, }), withOnyx({ parentReportActions: { diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 4a2c85cb9983..a27606f4d96f 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -960,12 +960,11 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC // Should only update if the transaction matches the currency of the report, else we wait for the update // from the server with the currency conversion let updatedIouReport = null; - const updatedChatReport = { ...chatReport}; + const updatedChatReport = {...chatReport}; if (updatedTransaction.currency === iouReport.currency && updatedTransaction.modifiedAmount) { if (ReportUtils.isExpenseReport(iouReport)) { updatedIouReport = {...iouReport}; - - // Because of the Expense reports are stored as negative values, we add the total from the amount + updatedIouReport.total -= TransactionUtils.getAmount(transaction, true); updatedIouReport.total += TransactionUtils.getAmount(updatedTransaction, true); } else { updatedIouReport = IOUUtils.updateIOUOwnerAndTotal( @@ -987,10 +986,18 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC updatedIouReport.cachedTotal = CurrencyUtils.convertToDisplayString(updatedIouReport.total, updatedTransaction.currency); // Update the last message of the IOU report - const lastMessage = ReportUtils.getIOUReportActionMessage(iouReport.reportID, CONST.IOU.REPORT_ACTION_TYPE.CREATE, updatedIouReport.total, '', updatedTransaction.currency, '', false); + const lastMessage = ReportUtils.getIOUReportActionMessage( + iouReport.reportID, + CONST.IOU.REPORT_ACTION_TYPE.CREATE, + updatedIouReport.total, + '', + updatedTransaction.currency, + '', + false, + ); updatedIouReport.lastMessageText = lastMessage[0].text; updatedIouReport.lastMessageHtml = lastMessage[0].html; - + // Update the last message of the IOU chat report const messageText = Localize.translateLocal('iou.payerOwesAmount', { payer: updatedIouReport.managerEmail, From 4cbd6d50a7248f2e898848ffd9bf959ff75fde72 Mon Sep 17 00:00:00 2001 From: Ana Margarida Silva Date: Thu, 24 Aug 2023 09:48:32 +0100 Subject: [PATCH 05/12] fix: simplify total calculation and add missing proptype --- .../LHNOptionsList/OptionRowLHNData.js | 9 +++++ src/libs/actions/IOU.js | 39 +++++++------------ 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/components/LHNOptionsList/OptionRowLHNData.js b/src/components/LHNOptionsList/OptionRowLHNData.js index eaa87497f28f..5d2faaed7a2d 100644 --- a/src/components/LHNOptionsList/OptionRowLHNData.js +++ b/src/components/LHNOptionsList/OptionRowLHNData.js @@ -45,6 +45,14 @@ const propTypes = { /** The actions from the parent report */ parentReportActions: PropTypes.objectOf(PropTypes.shape(reportActionPropTypes)), + /** The transactions from the parent report action */ + transactions: PropTypes.objectOf( + PropTypes.shape({ + /** The ID of the transaction */ + transactionID: PropTypes.string, + }), + ), + ...withCurrentReportIDPropTypes, ...basePropTypes, }; @@ -55,6 +63,7 @@ const defaultProps = { fullReport: {}, policies: {}, parentReportActions: {}, + transactions: {}, preferredLocale: CONST.LOCALES.DEFAULT, ...withCurrentReportIDDefaultProps, ...baseDefaultProps, diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index a27606f4d96f..94a289feae2e 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -959,49 +959,36 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC // STEP 3: Compute the IOU total and update the report preview message so LHN amount owed is correct // Should only update if the transaction matches the currency of the report, else we wait for the update // from the server with the currency conversion - let updatedIouReport = null; + let updatedMoneyRequestReport = null; const updatedChatReport = {...chatReport}; if (updatedTransaction.currency === iouReport.currency && updatedTransaction.modifiedAmount) { + const diff = TransactionUtils.getAmount(transaction, true) - TransactionUtils.getAmount(updatedTransaction, true); if (ReportUtils.isExpenseReport(iouReport)) { - updatedIouReport = {...iouReport}; - updatedIouReport.total -= TransactionUtils.getAmount(transaction, true); - updatedIouReport.total += TransactionUtils.getAmount(updatedTransaction, true); + updatedMoneyRequestReport = {...iouReport}; + updatedMoneyRequestReport.total += diff; } else { - updatedIouReport = IOUUtils.updateIOUOwnerAndTotal( - iouReport, - updatedReportAction.actorAccountID, - TransactionUtils.getAmount(transaction, false), - TransactionUtils.getCurrency(transaction), - true, - ); - updatedIouReport = IOUUtils.updateIOUOwnerAndTotal( - updatedIouReport, - updatedReportAction.actorAccountID, - TransactionUtils.getAmount(updatedTransaction, false), - TransactionUtils.getCurrency(updatedTransaction), - false, - ); + updatedMoneyRequestReport = IOUUtils.updateIOUOwnerAndTotal(iouReport, updatedReportAction.actorAccountID, diff, TransactionUtils.getCurrency(transaction), false); } - updatedIouReport.cachedTotal = CurrencyUtils.convertToDisplayString(updatedIouReport.total, updatedTransaction.currency); + updatedMoneyRequestReport.cachedTotal = CurrencyUtils.convertToDisplayString(updatedMoneyRequestReport.total, updatedTransaction.currency); - // Update the last message of the IOU report + // Update the last message of the chat report const lastMessage = ReportUtils.getIOUReportActionMessage( iouReport.reportID, CONST.IOU.REPORT_ACTION_TYPE.CREATE, - updatedIouReport.total, + updatedMoneyRequestReport.total, '', updatedTransaction.currency, '', false, ); - updatedIouReport.lastMessageText = lastMessage[0].text; - updatedIouReport.lastMessageHtml = lastMessage[0].html; + updatedMoneyRequestReport.lastMessageText = lastMessage[0].text; + updatedMoneyRequestReport.lastMessageHtml = lastMessage[0].html; // Update the last message of the IOU chat report const messageText = Localize.translateLocal('iou.payerOwesAmount', { - payer: updatedIouReport.managerEmail, - amount: CurrencyUtils.convertToDisplayString(updatedIouReport.total, updatedIouReport.currency), + payer: updatedMoneyRequestReport.managerEmail, + amount: CurrencyUtils.convertToDisplayString(updatedMoneyRequestReport.total, updatedMoneyRequestReport.currency), }); updatedChatReport.lastMessageText = messageText; updatedChatReport.lastMessageHtml = messageText; @@ -1024,7 +1011,7 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, - value: updatedIouReport, + value: updatedMoneyRequestReport, }, { onyxMethod: Onyx.METHOD.MERGE, From db3cf8a22e2162b00613fcd7027bfb2c6123aa1c Mon Sep 17 00:00:00 2001 From: Ana Margarida Silva Date: Thu, 24 Aug 2023 10:04:19 +0100 Subject: [PATCH 06/12] fix: small fix --- src/libs/actions/IOU.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 94a289feae2e..7db4f86d11ed 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -972,7 +972,7 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC updatedMoneyRequestReport.cachedTotal = CurrencyUtils.convertToDisplayString(updatedMoneyRequestReport.total, updatedTransaction.currency); - // Update the last message of the chat report + // Update the last message of the IOU report const lastMessage = ReportUtils.getIOUReportActionMessage( iouReport.reportID, CONST.IOU.REPORT_ACTION_TYPE.CREATE, @@ -985,7 +985,7 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC updatedMoneyRequestReport.lastMessageText = lastMessage[0].text; updatedMoneyRequestReport.lastMessageHtml = lastMessage[0].html; - // Update the last message of the IOU chat report + // Update the last message of the chat report const messageText = Localize.translateLocal('iou.payerOwesAmount', { payer: updatedMoneyRequestReport.managerEmail, amount: CurrencyUtils.convertToDisplayString(updatedMoneyRequestReport.total, updatedMoneyRequestReport.currency), From ea2926fce2a65eb3c1619aaecaaf0449bf68fb7e Mon Sep 17 00:00:00 2001 From: Ana Margarida Silva Date: Thu, 24 Aug 2023 10:54:59 +0100 Subject: [PATCH 07/12] feat: improve prop composition --- .../LHNOptionsList/OptionRowLHNData.js | 59 +++++++++---------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/src/components/LHNOptionsList/OptionRowLHNData.js b/src/components/LHNOptionsList/OptionRowLHNData.js index 5d2faaed7a2d..d6479f34851b 100644 --- a/src/components/LHNOptionsList/OptionRowLHNData.js +++ b/src/components/LHNOptionsList/OptionRowLHNData.js @@ -30,28 +30,24 @@ const propTypes = { // eslint-disable-next-line react/forbid-prop-types fullReport: PropTypes.object, - /** The policies which the user has access to and which the report could be tied to */ - policies: PropTypes.objectOf( - PropTypes.shape({ - /** The ID of the policy */ - id: PropTypes.string, - /** Name of the policy */ - name: PropTypes.string, - /** Avatar of the policy */ - avatar: PropTypes.string, - }), - ), + /** The policy which the user has access to and which the report could be tied to */ + policy: PropTypes.shape({ + /** The ID of the policy */ + id: PropTypes.string, + /** Name of the policy */ + name: PropTypes.string, + /** Avatar of the policy */ + avatar: PropTypes.string, + }), /** The actions from the parent report */ parentReportActions: PropTypes.objectOf(PropTypes.shape(reportActionPropTypes)), - /** The transactions from the parent report action */ - transactions: PropTypes.objectOf( - PropTypes.shape({ - /** The ID of the transaction */ - transactionID: PropTypes.string, - }), - ), + /** The transaction from the parent report action */ + transaction: PropTypes.shape({ + /** The ID of the transaction */ + transactionID: PropTypes.string, + }), ...withCurrentReportIDPropTypes, ...basePropTypes, @@ -61,9 +57,9 @@ const defaultProps = { shouldDisableFocusOptions: false, personalDetails: {}, fullReport: {}, - policies: {}, + policy: {}, parentReportActions: {}, - transactions: {}, + transaction: {}, preferredLocale: CONST.LOCALES.DEFAULT, ...withCurrentReportIDDefaultProps, ...baseDefaultProps, @@ -83,9 +79,9 @@ function OptionRowLHNData({ personalDetails, preferredLocale, comment, - policies, + policy, parentReportActions, - transactions, + transaction, ...propsToForward }) { const reportID = propsToForward.reportID; @@ -93,11 +89,7 @@ function OptionRowLHNData({ // instead of a changing number (so we prevent unnecessary re-renders). const isFocused = !shouldDisableFocusOptions && currentReportID === reportID; - const policy = lodashGet(policies, [`${ONYXKEYS.COLLECTION.POLICY}${fullReport.policyID}`], ''); - const parentReportAction = parentReportActions[fullReport.parentReportActionID]; - const transactionID = lodashGet(parentReportAction, ['originalMessage', 'IOUTransactionID'], ''); - const transaction = lodashGet(transactions, [`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`], ''); const optionItemRef = useRef(); const optionItem = useMemo(() => { @@ -189,18 +181,21 @@ export default React.memo( preferredLocale: { key: ONYXKEYS.NVP_PREFERRED_LOCALE, }, - policies: { - key: ONYXKEYS.COLLECTION.POLICY, - }, - transactions: { - key: ONYXKEYS.COLLECTION.TRANSACTION, - }, }), withOnyx({ parentReportActions: { key: ({fullReport}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${fullReport.parentReportID}`, canEvict: false, }, + policy: { + key: ({fullReport}) => `${ONYXKEYS.COLLECTION.POLICY}${fullReport.policyID}`, + }, + }), + withOnyx({ + transaction: { + key: ({fullReport, parentReportActions}) => + `${ONYXKEYS.COLLECTION.TRANSACTION}${lodashGet(parentReportActions, [fullReport.parentReportActionID, 'originalMessage', 'IOUTransactionID'], '')}`, + }, }), )(OptionRowLHNData), ); From 4399aa174ab5467fd19341e8b61ca4683236780e Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Mon, 28 Aug 2023 20:14:36 +0200 Subject: [PATCH 08/12] fix: reset chatReport data on failure --- src/libs/actions/IOU.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 7db4f86d11ed..d1ee623a6839 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1065,6 +1065,11 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, value: iouReport, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.chatReportID}`, + value: chatReport, + }, ]; // STEP 6: Call the API endpoint From e89644cb4a0c1ec4f4edfad0d0fd866a2b789a8b Mon Sep 17 00:00:00 2001 From: Ana Margarida Silva Date: Mon, 11 Sep 2023 10:04:45 +0100 Subject: [PATCH 09/12] fix: prettier fix --- src/components/LHNOptionsList/OptionRowLHNData.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/LHNOptionsList/OptionRowLHNData.js b/src/components/LHNOptionsList/OptionRowLHNData.js index cdbe3b0f26d6..2c51d6332946 100644 --- a/src/components/LHNOptionsList/OptionRowLHNData.js +++ b/src/components/LHNOptionsList/OptionRowLHNData.js @@ -213,7 +213,7 @@ export default React.memo( transaction: { key: ({fullReport, parentReportActions}) => `${ONYXKEYS.COLLECTION.TRANSACTION}${lodashGet(parentReportActions, [fullReport.parentReportActionID, 'originalMessage', 'IOUTransactionID'], '')}`, - } + }, }), )(OptionRowLHNData), ); From 529180dade76fe8e35781c7b4f2282203dc783d3 Mon Sep 17 00:00:00 2001 From: Ana Margarida Silva Date: Tue, 12 Sep 2023 12:43:41 +0100 Subject: [PATCH 10/12] fix: update header when description changes --- src/components/MoneyRequestHeader.js | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/components/MoneyRequestHeader.js b/src/components/MoneyRequestHeader.js index f04a41ae1153..8e5fdfb29bf4 100644 --- a/src/components/MoneyRequestHeader.js +++ b/src/components/MoneyRequestHeader.js @@ -25,9 +25,6 @@ const propTypes = { /** The report currently being looked at */ report: iouReportPropTypes.isRequired, - /** The expense report or iou report (only will have a value if this is a transaction thread) */ - parentReport: iouReportPropTypes, - /** The policy which the report is tied to */ policy: PropTypes.shape({ /** Name of the policy */ @@ -37,12 +34,22 @@ const propTypes = { /** Personal details so we can get the ones for the report participants */ personalDetails: PropTypes.objectOf(participantPropTypes).isRequired, + /** Onyx Props */ /** Session info for the currently logged in user. */ session: PropTypes.shape({ /** Currently logged in user email */ email: PropTypes.string, }), + /** The expense report or iou report (only will have a value if this is a transaction thread) */ + parentReport: iouReportPropTypes, + + /** The transaction from the parent report action */ + transaction: PropTypes.shape({ + /** The ID of the transaction */ + transactionID: PropTypes.string, + }), + ...windowDimensionsPropTypes, }; @@ -51,6 +58,7 @@ const defaultProps = { email: null, }, parentReport: {}, + transaction: {}, }; function MoneyRequestHeader(props) { @@ -72,8 +80,7 @@ function MoneyRequestHeader(props) { setIsDeleteModalVisible(false); }, [parentReportAction, setIsDeleteModalVisible]); - const transaction = TransactionUtils.getLinkedTransaction(parentReportAction); - const isScanning = TransactionUtils.hasReceipt(transaction) && TransactionUtils.isReceiptBeingScanned(transaction); + const isScanning = TransactionUtils.hasReceipt(props.transaction) && TransactionUtils.isReceiptBeingScanned(props.transaction); return ( <> @@ -125,5 +132,15 @@ export default compose( parentReport: { key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`, }, + parentReportActions: { + key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`, + canEvict: false, + }, + }), + withOnyx({ + transaction: { + key: ({report, parentReportActions}) => + `${ONYXKEYS.COLLECTION.TRANSACTION}${lodashGet(parentReportActions, [report.parentReportActionID, 'originalMessage', 'IOUTransactionID'], '')}`, + }, }), )(MoneyRequestHeader); From 2590bdcc5409a4fede52321ed836da0935159a1a Mon Sep 17 00:00:00 2001 From: Ana Margarida Silva Date: Wed, 13 Sep 2023 09:13:49 +0100 Subject: [PATCH 11/12] fix: console error --- src/libs/actions/IOU.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 37246fdf102c..d0f392638a88 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -999,12 +999,11 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC // STEP 3: Compute the IOU total and update the report preview message so LHN amount owed is correct // Should only update if the transaction matches the currency of the report, else we wait for the update // from the server with the currency conversion - let updatedMoneyRequestReport = null; + let updatedMoneyRequestReport = {...iouReport}; const updatedChatReport = {...chatReport}; if (updatedTransaction.currency === iouReport.currency && updatedTransaction.modifiedAmount) { const diff = TransactionUtils.getAmount(transaction, true) - TransactionUtils.getAmount(updatedTransaction, true); if (ReportUtils.isExpenseReport(iouReport)) { - updatedMoneyRequestReport = {...iouReport}; updatedMoneyRequestReport.total += diff; } else { updatedMoneyRequestReport = IOUUtils.updateIOUOwnerAndTotal(iouReport, updatedReportAction.actorAccountID, diff, TransactionUtils.getCurrency(transaction), false); From 58346d1fc2da9937037a7dd74d19bd7fd39bdab8 Mon Sep 17 00:00:00 2001 From: Ana Margarida Silva Date: Thu, 14 Sep 2023 10:53:35 +0100 Subject: [PATCH 12/12] fix: do not use onyx subscription composition --- src/components/MoneyRequestHeader.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/components/MoneyRequestHeader.js b/src/components/MoneyRequestHeader.js index 8e5fdfb29bf4..bdd7365b7893 100644 --- a/src/components/MoneyRequestHeader.js +++ b/src/components/MoneyRequestHeader.js @@ -15,11 +15,11 @@ import Navigation from '../libs/Navigation/Navigation'; import ROUTES from '../ROUTES'; import ONYXKEYS from '../ONYXKEYS'; import * as IOU from '../libs/actions/IOU'; -import * as ReportActionsUtils from '../libs/ReportActionsUtils'; import ConfirmModal from './ConfirmModal'; import useLocalize from '../hooks/useLocalize'; import MoneyRequestHeaderStatusBar from './MoneyRequestHeaderStatusBar'; import * as TransactionUtils from '../libs/TransactionUtils'; +import reportActionPropTypes from '../pages/home/report/reportActionPropTypes'; const propTypes = { /** The report currently being looked at */ @@ -44,6 +44,9 @@ const propTypes = { /** The expense report or iou report (only will have a value if this is a transaction thread) */ parentReport: iouReportPropTypes, + /** The report action the transaction is tied to from the parent report */ + parentReportAction: PropTypes.shape(reportActionPropTypes), + /** The transaction from the parent report action */ transaction: PropTypes.shape({ /** The ID of the transaction */ @@ -58,6 +61,7 @@ const defaultProps = { email: null, }, parentReport: {}, + parentReportAction: {}, transaction: {}, }; @@ -67,18 +71,16 @@ function MoneyRequestHeader(props) { const moneyRequestReport = props.parentReport; const isSettled = ReportUtils.isSettled(moneyRequestReport.reportID); - const parentReportAction = ReportActionsUtils.getParentReportAction(props.report); - // Only the requestor can take delete the request, admins can only edit it. - const isActionOwner = parentReportAction.actorAccountID === lodashGet(props.session, 'accountID', null); + const isActionOwner = props.parentReportAction.actorAccountID === lodashGet(props.session, 'accountID', null); const report = props.report; report.ownerAccountID = lodashGet(props, ['parentReport', 'ownerAccountID'], null); report.ownerEmail = lodashGet(props, ['parentReport', 'ownerEmail'], ''); const deleteTransaction = useCallback(() => { - IOU.deleteMoneyRequest(parentReportAction.originalMessage.IOUTransactionID, parentReportAction, true); + IOU.deleteMoneyRequest(props.parentReportAction.originalMessage.IOUTransactionID, props.parentReportAction, true); setIsDeleteModalVisible(false); - }, [parentReportAction, setIsDeleteModalVisible]); + }, [props.parentReportAction, setIsDeleteModalVisible]); const isScanning = TransactionUtils.hasReceipt(props.transaction) && TransactionUtils.isReceiptBeingScanned(props.transaction); @@ -92,7 +94,7 @@ function MoneyRequestHeader(props) { threeDotsMenuItems={[ { icon: Expensicons.Trashcan, - text: translate('reportActionContextMenu.deleteAction', {action: parentReportAction}), + text: translate('reportActionContextMenu.deleteAction', {action: props.parentReportAction}), onSelected: () => setIsDeleteModalVisible(true), }, ]} @@ -132,12 +134,11 @@ export default compose( parentReport: { key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`, }, - parentReportActions: { - key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`, + parentReportAction: { + key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${(report.parentReportID, report.parentReportActionID)}`, + selector: (reportActions, props) => props && props.parentReport && reportActions && reportActions[props.parentReport.parentReportActionID], canEvict: false, }, - }), - withOnyx({ transaction: { key: ({report, parentReportActions}) => `${ONYXKEYS.COLLECTION.TRANSACTION}${lodashGet(parentReportActions, [report.parentReportActionID, 'originalMessage', 'IOUTransactionID'], '')}`,