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

Implement the RequestPreview component and update the IOUPreview #18486

Merged
merged 33 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
fc98c90
when an iouAction is available, display the individual action amount …
Julesssss May 5, 2023
1b1b7a2
render the IOUQuote beneath the IOUPreview, but only if it's the most…
Julesssss May 5, 2023
9c978b7
provide iouQuote with iouReport data
Julesssss May 5, 2023
2dd9a6e
make IOUQuote component UI a variable to make it more readable
Julesssss May 5, 2023
2646f5d
start showing report currency in reportpreview
Julesssss May 5, 2023
5303a67
use correct currency for iouPreview depending on parent component
Julesssss May 5, 2023
5bdaf09
Merge branch 'jules-iouPreview-showForBillSplit' into jules-displayRe…
Julesssss May 5, 2023
9486956
Merge branch 'main' into jules-displayReportPreview
Julesssss May 9, 2023
12d9723
clear up code and resolve lint issues
Julesssss May 9, 2023
7d0c14b
reintroduce formatted amount string for ReportPreview
Julesssss May 9, 2023
52a11db
use report manager name for ReportPreview 'x owes' message
Julesssss May 9, 2023
bbf574c
show the 'settled' icon on a report preview if paid
Julesssss May 9, 2023
c1bf09e
report preview should show 'settled up' message if paid
Julesssss May 9, 2023
a28855f
rename IOUQuote as ReportPreview
Julesssss May 9, 2023
1299309
update missing reference to the new report preview component name
Julesssss May 9, 2023
088bcbd
fix minor lint issue
Julesssss May 9, 2023
4a75695
Merge branch 'main' into jules-displayReportPreview
Julesssss May 10, 2023
f41dca8
run npm prettier
Julesssss May 10, 2023
3ba7186
add pay button to the report preview component
Julesssss May 10, 2023
4523766
navigate to IOUDetails when pay button is pressed
Julesssss May 10, 2023
7f5a1fb
only show pay button if the report is outstanding, and only show to t…
Julesssss May 10, 2023
bb13b69
stop showing pay button in IOUPreview
Julesssss May 10, 2023
d86fbbd
add Spanish translation for request preview strings
Julesssss May 10, 2023
8e5afd0
add missing session prop
Julesssss May 10, 2023
cb2a047
switch to prop, to avoid needing action data
Julesssss May 10, 2023
8e3fb1c
Merge branch 'main' into jules-displayReportPreview
Julesssss May 11, 2023
155d43d
align main changes with PR, re-add request currency logic
Julesssss May 11, 2023
a4f3345
Merge branch 'main' into jules-displayReportPreview
Julesssss May 11, 2023
fa60306
remove chevron icon from IOUPreview component
Julesssss May 11, 2023
6851675
add isSettled, rm default comment, standardize on CurrencyUtils.conve…
luacmartins May 11, 2023
f472b62
fix keys passes to strings for rendering
bondydaa May 11, 2023
91ced53
Merge branch 'main' into jules-displayReportPreview
Julesssss May 12, 2023
4237d03
apply style fixes
Julesssss May 12, 2023
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
8 changes: 3 additions & 5 deletions src/components/MoneyRequestHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import compose from '../libs/compose';
import Navigation from '../libs/Navigation/Navigation';
import ROUTES from '../ROUTES';
import Icon from './Icon';
import * as CurrencyUtils from '../libs/CurrencyUtils';

