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

Show transaction amount & description in report header for "transaction thread" #18695

Merged
merged 18 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from 15 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
55 changes: 49 additions & 6 deletions src/components/MoneyRequestHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import lodashGet from 'lodash/get';
import {withOnyx} from 'react-native-onyx';
import HeaderWithCloseButton from './HeaderWithCloseButton';
import iouReportPropTypes from '../pages/iouReportPropTypes';
import withLocalize, {withLocalizePropTypes} from './withLocalize';
Expand All @@ -19,11 +20,17 @@ import Navigation from '../libs/Navigation/Navigation';
import ROUTES from '../ROUTES';
import Icon from './Icon';
import * as CurrencyUtils from '../libs/CurrencyUtils';
import MenuItemWithTopDescription from './MenuItemWithTopDescription';
import DateUtils from '../libs/DateUtils';
import ONYXKEYS from '../ONYXKEYS';

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 policies which the user has access to and which the report could be tied to */
policies: PropTypes.shape({
/** Name of the policy */
Expand All @@ -41,15 +48,26 @@ const propTypes = {

const defaultProps = {
isSingleTransactionView: false,
parentReport: {},
};

const MoneyRequestHeader = (props) => {
// These are only used for the single transaction view and not "money requests"
const transactionAmount = lodashGet(props.parentReportAction, ['originalMessage', 'amount']);
const transactionCurrency = lodashGet(props.parentReportAction, ['originalMessage', 'currency']);
const transactionDescription = lodashGet(props.parentReportAction, ['originalMessage', 'comment']);
const formattedTransactionAmount = transactionAmount && transactionCurrency && CurrencyUtils.convertToDisplayString(transactionAmount, transactionCurrency);
const transactionDate = lodashGet(props.parentReportAction, ['created']);
const formattedTransactionDate = DateUtils.getDateStringFromISOTimestamp(transactionDate);

const formattedAmount = CurrencyUtils.convertToDisplayString(ReportUtils.getMoneyRequestTotal(props.report), props.report.currency);
const isSettled = ReportUtils.isSettled(props.report.reportID);
const isExpenseReport = ReportUtils.isExpenseReport(props.report);
const payeeName = isExpenseReport ? ReportUtils.getPolicyName(props.report, props.policies) : ReportUtils.getDisplayNameForParticipant(props.report.managerEmail);

const moneyRequestReport = props.isSingleTransactionView ? props.parentReport : props.report;
const isSettled = ReportUtils.isSettled(moneyRequestReport.reportID);
const isExpenseReport = ReportUtils.isExpenseReport(moneyRequestReport);
const payeeName = isExpenseReport ? ReportUtils.getPolicyName(moneyRequestReport, props.policies) : ReportUtils.getDisplayNameForParticipant(props.report.managerEmail);
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
const payeeAvatar = isExpenseReport
? ReportUtils.getWorkspaceAvatar(props.report)
? ReportUtils.getWorkspaceAvatar(moneyRequestReport)
: ReportUtils.getAvatar(lodashGet(props.personalDetails, [props.report.managerEmail, 'avatar']), props.report.managerEmail);
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
return (
<View style={[{backgroundColor: themeColors.highlightBG}, styles.pl0]}>
Expand All @@ -64,7 +82,7 @@ const MoneyRequestHeader = (props) => {
},
]}
threeDotsAnchorPosition={styles.threeDotsPopoverOffsetNoCloseButton}
report={props.report}
report={moneyRequestReport}
policies={props.policies}
personalDetails={props.personalDetails}
shouldShowCloseButton={false}
Expand Down Expand Up @@ -111,6 +129,23 @@ const MoneyRequestHeader = (props) => {
</View>
</View>
</View>
{props.isSingleTransactionView && (
<>
<MenuItemWithTopDescription
title={formattedTransactionAmount}
description="Amount • Cash"
titleStyle={styles.newKansasLarge}
/>
<MenuItemWithTopDescription
description="Description"
title={transactionDescription}
/>
<MenuItemWithTopDescription
description="Date"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We'll have to follow up and translate these

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we already have translation keys for these: Amount, Cash, Date, Description

title={formattedTransactionDate}
/>
</>
)}
</View>
);
};
Expand All @@ -119,4 +154,12 @@ MoneyRequestHeader.displayName = 'MoneyRequestHeader';
MoneyRequestHeader.propTypes = propTypes;
MoneyRequestHeader.defaultProps = defaultProps;

export default compose(withWindowDimensions, withLocalize)(MoneyRequestHeader);
export default compose(
withWindowDimensions,
withLocalize,
withOnyx({
parentReport: {
key: (props) => `${ONYXKEYS.COLLECTION.REPORT}${props.report.parentReportID}`,
},
}),
)(MoneyRequestHeader);
14 changes: 14 additions & 0 deletions src/libs/DateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,19 @@ function subtractMillisecondsFromDateTime(dateTime, milliseconds) {
return getDBTime(newTimestamp);
}

/**
* @param {string} isoTimestamp example: 2023-05-16 05:34:14.388
* @returns {string} example: 2023-05-16
*/
function getDateStringFromISOTimestamp(isoTimestamp) {
if (!isoTimestamp) {
return '';
}

const [dateString] = isoTimestamp.split(' ');
return dateString;
}

/**
* @namespace DateUtils
*/
Expand All @@ -206,6 +219,7 @@ const DateUtils = {
getMicroseconds,
getDBTime,
subtractMillisecondsFromDateTime,
getDateStringFromISOTimestamp,
};

export default DateUtils;
7 changes: 5 additions & 2 deletions src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ class ReportScreen extends React.Component {
// the moment the ReportScreen becomes unfrozen we want to start the animation of the placeholder skeleton content
// (which is shown, until all the actual views of the ReportScreen have been rendered)
const shouldAnimate = !shouldFreeze;

const parentReportAction = ReportActionsUtils.getParentReportAction(this.props.report);
const isSingleTransactionView = ReportActionsUtils.isTransactionThread(parentReportAction);
return (
<ScreenWrapper style={screenWrapperStyle}>
<Freeze
Expand Down Expand Up @@ -281,11 +282,13 @@ class ReportScreen extends React.Component {
errors={addWorkspaceRoomOrChatErrors}
shouldShowErrorMessages={false}
>
{ReportUtils.isMoneyRequestReport(this.props.report) ? (
{ReportUtils.isMoneyRequestReport(this.props.report) || isSingleTransactionView ? (
<MoneyRequestHeader
report={this.props.report}
policies={this.props.policies}
personalDetails={this.props.personalDetails}
isSingleTransactionView={isSingleTransactionView}
parentReportAction={parentReportAction}
/>
) : (
<HeaderView
Expand Down