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

Make sure the IOU or expense level settlement button defaults to last used method #22846

Merged
merged 6 commits into from
Jul 18, 2023
Merged
Changes from 5 commits
Commits
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
9 changes: 8 additions & 1 deletion src/components/SettlementButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ class SettlementButton extends React.Component {

// To achieve the one tap pay experience we need to choose the correct payment type as default,
// if user already paid for some request or expense, let's use the last payment method or use default.
let paymentMethod = this.props.nvp_lastPaymentMethod[this.props.policyID] || '';
if (!this.props.shouldShowPaymentOptions) {
let paymentMethod = this.props.nvp_lastPaymentMethod[this.props.policyID];
if (!paymentMethod) {
// In case the user hasn't paid a request yet, let's default to VBBA payment type in case of expense reports
if (isExpenseReport) {
Expand Down Expand Up @@ -141,6 +141,13 @@ class SettlementButton extends React.Component {
buttonOptions.push(paymentMethods[CONST.IOU.PAYMENT_TYPE.PAYPAL_ME]);
}
buttonOptions.push(paymentMethods[CONST.IOU.PAYMENT_TYPE.ELSEWHERE]);

// Put the prefered payment method to the front of the array so its shown as default
mountiny marked this conversation as resolved.
Show resolved Hide resolved
if (paymentMethod) {
const indexOfElement = _.findIndex(buttonOptions, (method) => method.value === paymentMethod);
buttonOptions.splice(indexOfElement, 1);
buttonOptions.unshift(paymentMethods[paymentMethod]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const indexOfElement = _.findIndex(buttonOptions, (method) => method.value === paymentMethod);
buttonOptions.splice(indexOfElement, 1);
buttonOptions.unshift(paymentMethods[paymentMethod]);
return sortBy(buttonOptions, method => (method.value === paymentMethod ? 0 : 1))

Can be simplified using lodash/sortBy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

}
return buttonOptions;
}

Expand Down