Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove data from being sideloaded in the money request header #27286

Merged
merged 12 commits into from
Sep 19, 2023
41 changes: 22 additions & 19 deletions src/components/MoneyRequestHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import useLocalize from '../hooks/useLocalize';
import MoneyRequestHeaderStatusBar from './MoneyRequestHeaderStatusBar';
import * as TransactionUtils from '../libs/TransactionUtils';
import reportActionPropTypes from '../pages/home/report/reportActionPropTypes';
import transactionPropTypes from './transactionPropTypes';

const propTypes = {
/** The report currently being looked at */
Expand All @@ -34,7 +35,9 @@ const propTypes = {
/** Personal details so we can get the ones for the report participants */
personalDetails: PropTypes.objectOf(participantPropTypes).isRequired,

/** Onyx Props */
...windowDimensionsPropTypes,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is function component, let's use useWindowDimensions hook


/* Onyx Props */
/** Session info for the currently logged in user. */
session: PropTypes.shape({
/** Currently logged in user email */
Expand All @@ -47,11 +50,8 @@ const propTypes = {
/** 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 */
transactionID: PropTypes.string,
}),
/** All the data for the transaction */
transaction: transactionPropTypes,

...windowDimensionsPropTypes,
};
Expand All @@ -65,24 +65,24 @@ const defaultProps = {
transaction: {},
};

function MoneyRequestHeader(props) {
function MoneyRequestHeader({session, parentReport, report, parentReportAction, transaction, policy, personalDetails, isSmallScreenWidth, windowWidth}) {
const {translate} = useLocalize();
const [isDeleteModalVisible, setIsDeleteModalVisible] = useState(false);
const moneyRequestReport = props.parentReport;
const moneyRequestReport = parentReport;
const isSettled = ReportUtils.isSettled(moneyRequestReport.reportID);

// Only the requestor can take delete the request, admins can only edit it.
const isActionOwner = props.parentReportAction.actorAccountID === lodashGet(props.session, 'accountID', null);
const isActionOwner = lodashGet(parentReportAction, 'actorAccountID') === lodashGet(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(props.parentReportAction.originalMessage.IOUTransactionID, props.parentReportAction, true);
IOU.deleteMoneyRequest(lodashGet(parentReportAction, 'originalMessage.IOUTransactionID'), parentReportAction, true);
setIsDeleteModalVisible(false);
}, [props.parentReportAction, setIsDeleteModalVisible]);
}, [parentReportAction, setIsDeleteModalVisible]);

const isScanning = TransactionUtils.hasReceipt(props.transaction) && TransactionUtils.isReceiptBeingScanned(props.transaction);
const isScanning = TransactionUtils.hasReceipt(transaction) && TransactionUtils.isReceiptBeingScanned(transaction);

return (
<>
Expand All @@ -98,11 +98,15 @@ function MoneyRequestHeader(props) {
onSelected: () => setIsDeleteModalVisible(true),
},
]}
threeDotsAnchorPosition={styles.threeDotsPopoverOffsetNoCloseButton(props.windowWidth)}
report={report}
policy={props.policy}
personalDetails={props.personalDetails}
shouldShowBackButton={props.isSmallScreenWidth}
threeDotsAnchorPosition={styles.threeDotsPopoverOffsetNoCloseButton(windowWidth)}
report={{
...report,
ownerAccountID: lodashGet(parentReport, 'ownerAccountID', null),
ownerEmail: lodashGet(parentReport, 'ownerEmail', null),
}}
policy={policy}
personalDetails={personalDetails}
shouldShowBackButton={isSmallScreenWidth}
onBackButtonPress={() => Navigation.goBack(ROUTES.HOME, false, true)}
/>
{isScanning && <MoneyRequestHeaderStatusBar />}
Expand Down Expand Up @@ -140,8 +144,7 @@ export default compose(
canEvict: false,
},
transaction: {
key: ({report, parentReportActions}) =>
`${ONYXKEYS.COLLECTION.TRANSACTION}${lodashGet(parentReportActions, [report.parentReportActionID, 'originalMessage', 'IOUTransactionID'], '')}`,
key: ({parentReportAction}) => `${ONYXKEYS.COLLECTION.TRANSACTION}${lodashGet(parentReportAction, 'originalMessage.IOUTransactionID', 0)}`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! parentReportActions -> parentReportAction
Seems like fixing regression from #25498

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! I spotted that and wanted to fix it here.

},
}),
)(MoneyRequestHeader);
1 change: 1 addition & 0 deletions src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ function isThreadParentMessage(reportAction = {}, reportID) {
* @param {Object} report
* @param {Object} [allReportActionsParam]
* @returns {Object}
* @deprecated Use Onyx.connect() or withOnyx() instead
*/
function getParentReportAction(report, allReportActionsParam = undefined) {
if (!report || !report.parentReportID || !report.parentReportActionID) {
Expand Down
2 changes: 2 additions & 0 deletions src/libs/TransactionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ function getUpdatedTransaction(transaction, transactionChanges, isFromExpenseRep
*
* @param {String} transactionID
* @returns {Object}
* @deprecated Use withOnyx() or Onyx.connect() instead
*/
function getTransaction(transactionID) {
return lodashGet(allTransactions, `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {});
Expand Down Expand Up @@ -291,6 +292,7 @@ function hasMissingSmartscanFields(transaction) {
*
* @param {Object} reportAction
* @returns {Object}
* @deprecated Use Onyx.connect() or withOnyx() instead
*/
function getLinkedTransaction(reportAction = {}) {
const transactionID = lodashGet(reportAction, ['originalMessage', 'IOUTransactionID'], '');
Expand Down
Loading