diff --git a/src/pages/home/report/ReportActionCompose.js b/src/pages/home/report/ReportActionCompose.js index fda6efda78a3..a4c0e0656f0c 100755 --- a/src/pages/home/report/ReportActionCompose.js +++ b/src/pages/home/report/ReportActionCompose.js @@ -95,6 +95,13 @@ const propTypes = { // The date that the user will be unblocked expiresAt: PropTypes.string, }), + + /** The personal details of the person who is logged in */ + myPersonalDetails: PropTypes.shape({ + /** Primary login of the user */ + login: PropTypes.string, + }), + ...windowDimensionsPropTypes, ...withLocalizePropTypes, }; @@ -106,6 +113,7 @@ const defaultProps = { reportActions: {}, blockedFromConcierge: {}, personalDetails: {}, + myPersonalDetails: {}, }; class ReportActionCompose extends React.Component { @@ -125,6 +133,7 @@ class ReportActionCompose extends React.Component { this.onSelectionChange = this.onSelectionChange.bind(this); this.setTextInputRef = this.setTextInputRef.bind(this); this.getInputPlaceholder = this.getInputPlaceholder.bind(this); + this.getIOUOptions = this.getIOUOptions.bind(this); this.state = { isFocused: this.shouldFocusInputOnScreenFocus, @@ -230,6 +239,45 @@ class ReportActionCompose extends React.Component { return this.props.translate('reportActionCompose.writeSomething'); } + /** + * Returns the list of IOU Options + * + * @param {Array} reportParticipants + * @returns {Array} + */ + getIOUOptions(reportParticipants) { + const participants = _.filter(reportParticipants, email => this.props.myPersonalDetails.login !== email); + const hasExcludedIOUEmails = lodashIntersection(reportParticipants, CONST.EXPENSIFY_EMAILS).length > 0; + const hasMultipleParticipants = participants.length > 1; + const iouOptions = []; + + if (hasExcludedIOUEmails || participants.length === 0 || !Permissions.canUseIOU(this.props.betas)) { + return []; + } + + if (hasMultipleParticipants) { + return [{ + icon: Expensicons.Receipt, + text: this.props.translate('iou.splitBill'), + onSelected: () => Navigation.navigate(ROUTES.getIouSplitRoute(this.props.reportID)), + }]; + } + + iouOptions.push({ + icon: Expensicons.MoneyCircle, + text: this.props.translate('iou.requestMoney'), + onSelected: () => Navigation.navigate(ROUTES.getIouRequestRoute(this.props.reportID)), + }); + if (Permissions.canUseIOUSend(this.props.betas)) { + iouOptions.push({ + icon: Expensicons.Send, + text: this.props.translate('iou.sendMoney'), + onSelected: () => Navigation.navigate(ROUTES.getIOUSendRoute(this.props.reportID)), + }); + } + return iouOptions; + } + /** * Callback for the emoji picker to add whatever emoji is chosen into the main input * @@ -389,8 +437,6 @@ class ReportActionCompose extends React.Component { } const reportParticipants = lodashGet(this.props.report, 'participants', []); - const hasMultipleParticipants = reportParticipants.length > 1; - const hasExcludedIOUEmails = lodashIntersection(reportParticipants, CONST.EXPENSIFY_EMAILS).length > 0; const reportRecipient = this.props.personalDetails[reportParticipants[0]]; const shouldShowReportRecipientLocalTime = ReportUtils.canShowReportRecipientLocalTime(this.props.personalDetails, this.props.report); @@ -446,45 +492,7 @@ class ReportActionCompose extends React.Component { onClose={() => this.setMenuVisibility(false)} onItemSelected={() => this.setMenuVisibility(false)} anchorPosition={styles.createMenuPositionReportActionCompose} - menuItems={[ - ...(!hasExcludedIOUEmails - && Permissions.canUseIOU(this.props.betas) ? [ - hasMultipleParticipants - ? { - icon: Expensicons.Receipt, - text: this.props.translate('iou.splitBill'), - onSelected: () => { - Navigation.navigate( - ROUTES.getIouSplitRoute( - this.props.reportID, - ), - ); - }, - } : { - icon: Expensicons.MoneyCircle, - text: this.props.translate('iou.requestMoney'), - onSelected: () => { - Navigation.navigate( - ROUTES.getIouRequestRoute( - this.props.reportID, - ), - ); - }, - }, - ] : []), - ...(!hasExcludedIOUEmails && Permissions.canUseIOUSend(this.props.betas) && !hasMultipleParticipants ? [ - { - icon: Expensicons.Send, - text: this.props.translate('iou.sendMoney'), - onSelected: () => { - Navigation.navigate( - ROUTES.getIOUSendRoute( - this.props.reportID, - ), - ); - }, - }, - ] : []), + menuItems={[...this.getIOUOptions(reportParticipants), { icon: Expensicons.Paperclip, text: this.props.translate('reportActionCompose.addAttachment'), @@ -634,5 +642,8 @@ export default compose( blockedFromConcierge: { key: ONYXKEYS.NVP_BLOCKED_FROM_CONCIERGE, }, + myPersonalDetails: { + key: ONYXKEYS.MY_PERSONAL_DETAILS, + }, }), )(ReportActionCompose); diff --git a/src/pages/iou/IOUModal.js b/src/pages/iou/IOUModal.js index a75b7f990cfe..c0d8cf70449f 100755 --- a/src/pages/iou/IOUModal.js +++ b/src/pages/iou/IOUModal.js @@ -429,7 +429,7 @@ class IOUModal extends Component { onConfirm={this.createTransaction} onSendMoney={this.sendMoney} hasMultipleParticipants={this.props.hasMultipleParticipants} - participants={this.state.participants} + participants={_.filter(this.state.participants, email => this.props.myPersonalDetails.login !== email.login)} iouAmount={this.state.amount} comment={this.state.comment} onUpdateComment={this.updateComment}