Skip to content

Commit

Permalink
Merge pull request Expensify#22562 from Expensify/georgia-expenseRequ…
Browse files Browse the repository at this point in the history
…estView

Update Expense Request Headers / Empty State
  • Loading branch information
Gonals authored Jul 19, 2023
2 parents e19a620 + b9d2df8 commit 9508dfa
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 31 deletions.
18 changes: 7 additions & 11 deletions src/components/MoneyRequestHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -46,29 +43,27 @@ const propTypes = {
};

const defaultProps = {
isSingleTransactionView: false,
session: {
email: null,
},
parentReport: {},
};

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 (
<View style={[styles.highlightBG, styles.pl0]}>
<View style={[styles.pl0]}>
<HeaderWithBackButton
shouldShowAvatarWithDisplay
shouldShowPinButton={props.isSingleTransactionView}
shouldShowThreeDotsButton={!isPayer && !isSettled && props.isSingleTransactionView}
shouldShowPinButton={false}
shouldShowThreeDotsButton={!isPayer && !isSettled}
threeDotsMenuItems={[
{
icon: Expensicons.Trashcan,
Expand All @@ -82,6 +77,7 @@ function MoneyRequestHeader(props) {
personalDetails={props.personalDetails}
shouldShowBackButton={props.isSmallScreenWidth}
onBackButtonPress={() => Navigation.goBack(ROUTES.HOME, false, true)}
shouldShowBorderBottom
/>
</View>
);
Expand Down
102 changes: 102 additions & 0 deletions src/components/ReportActionItem/MoneyRequestView.js
Original file line number Diff line number Diff line change
@@ -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 (
<View>
<View style={[StyleUtils.getReportWelcomeContainerStyle(props.isSmallScreenWidth), StyleUtils.getMinimumHeight(CONST.EMPTY_STATE_BACKGROUND.MONEY_REPORT.MIN_HEIGHT)]}>
<Image
pointerEvents="none"
source={EmptyStateBackgroundImage}
style={[StyleUtils.getReportWelcomeBackgroundImageStyle(true)]}
/>
</View>
<MenuItemWithTopDescription
title={formattedTransactionAmount}
shouldShowTitleIcon={isSettled}
titleIcon={Expensicons.Checkmark}
description={`${translate('iou.amount')}${translate('iou.cash')}${isSettled ? ` • ${translate('iou.settledExpensify')}` : ''}`}
titleStyle={styles.newKansasLarge}
disabled={isSettled}
// Note: These options are temporarily disabled while we figure out the required API changes
// shouldShowRightIcon={!isSettled}
// onPress={() => Navigation.navigate(ROUTES.getEditRequestRoute(props.report.reportID, CONST.EDIT_REQUEST_FIELD.AMOUNT))}
/>
<MenuItemWithTopDescription
description={translate('common.description')}
title={transactionDescription}
disabled={isSettled}
// shouldShowRightIcon={!isSettled}
// onPress={() => Navigation.navigate(ROUTES.getEditRequestRoute(props.report.reportID, CONST.EDIT_REQUEST_FIELD.DESCRIPTION))}
/>
<MenuItemWithTopDescription
description={translate('common.date')}
title={formattedTransactionDate}
// shouldShowRightIcon={!isSettled}
// onPress={() => Navigation.navigate(ROUTES.getEditRequestRoute(props.report.reportID, CONST.EDIT_REQUEST_FIELD.DATE))}
/>
{props.shouldShowHorizontalRule && <View style={styles.reportHorizontalRule} />}
</View>
);
}

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);
12 changes: 11 additions & 1 deletion src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 = {
Expand Down Expand Up @@ -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 (
<MoneyRequestView
report={props.report}
shouldShowHorizontalRule={!props.isOnlyReportAction}
/>
);
}
if (ReportUtils.isTaskReport(props.report)) {
return (
<TaskView
Expand Down
24 changes: 5 additions & 19 deletions src/pages/home/report/ReportActionsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import reportPropTypes from '../../reportPropTypes';
import networkPropTypes from '../../../components/networkPropTypes';
import withLocalize from '../../../components/withLocalize';
import useReportScrollManager from '../../../hooks/useReportScrollManager';
import MoneyRequestDetails from '../../../components/MoneyRequestDetails';

const propTypes = {
/** Position of the "New" line marker */
Expand Down Expand Up @@ -126,7 +125,10 @@ function ReportActionsList(props) {
({item: reportAction, index}) => {
// 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 ? (
Expand Down Expand Up @@ -160,24 +162,19 @@ 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 (
<Animated.View style={[animatedStyles, styles.flex1]}>
<InvertedFlatList
accessibilityLabel={props.translate('sidebarScreen.listOfChatMessages')}
ref={reportScrollManager.ref}
data={props.sortedReportActions}
renderItem={renderItem}
contentContainerStyle={[styles.chatContentScrollView, shouldShowReportRecipientLocalTime && styles.pt0, showMoneyRequestDetails && styles.pb0]}
contentContainerStyle={[styles.chatContentScrollView, shouldShowReportRecipientLocalTime]}
keyExtractor={keyExtractor}
initialRowHeight={32}
initialNumToRender={calculateInitialNumToRender()}
onEndReached={props.loadMoreChats}
onEndReachedThreshold={0.75}
ListFooterComponentStyle={showMoneyRequestDetails ? styles.chatFooterAtTheTop : {}}
ListFooterComponent={() => {
if (props.report.isLoadingMoreReportActions) {
return <ReportActionsSkeletonView containerHeight={CONST.CHAT_SKELETON_VIEW.AVERAGE_ROW_HEIGHT * 3} />;
Expand All @@ -195,17 +192,6 @@ function ReportActionsList(props) {
/>
);
}
if (showMoneyRequestDetails) {
return (
<MoneyRequestDetails
report={props.report}
policy={props.policy}
personalDetails={props.personalDetailsList}
isSingleTransactionView={isSingleTransactionView}
parentReportAction={parentReportAction}
/>
);
}
return null;
}}
keyboardShouldPersistTaps="handled"
Expand Down

0 comments on commit 9508dfa

Please sign in to comment.