const propTypes = {
/** The report currently being looked at */
Expand All @@ -43,11 +44,8 @@ const defaultProps = {
};

const MoneyRequestHeader = (props) => {
const formattedAmount = props.numberFormat(props.report.total / 100, {
style: 'currency',
currency: props.report.currency,
});
const isSettled = false; // TODO: use ReportUtils.isSettled(props.report.reportID) once that method is added
const formattedAmount = CurrencyUtils.convertToDisplayString(props.report.total, 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 payeeAvatar = isExpenseReport
Expand Down
43 changes: 9 additions & 34 deletions src/components/ReportActionItem/IOUPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,9 @@ import * as DeviceCapabilities from '../../libs/DeviceCapabilities';
import reportActionPropTypes from '../../pages/home/report/reportActionPropTypes';
import {showContextMenuForReport} from '../ShowContextMenuContext';
import * as OptionsListUtils from '../../libs/OptionsListUtils';
import Button from '../Button';
import * as CurrencyUtils from '../../libs/CurrencyUtils';
import * as StyleUtils from '../../styles/StyleUtils';
import getButtonState from '../../libs/getButtonState';

const propTypes = {
/** Additional logic for displaying the pay button */
shouldHidePayButton: PropTypes.bool,

/** Callback for the Pay/Settle button */
onPayButtonPressed: PropTypes.func,

/** The active IOUReport, used for Onyx subscription */
// eslint-disable-next-line react/no-unused-prop-types
iouReportID: PropTypes.string.isRequired,
Expand Down Expand Up @@ -82,6 +73,9 @@ const propTypes = {
/** True if this is this IOU is a split instead of a 1:1 request */
isBillSplit: PropTypes.bool.isRequired,

/** True if the IOU Preview is rendered within a single IOUAction */
isIOUAction: PropTypes.bool,

/** True if the IOU Preview card is hovered */
isHovered: PropTypes.bool,

Expand Down Expand Up @@ -115,15 +109,14 @@ const propTypes = {

const defaultProps = {
iouReport: {},
shouldHidePayButton: false,
onPayButtonPressed: null,
onPreviewPressed: null,
action: undefined,
contextMenuAnchor: undefined,
checkIfContextMenuActive: () => {},
containerStyles: [],
walletTerms: {},
pendingAction: null,
isIOUAction: true,
isHovered: false,
personalDetails: {},
session: {
Expand Down Expand Up @@ -152,9 +145,9 @@ const IOUPreview = (props) => {
// Pay button should only be visible to the manager of the report.
const isCurrentUserManager = managerEmail === sessionEmail;

// Get request formatting options, as long as currency is provided
const requestAmount = props.isBillSplit ? props.action.originalMessage.amount : props.iouReport.total;
const requestCurrency = props.isBillSplit ? lodashGet(props.action, 'originalMessage.currency', CONST.CURRENCY.USD) : props.iouReport.currency;
// If props.action is undefined then we are displaying within IOUDetailsModal and should use the full report amount
const requestAmount = props.isIOUAction ? lodashGet(props.action, 'originalMessage.amount', 0) : props.iouReport.total;
const requestCurrency = props.isIOUAction ? lodashGet(props.action, 'originalMessage.currency', CONST.CURRENCY.USD) : props.iouReport.currency;

const getSettledMessage = () => {
switch (lodashGet(props.action, 'originalMessage.paymentType', '')) {
Expand All @@ -170,9 +163,9 @@ const IOUPreview = (props) => {
};

const showContextMenu = (event) => {
// Use action and shouldHidePayButton props to check if we are in IOUDetailsModal,
// Use action prop to check if we are in IOUDetailsModal,
// if it's true, do nothing when user long press, otherwise show context menu.
if (!props.action && props.shouldHidePayButton) {
if (!props.action) {
return;
}

Expand Down Expand Up @@ -207,11 +200,6 @@ const IOUPreview = (props) => {
</>
)}
</View>
<Icon
src={Expensicons.ArrowRight}
fill={StyleUtils.getIconFillColor(getButtonState(props.isHovered))}
additionalStyles={[styles.mb1]}
/>
</View>
<View style={[styles.flexRow]}>
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter]}>
Expand Down Expand Up @@ -241,19 +229,6 @@ const IOUPreview = (props) => {
)}

<Text style={[styles.colorMuted]}>{Str.htmlDecode(lodashGet(props.action, 'originalMessage.comment', ''))}</Text>

{isCurrentUserManager && !props.shouldHidePayButton && props.iouReport.stateNum === CONST.REPORT.STATE_NUM.PROCESSING && (
<Button
style={styles.mt4}
onPress={props.onPayButtonPressed}
onPressIn={() => DeviceCapabilities.canUseTouchScreen() && ControlSelection.block()}
onPressOut={() => ControlSelection.unblock()}
onLongPress={showContextMenu}
text={props.translate('iou.pay')}
success
medium
/>
)}
</View>
</OfflineWithFeedback>
</View>
Expand Down
81 changes: 0 additions & 81 deletions src/components/ReportActionItem/IOUQuote.js

This file was deleted.

28 changes: 13 additions & 15 deletions src/components/ReportActionItem/MoneyRequestAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ONYXKEYS from '../../ONYXKEYS';
import CONST from '../../CONST';
import {withNetwork} from '../OnyxProvider';
import compose from '../../libs/compose';
import IOUQuote from './IOUQuote';
import ReportPreview from './ReportPreview';
import reportActionPropTypes from '../../pages/home/report/reportActionPropTypes';
import networkPropTypes from '../networkPropTypes';
import iouReportPropTypes from '../../pages/iouReportPropTypes';
Expand Down Expand Up @@ -78,8 +78,6 @@ const MoneyRequestAction = (props) => {
}
};

const shouldShowIOUPreview = props.isMostRecentIOUReportAction || props.action.originalMessage.type === 'pay';

let shouldShowPendingConversionMessage = false;
if (
!_.isEmpty(props.iouReport) &&
Expand All @@ -94,26 +92,26 @@ const MoneyRequestAction = (props) => {

return (
<>
<IOUQuote
action={props.action}
<IOUPreview
iouReportID={props.requestReportID}
chatReportID={props.chatReportID}
isBillSplit={hasMultipleParticipants}
action={props.action}
contextMenuAnchor={props.contextMenuAnchor}
onViewDetailsPressed={onIOUPreviewPressed}
checkIfContextMenuActive={props.checkIfContextMenuActive}
shouldShowPendingConversionMessage={shouldShowPendingConversionMessage}
onPreviewPressed={onIOUPreviewPressed}
containerStyles={[styles.cursorPointer, props.isHovered ? styles.iouPreviewBoxHover : undefined]}
isHovered={props.isHovered}
/>
{shouldShowIOUPreview && (
<IOUPreview
iouReportID={props.requestReportID}
chatReportID={props.chatReportID}
isBillSplit={hasMultipleParticipants}
{props.isMostRecentIOUReportAction && !hasMultipleParticipants && (
<ReportPreview
action={props.action}
chatReportID={props.chatReportID}
iouReportID={props.requestReportID}
contextMenuAnchor={props.contextMenuAnchor}
onViewDetailsPressed={onIOUPreviewPressed}
checkIfContextMenuActive={props.checkIfContextMenuActive}
shouldShowPendingConversionMessage={shouldShowPendingConversionMessage}
onPayButtonPressed={onIOUPreviewPressed}
onPreviewPressed={onIOUPreviewPressed}
containerStyles={[styles.cursorPointer, props.isHovered ? styles.iouPreviewBoxHover : undefined]}
isHovered={props.isHovered}
/>
)}
Expand Down
Loading