From 58346d1fc2da9937037a7dd74d19bd7fd39bdab8 Mon Sep 17 00:00:00 2001 From: Ana Margarida Silva Date: Thu, 14 Sep 2023 10:53:35 +0100 Subject: [PATCH] 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'], '')}`,