-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Fix IOU Options bug #8839
Fix IOU Options bug #8839
Changes from 2 commits
3677e33
2a601ad
03a88f4
4819a4b
657693b
9e3952a
189ec6b
980ba2e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -125,6 +125,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.getReportComposeActions = this.getReportComposeActions.bind(this); | ||||||||||||||||||
|
||||||||||||||||||
this.state = { | ||||||||||||||||||
isFocused: this.shouldFocusInputOnScreenFocus, | ||||||||||||||||||
|
@@ -230,6 +231,75 @@ class ReportActionCompose extends React.Component { | |||||||||||||||||
return this.props.translate('reportActionCompose.writeSomething'); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
/** | ||||||||||||||||||
* Returns the list of report compose actions | ||||||||||||||||||
* | ||||||||||||||||||
* @param {Boolean} showSplitBill | ||||||||||||||||||
* @param {Boolean} showSendRequestMoney | ||||||||||||||||||
* @param {Boolean} hasExcludedIOUEmails | ||||||||||||||||||
* @param {Function} openPicker | ||||||||||||||||||
* @param {Function} displayFileInModal | ||||||||||||||||||
* @returns {Array<object>} | ||||||||||||||||||
*/ | ||||||||||||||||||
getReportComposeActions(showSplitBill, showSendRequestMoney, hasExcludedIOUEmails, openPicker, displayFileInModal) { | ||||||||||||||||||
return [ | ||||||||||||||||||
...(!hasExcludedIOUEmails | ||||||||||||||||||
&& Permissions.canUseIOU(this.props.betas) | ||||||||||||||||||
&& showSplitBill ? [ | ||||||||||||||||||
{ | ||||||||||||||||||
icon: Expensicons.Receipt, | ||||||||||||||||||
text: this.props.translate('iou.splitBill'), | ||||||||||||||||||
onSelected: () => { | ||||||||||||||||||
Navigation.navigate( | ||||||||||||||||||
ROUTES.getIouSplitRoute( | ||||||||||||||||||
this.props.reportID, | ||||||||||||||||||
), | ||||||||||||||||||
); | ||||||||||||||||||
}, | ||||||||||||||||||
}, | ||||||||||||||||||
] : []), | ||||||||||||||||||
...(!hasExcludedIOUEmails | ||||||||||||||||||
&& Permissions.canUseIOU(this.props.betas) | ||||||||||||||||||
&& showSendRequestMoney ? [ | ||||||||||||||||||
{ | ||||||||||||||||||
icon: Expensicons.MoneyCircle, | ||||||||||||||||||
text: this.props.translate('iou.requestMoney'), | ||||||||||||||||||
onSelected: () => { | ||||||||||||||||||
Navigation.navigate( | ||||||||||||||||||
ROUTES.getIouRequestRoute( | ||||||||||||||||||
this.props.reportID, | ||||||||||||||||||
), | ||||||||||||||||||
); | ||||||||||||||||||
}, | ||||||||||||||||||
}, | ||||||||||||||||||
] : []), | ||||||||||||||||||
...(!hasExcludedIOUEmails && Permissions.canUseIOUSend(this.props.betas) && showSendRequestMoney ? [ | ||||||||||||||||||
{ | ||||||||||||||||||
icon: Expensicons.Send, | ||||||||||||||||||
text: this.props.translate('iou.sendMoney'), | ||||||||||||||||||
onSelected: () => { | ||||||||||||||||||
Navigation.navigate( | ||||||||||||||||||
ROUTES.getIOUSendRoute( | ||||||||||||||||||
this.props.reportID, | ||||||||||||||||||
), | ||||||||||||||||||
); | ||||||||||||||||||
}, | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given it's only one param per method and line is not too long, I think this is more readable
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. made the requested change |
||||||||||||||||||
}, | ||||||||||||||||||
] : []), | ||||||||||||||||||
{ | ||||||||||||||||||
icon: Expensicons.Paperclip, | ||||||||||||||||||
text: this.props.translate('reportActionCompose.addAttachment'), | ||||||||||||||||||
onSelected: () => { | ||||||||||||||||||
openPicker({ | ||||||||||||||||||
onPicked: (file) => { | ||||||||||||||||||
displayFileInModal({file}); | ||||||||||||||||||
}, | ||||||||||||||||||
}); | ||||||||||||||||||
}, | ||||||||||||||||||
}, | ||||||||||||||||||
]; | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code is not DRY, we have redundant checks here. Can you refactor this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactoring this might result into nested ternary operators. I was discouraged to use nested ternary operators in previous PRs. Any suggestion? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could use simple if/else no need for ternary here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will look something like this. Any suggestion?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's just move IOU options computation alone to a new method, leave Add Attachment untouched thanks! getIOUOptions(reportParticipants) {
const iouOptions = [];
const participants = _.filter(reportParticipants, email => this.props.myPersonalDetails.login !== email).length > 1;
const hasExcludedIOUEmails = lodashIntersection(reportParticipants, CONST.EXPENSIFY_EMAILS).length > 0;
const hasMultipleParticipants = participants.length > 1;
if (hasExcludedIOUEmails || participants.length === 0 || Permissions.canUseIOU(this.props.betas)) {
return iouOptions;
}
if (hasMultipleParticipants) {
// append split
}
else {
if (Permissions.canUseIOUSend(this.props.betas)) {
// append send
}
// append request
}
return iouOptions;
} cc: @iwiznia There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
/** | ||||||||||||||||||
* Callback for the emoji picker to add whatever emoji is chosen into the main input | ||||||||||||||||||
* | ||||||||||||||||||
|
@@ -389,7 +459,8 @@ class ReportActionCompose extends React.Component { | |||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
const reportParticipants = lodashGet(this.props.report, 'participants', []); | ||||||||||||||||||
const hasMultipleParticipants = reportParticipants.length > 1; | ||||||||||||||||||
const showSplitBill = _.filter(reportParticipants, email => this.props.myPersonalDetails.login !== email).length > 1; | ||||||||||||||||||
const showSendRequestMoney = _.filter(reportParticipants, email => this.props.myPersonalDetails.login !== email).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); | ||||||||||||||||||
|
@@ -448,57 +519,7 @@ class ReportActionCompose extends React.Component { | |||||||||||||||||
anchorPosition={styles.createMenuPositionReportActionCompose} | ||||||||||||||||||
animationIn="fadeInUp" | ||||||||||||||||||
animationOut="fadeOutDown" | ||||||||||||||||||
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, | ||||||||||||||||||
), | ||||||||||||||||||
); | ||||||||||||||||||
}, | ||||||||||||||||||
}, | ||||||||||||||||||
] : []), | ||||||||||||||||||
{ | ||||||||||||||||||
icon: Expensicons.Paperclip, | ||||||||||||||||||
text: this.props.translate('reportActionCompose.addAttachment'), | ||||||||||||||||||
onSelected: () => { | ||||||||||||||||||
openPicker({ | ||||||||||||||||||
onPicked: (file) => { | ||||||||||||||||||
displayFileInModal({file}); | ||||||||||||||||||
}, | ||||||||||||||||||
}); | ||||||||||||||||||
}, | ||||||||||||||||||
}, | ||||||||||||||||||
]} | ||||||||||||||||||
menuItems={this.getReportComposeActions(showSplitBill, showSendRequestMoney, hasExcludedIOUEmails, openPicker, displayFileInModal)} | ||||||||||||||||||
/> | ||||||||||||||||||
</> | ||||||||||||||||||
)} | ||||||||||||||||||
|
@@ -636,5 +657,8 @@ export default compose( | |||||||||||||||||
blockedFromConcierge: { | ||||||||||||||||||
key: ONYXKEYS.NVP_BLOCKED_FROM_CONCIERGE, | ||||||||||||||||||
}, | ||||||||||||||||||
myPersonalDetails: { | ||||||||||||||||||
key: ONYXKEYS.MY_PERSONAL_DETAILS, | ||||||||||||||||||
}, | ||||||||||||||||||
Comment on lines
+645
to
+647
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. prop type is defined for |
||||||||||||||||||
}), | ||||||||||||||||||
)(ReportActionCompose); |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -429,7 +429,9 @@ class IOUModal extends Component { | |||||
onConfirm={this.createTransaction} | ||||||
onSendMoney={this.sendMoney} | ||||||
hasMultipleParticipants={this.props.hasMultipleParticipants} | ||||||
participants={this.state.participants} | ||||||
participants={this.props.hasMultipleParticipants | ||||||
? this.state.participants | ||||||
: _.filter(this.state.participants, email => this.props.myPersonalDetails.login !== email.login)} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be done here, I think it could be moved along the lines here Lines 110 to 111 in 4c64bec
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Participants are updated during IOUParicipantsPage step. So, it cannot be moved here. We need to make use of updated participants list. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check and let me know! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's a good idea. It adds more complication. |
||||||
iouAmount={this.state.amount} | ||||||
comment={this.state.comment} | ||||||
onUpdateComment={this.updateComment} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to compute and pass everything to this function it does not make any sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved.