-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22484 from Expensify/georgia-expenseReportView
Update Expense Report View / Headers
- Loading branch information
Showing
13 changed files
with
287 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import React from 'react'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import {View} from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
import lodashGet from 'lodash/get'; | ||
import HeaderWithBackButton from './HeaderWithBackButton'; | ||
import iouReportPropTypes from '../pages/iouReportPropTypes'; | ||
import * as ReportUtils from '../libs/ReportUtils'; | ||
import * as Expensicons from './Icon/Expensicons'; | ||
import participantPropTypes from './participantPropTypes'; | ||
import styles from '../styles/styles'; | ||
import withWindowDimensions, {windowDimensionsPropTypes} from './withWindowDimensions'; | ||
import compose from '../libs/compose'; | ||
import Navigation from '../libs/Navigation/Navigation'; | ||
import ROUTES from '../ROUTES'; | ||
import SettlementButton from './SettlementButton'; | ||
import * as Policy from '../libs/actions/Policy'; | ||
import ONYXKEYS from '../ONYXKEYS'; | ||
import * as IOU from '../libs/actions/IOU'; | ||
import * as CurrencyUtils from '../libs/CurrencyUtils'; | ||
import reportPropTypes from '../pages/reportPropTypes'; | ||
import useLocalize from '../hooks/useLocalize'; | ||
|
||
const propTypes = { | ||
/** The report currently being looked at */ | ||
report: iouReportPropTypes.isRequired, | ||
|
||
/** The policies which the user has access to and which the report could be tied to */ | ||
policies: PropTypes.shape({ | ||
/** Name of the policy */ | ||
name: PropTypes.string, | ||
}).isRequired, | ||
|
||
/** The chat report this report is linked to */ | ||
chatReport: reportPropTypes, | ||
|
||
/** Personal details so we can get the ones for the report participants */ | ||
personalDetails: PropTypes.objectOf(participantPropTypes).isRequired, | ||
|
||
/** Session info for the currently logged in user. */ | ||
session: PropTypes.shape({ | ||
/** Currently logged in user email */ | ||
email: PropTypes.string, | ||
}), | ||
|
||
...windowDimensionsPropTypes, | ||
}; | ||
|
||
const defaultProps = { | ||
chatReport: {}, | ||
session: { | ||
email: null, | ||
}, | ||
}; | ||
|
||
function MoneyReportHeader(props) { | ||
const moneyRequestReport = props.report; | ||
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 shouldShowSettlementButton = !isSettled && isPayer; | ||
const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport); | ||
const shouldShowPaypal = Boolean(lodashGet(props.personalDetails, [moneyRequestReport.managerID, 'payPalMeAddress'])); | ||
const formattedAmount = CurrencyUtils.convertToDisplayString(ReportUtils.getMoneyRequestTotal(props.report), props.report.currency); | ||
const {translate} = useLocalize(); | ||
|
||
return ( | ||
<View style={[styles.pt0]}> | ||
<HeaderWithBackButton | ||
shouldShowAvatarWithDisplay | ||
shouldShowPinButton={false} | ||
shouldShowThreeDotsButton={false} | ||
threeDotsMenuItems={[ | ||
{ | ||
icon: Expensicons.Trashcan, | ||
text: translate('common.delete'), | ||
onSelected: () => {}, | ||
}, | ||
]} | ||
threeDotsAnchorPosition={styles.threeDotsPopoverOffsetNoCloseButton(props.windowWidth)} | ||
report={props.report} | ||
policies={props.policies} | ||
personalDetails={props.personalDetails} | ||
shouldShowBackButton | ||
onBackButtonPress={() => Navigation.goBack(ROUTES.HOME, false, true)} | ||
shouldShowBorderBottom={!shouldShowSettlementButton || !props.isSmallScreenWidth} | ||
> | ||
{shouldShowSettlementButton && !props.isSmallScreenWidth && ( | ||
<View style={[styles.pv2]}> | ||
<SettlementButton | ||
currency={props.report.currency} | ||
policyID={props.report.policyID} | ||
shouldShowPaypal={shouldShowPaypal} | ||
chatReportID={props.chatReport.reportID} | ||
iouReport={props.report} | ||
onPress={(paymentType) => IOU.payMoneyRequest(paymentType, props.chatReport, props.report)} | ||
enablePaymentsRoute={ROUTES.BANK_ACCOUNT_NEW} | ||
addBankAccountRoute={bankAccountRoute} | ||
shouldShowPaymentOptions | ||
style={[styles.pv2]} | ||
formattedAmount={formattedAmount} | ||
/> | ||
</View> | ||
)} | ||
</HeaderWithBackButton> | ||
{shouldShowSettlementButton && props.isSmallScreenWidth && ( | ||
<View style={[styles.ph5, styles.pb2, props.isSmallScreenWidth && styles.borderBottom]}> | ||
<SettlementButton | ||
currency={props.report.currency} | ||
policyID={props.report.policyID} | ||
shouldShowPaypal={shouldShowPaypal} | ||
chatReportID={props.report.chatReportID} | ||
iouReport={props.report} | ||
onPress={(paymentType) => IOU.payMoneyRequest(paymentType, props.chatReport, props.report)} | ||
enablePaymentsRoute={ROUTES.BANK_ACCOUNT_NEW} | ||
addBankAccountRoute={bankAccountRoute} | ||
shouldShowPaymentOptions | ||
formattedAmount={formattedAmount} | ||
/> | ||
</View> | ||
)} | ||
</View> | ||
); | ||
} | ||
|
||
MoneyReportHeader.displayName = 'MoneyReportHeader'; | ||
MoneyReportHeader.propTypes = propTypes; | ||
MoneyReportHeader.defaultProps = defaultProps; | ||
|
||
export default compose( | ||
withWindowDimensions, | ||
withOnyx({ | ||
chatReport: { | ||
key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT}${report.chatReportID}`, | ||
}, | ||
session: { | ||
key: ONYXKEYS.SESSION, | ||
}, | ||
}), | ||
)(MoneyReportHeader); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import React from 'react'; | ||
import {View, Image} from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
import reportPropTypes from '../../pages/reportPropTypes'; | ||
import withWindowDimensions, {windowDimensionsPropTypes} from '../withWindowDimensions'; | ||
import styles from '../../styles/styles'; | ||
import * as ReportUtils from '../../libs/ReportUtils'; | ||
import * as StyleUtils from '../../styles/StyleUtils'; | ||
import CONST from '../../CONST'; | ||
import Text from '../Text'; | ||
import Icon from '../Icon'; | ||
import * as Expensicons from '../Icon/Expensicons'; | ||
import variables from '../../styles/variables'; | ||
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, | ||
|
||
/** Whether we should display the horizontal rule below the component */ | ||
shouldShowHorizontalRule: PropTypes.bool.isRequired, | ||
|
||
...windowDimensionsPropTypes, | ||
}; | ||
|
||
function MoneyReportView(props) { | ||
const formattedAmount = CurrencyUtils.convertToDisplayString(ReportUtils.getMoneyRequestTotal(props.report), props.report.currency); | ||
const isSettled = ReportUtils.isSettled(props.report.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> | ||
<View style={[styles.flexRow, styles.menuItemTextContainer, styles.pointerEventsNone, styles.containerWithSpaceBetween, styles.ph5, styles.pv2]}> | ||
<View style={[styles.flex1, styles.justifyContentCenter]}> | ||
<Text | ||
style={[styles.textLabelSupporting, styles.lhNormal, StyleUtils.getFontSizeStyle(variables.fontSizeNormal)]} | ||
numberOfLines={1} | ||
> | ||
{translate('common.total')} | ||
</Text> | ||
</View> | ||
<View style={[styles.flexRow, styles.justifyContentCenter]}> | ||
{isSettled && ( | ||
<View style={[styles.defaultCheckmarkWrapper, styles.mh1]}> | ||
<Icon | ||
src={Expensicons.Checkmark} | ||
fill={styles.success} | ||
/> | ||
</View> | ||
)} | ||
<Text | ||
numberOfLines={1} | ||
style={[styles.taskTitleMenuItem, styles.alignSelfCenter]} | ||
> | ||
{formattedAmount} | ||
</Text> | ||
</View> | ||
</View> | ||
{props.shouldShowHorizontalRule && <View style={styles.reportHorizontalRule} />} | ||
</View> | ||
); | ||
} | ||
|
||
MoneyReportView.propTypes = propTypes; | ||
MoneyReportView.displayName = 'MoneyReportView'; | ||
|
||
export default withWindowDimensions(MoneyReportView); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.