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

Add subscriber to money request view to immediately update view #25435

Merged
merged 9 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/components/ReportActionItem/MoneyRequestView.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import MenuItemWithTopDescription from '../MenuItemWithTopDescription';
import styles from '../../styles/styles';
import * as ReportUtils from '../../libs/ReportUtils';
import * as ReportActionsUtils from '../../libs/ReportActionsUtils';
import * as TransactionUtils from '../../libs/TransactionUtils';
import * as StyleUtils from '../../styles/StyleUtils';
import CONST from '../../CONST';
import * as Expensicons from '../Icon/Expensicons';
Expand All @@ -24,8 +23,10 @@ import EmptyStateBackgroundImage from '../../../assets/images/empty-state_backgr
import useLocalize from '../../hooks/useLocalize';
import * as ReceiptUtils from '../../libs/ReceiptUtils';
import useWindowDimensions from '../../hooks/useWindowDimensions';
import transactionPropTypes from '../transactionPropTypes';
import Image from '../Image';
import ReportActionItemImage from './ReportActionItemImage';
import * as TransactionUtils from '../../libs/TransactionUtils';
import OfflineWithFeedback from '../OfflineWithFeedback';

const propTypes = {
Expand All @@ -50,6 +51,9 @@ const propTypes = {
email: PropTypes.string,
}),

/** The transaction associated with the transactionThread */
transaction: transactionPropTypes,

/** Whether we should display the horizontal rule below the component */
shouldShowHorizontalRule: PropTypes.bool.isRequired,

Expand All @@ -62,15 +66,19 @@ const defaultProps = {
session: {
email: null,
},
transaction: {
amount: 0,
currency: CONST.CURRENCY.USD,
comment: {comment: ''},
},
};

function MoneyRequestView({report, parentReport, shouldShowHorizontalRule, policy, session}) {
function MoneyRequestView({report, parentReport, shouldShowHorizontalRule, policy, session, transaction}) {
const {isSmallScreenWidth} = useWindowDimensions();
const {translate} = useLocalize();

const parentReportAction = ReportActionsUtils.getParentReportAction(report);
const moneyRequestReport = parentReport;
const transaction = TransactionUtils.getLinkedTransaction(parentReportAction);
const {
created: transactionDate,
amount: transactionAmount,
Expand Down Expand Up @@ -181,5 +189,12 @@ export default compose(
session: {
key: ONYXKEYS.SESSION,
},
transaction: {
key: ({report}) => {
const parentReportAction = ReportActionsUtils.getParentReportAction(report);
const transactionID = lodashGet(parentReportAction, ['originalMessage', 'IOUTransactionID'], 0);
return `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`;
},
},
}),
)(MoneyRequestView);
48 changes: 48 additions & 0 deletions src/components/transactionPropTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import PropTypes from 'prop-types';

export default PropTypes.shape({
/** The transaction id */
transactionID: PropTypes.string,

/** The iouReportID associated with the transaction */
reportID: PropTypes.string,

/** The original transaction amount */
amount: PropTypes.number,

/** The edited transaction amount */
modifiedAmount: PropTypes.number,

/** The original created data */
created: PropTypes.string,

/** The edited transaction date */
modifiedCreated: PropTypes.string,

/** The filename of the associated receipt */
filename: PropTypes.string,

/** The original merchant name */
merchant: PropTypes.string,

/** The edited merchant name */
modifiedMerchant: PropTypes.string,

/** The comment added to the transaction */
comment: PropTypes.shape({
comment: PropTypes.string,
}),

/** The original currency of the transaction */
currency: PropTypes.string,

/** The edited currency of the transaction */
modifiedCurrency: PropTypes.string,

/** The receipt object associated with the transaction */
receipt: PropTypes.shape({
receiptID: PropTypes.string,
source: PropTypes.string,
state: PropTypes.string,
}),
});
Loading