diff --git a/src/components/MoneyRequestHeader.js b/src/components/MoneyRequestHeader.js index cb2ec4b3accc..a53aa476ff48 100644 --- a/src/components/MoneyRequestHeader.js +++ b/src/components/MoneyRequestHeader.js @@ -33,9 +33,6 @@ const propTypes = { /** Personal details so we can get the ones for the report participants */ personalDetails: PropTypes.objectOf(participantPropTypes).isRequired, - /** Whether we're viewing a report with a single transaction in it */ - isSingleTransactionView: PropTypes.bool, - /** Session info for the currently logged in user. */ session: PropTypes.shape({ /** Currently logged in user email */ @@ -46,7 +43,6 @@ const propTypes = { }; const defaultProps = { - isSingleTransactionView: false, session: { email: null, }, @@ -54,21 +50,20 @@ const defaultProps = { }; function MoneyRequestHeader(props) { - const moneyRequestReport = props.isSingleTransactionView ? props.parentReport : props.report; + const moneyRequestReport = props.parentReport; const isSettled = ReportUtils.isSettled(moneyRequestReport.reportID); const policy = props.policies[`${ONYXKEYS.COLLECTION.POLICY}${props.report.policyID}`]; const isPayer = Policy.isAdminOfFreePolicy([policy]) || (ReportUtils.isMoneyRequestReport(moneyRequestReport) && lodashGet(props.session, 'accountID', null) === moneyRequestReport.managerID); const report = props.report; - if (props.isSingleTransactionView) { - report.ownerAccountID = lodashGet(props, ['parentReport', 'ownerAccountID'], null); - } + report.ownerAccountID = lodashGet(props, ['parentReport', 'ownerAccountID'], null); + report.ownerEmail = lodashGet(props, ['parentReport', 'ownerEmail'], ''); return ( - + Navigation.goBack(ROUTES.HOME, false, true)} + shouldShowBorderBottom /> ); diff --git a/src/components/ReportActionItem/MoneyRequestView.js b/src/components/ReportActionItem/MoneyRequestView.js new file mode 100644 index 000000000000..06cb6465fccd --- /dev/null +++ b/src/components/ReportActionItem/MoneyRequestView.js @@ -0,0 +1,102 @@ +import React from 'react'; +import {View, Image} from 'react-native'; +import {withOnyx} from 'react-native-onyx'; +import lodashGet from 'lodash/get'; +import PropTypes from 'prop-types'; +import reportPropTypes from '../../pages/reportPropTypes'; +import ONYXKEYS from '../../ONYXKEYS'; +import withWindowDimensions from '../withWindowDimensions'; +import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsPropTypes} from '../withCurrentUserPersonalDetails'; +import compose from '../../libs/compose'; +import MenuItemWithTopDescription from '../MenuItemWithTopDescription'; +import styles from '../../styles/styles'; +import * as ReportUtils from '../../libs/ReportUtils'; +import * as ReportActionsUtils from '../../libs/ReportActionsUtils'; +import * as StyleUtils from '../../styles/StyleUtils'; +import CONST from '../../CONST'; +import * as Expensicons from '../Icon/Expensicons'; +import iouReportPropTypes from '../../pages/iouReportPropTypes'; +import DateUtils from '../../libs/DateUtils'; +import * as CurrencyUtils from '../../libs/CurrencyUtils'; +import EmptyStateBackgroundImage from '../../../assets/images/empty-state_background-fade.png'; +import useLocalize from '../../hooks/useLocalize'; + +const propTypes = { + /** The report currently being looked at */ + report: reportPropTypes.isRequired, + + /** The expense report or iou report (only will have a value if this is a transaction thread) */ + parentReport: iouReportPropTypes, + + /** Whether we should display the horizontal rule below the component */ + shouldShowHorizontalRule: PropTypes.bool.isRequired, + + ...withCurrentUserPersonalDetailsPropTypes, +}; + +const defaultProps = { + parentReport: {}, +}; + +function MoneyRequestView(props) { + const parentReportAction = ReportActionsUtils.getParentReportAction(props.report); + const {amount: transactionAmount, currency: transactionCurrency, comment: transactionDescription} = ReportUtils.getMoneyRequestAction(parentReportAction); + const formattedTransactionAmount = transactionAmount && transactionCurrency && CurrencyUtils.convertToDisplayString(transactionAmount, transactionCurrency); + const transactionDate = lodashGet(parentReportAction, ['created']); + const formattedTransactionDate = DateUtils.getDateStringFromISOTimestamp(transactionDate); + + const moneyRequestReport = props.parentReport; + const isSettled = ReportUtils.isSettled(moneyRequestReport.reportID); + const {translate} = useLocalize(); + + return ( + + + + + Navigation.navigate(ROUTES.getEditRequestRoute(props.report.reportID, CONST.EDIT_REQUEST_FIELD.AMOUNT))} + /> + Navigation.navigate(ROUTES.getEditRequestRoute(props.report.reportID, CONST.EDIT_REQUEST_FIELD.DESCRIPTION))} + /> + Navigation.navigate(ROUTES.getEditRequestRoute(props.report.reportID, CONST.EDIT_REQUEST_FIELD.DATE))} + /> + {props.shouldShowHorizontalRule && } + + ); +} + +MoneyRequestView.propTypes = propTypes; +MoneyRequestView.defaultProps = defaultProps; +MoneyRequestView.displayName = 'MoneyRequestView'; + +export default compose( + withWindowDimensions, + withCurrentUserPersonalDetails, + withOnyx({ + parentReport: { + key: (props) => `${ONYXKEYS.COLLECTION.REPORT}${props.report.parentReportID}`, + }, + }), +)(MoneyRequestView); diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 710df7e30f9c..b795dc460cd5 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -36,9 +36,9 @@ import SelectionScraper from '../../../libs/SelectionScraper'; import focusTextInputAfterAnimation from '../../../libs/focusTextInputAfterAnimation'; import * as User from '../../../libs/actions/User'; import * as ReportUtils from '../../../libs/ReportUtils'; +import * as ReportActionsUtils from '../../../libs/ReportActionsUtils'; import OfflineWithFeedback from '../../../components/OfflineWithFeedback'; import * as ReportActions from '../../../libs/actions/ReportActions'; -import * as ReportActionsUtils from '../../../libs/ReportActionsUtils'; import reportPropTypes from '../../reportPropTypes'; import {ShowContextMenuContext} from '../../../components/ShowContextMenuContext'; import ChronosOOOListActions from '../../../components/ReportActionItem/ChronosOOOListActions'; @@ -57,6 +57,7 @@ import TaskAction from '../../../components/ReportActionItem/TaskAction'; import TaskView from '../../../components/ReportActionItem/TaskView'; import MoneyReportView from '../../../components/ReportActionItem/MoneyReportView'; import * as Session from '../../../libs/actions/Session'; +import MoneyRequestView from '../../../components/ReportActionItem/MoneyRequestView'; import {hideContextMenu} from './ContextMenu/ReportActionContextMenu'; const propTypes = { @@ -416,6 +417,15 @@ function ReportActionItem(props) { }; if (props.action.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED) { + const parentReport = ReportActionsUtils.getParentReportAction(props.report); + if (ReportActionsUtils.isTransactionThread(parentReport)) { + return ( + + ); + } if (ReportUtils.isTaskReport(props.report)) { return ( { // When the new indicator should not be displayed we explicitly set it to null const shouldDisplayNewMarker = reportAction.reportActionID === newMarkerReportActionID; - const shouldDisplayParentAction = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED && ReportUtils.isChatThread(report); + const shouldDisplayParentAction = + reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED && + ReportUtils.isChatThread(report) && + !ReportActionsUtils.isTransactionThread(ReportActionsUtils.getParentReportAction(report)); const shouldHideThreadDividerLine = shouldDisplayParentAction && sortedReportActions.length > 1 && sortedReportActions[sortedReportActions.length - 2].reportActionID === newMarkerReportActionID; return shouldDisplayParentAction ? ( @@ -160,10 +162,6 @@ function ReportActionsList(props) { // To notify there something changes we can use extraData prop to flatlist const extraData = [props.isSmallScreenWidth ? props.newMarkerReportActionID : undefined, ReportUtils.isArchivedRoom(props.report)]; const shouldShowReportRecipientLocalTime = ReportUtils.canShowReportRecipientLocalTime(props.personalDetailsList, props.report, props.currentUserPersonalDetails.accountID); - - const parentReportAction = ReportActionsUtils.getParentReportAction(props.report); - const isSingleTransactionView = ReportActionsUtils.isTransactionThread(parentReportAction); - const showMoneyRequestDetails = isSingleTransactionView; return ( { if (props.report.isLoadingMoreReportActions) { return ; @@ -195,17 +192,6 @@ function ReportActionsList(props) { /> ); } - if (showMoneyRequestDetails) { - return ( - - ); - } return null; }} keyboardShouldPersistTaps="handled"