From 40c4540c1e84ca12d3d95ca831d9b8e79bc66b24 Mon Sep 17 00:00:00 2001 From: Vit Horacek Date: Thu, 13 Jul 2023 15:32:56 -0500 Subject: [PATCH 1/5] Put the prefered payment option as first in the settlement button array --- src/components/SettlementButton.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/SettlementButton.js b/src/components/SettlementButton.js index 13a25c94540e..5d0f4d19a398 100644 --- a/src/components/SettlementButton.js +++ b/src/components/SettlementButton.js @@ -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) { @@ -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 + if (paymentMethod) { + const indexOfElement = _.findIndex(buttonOptions, method => method === paymentMethod); + buttonOptions.splice(indexOfElement, 1); + buttonOptions.unshift(paymentMethod); + } return buttonOptions; } From c35256570e618cfd9e0b91ebed5adc7eabd38348 Mon Sep 17 00:00:00 2001 From: Vit Horacek Date: Thu, 13 Jul 2023 15:49:46 -0500 Subject: [PATCH 2/5] Pass the object to the button options --- src/components/SettlementButton.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/SettlementButton.js b/src/components/SettlementButton.js index 5d0f4d19a398..20597f6d9dc0 100644 --- a/src/components/SettlementButton.js +++ b/src/components/SettlementButton.js @@ -142,11 +142,11 @@ class SettlementButton extends React.Component { } buttonOptions.push(paymentMethods[CONST.IOU.PAYMENT_TYPE.ELSEWHERE]); - // Put the prefered payment method to the front of the array + // Put the prefered payment method to the front of the array so its shown as default if (paymentMethod) { const indexOfElement = _.findIndex(buttonOptions, method => method === paymentMethod); buttonOptions.splice(indexOfElement, 1); - buttonOptions.unshift(paymentMethod); + buttonOptions.unshift(paymentMethods[paymentMethod]); } return buttonOptions; } From de989ecab0ff5fd9e6bd75210991b2b0cd071e33 Mon Sep 17 00:00:00 2001 From: Vit Horacek Date: Thu, 13 Jul 2023 16:19:29 -0500 Subject: [PATCH 3/5] Use correct comparison --- src/components/SettlementButton.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/SettlementButton.js b/src/components/SettlementButton.js index 20597f6d9dc0..ea85ddd4b84f 100644 --- a/src/components/SettlementButton.js +++ b/src/components/SettlementButton.js @@ -144,7 +144,7 @@ class SettlementButton extends React.Component { // Put the prefered payment method to the front of the array so its shown as default if (paymentMethod) { - const indexOfElement = _.findIndex(buttonOptions, method => method === paymentMethod); + const indexOfElement = _.findIndex(buttonOptions, method => method.value === paymentMethod); buttonOptions.splice(indexOfElement, 1); buttonOptions.unshift(paymentMethods[paymentMethod]); } From 21c665ea9ef5c7f21694f52f679a50df47b904ad Mon Sep 17 00:00:00 2001 From: Vit Horacek Date: Thu, 13 Jul 2023 18:16:26 -0500 Subject: [PATCH 4/5] Fix linter --- src/components/SettlementButton.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/SettlementButton.js b/src/components/SettlementButton.js index ea85ddd4b84f..3a40ce3daa36 100644 --- a/src/components/SettlementButton.js +++ b/src/components/SettlementButton.js @@ -144,7 +144,7 @@ class SettlementButton extends React.Component { // Put the prefered payment method to the front of the array so its shown as default if (paymentMethod) { - const indexOfElement = _.findIndex(buttonOptions, method => method.value === paymentMethod); + const indexOfElement = _.findIndex(buttonOptions, (method) => method.value === paymentMethod); buttonOptions.splice(indexOfElement, 1); buttonOptions.unshift(paymentMethods[paymentMethod]); } From 3a9490345adbdcf6159f28a506e1d95462ab49a8 Mon Sep 17 00:00:00 2001 From: Vit Horacek Date: Sat, 15 Jul 2023 16:38:41 -0500 Subject: [PATCH 5/5] Address PR feedback --- src/components/SettlementButton.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/components/SettlementButton.js b/src/components/SettlementButton.js index 3a40ce3daa36..e791383da816 100644 --- a/src/components/SettlementButton.js +++ b/src/components/SettlementButton.js @@ -142,11 +142,9 @@ class SettlementButton extends React.Component { } buttonOptions.push(paymentMethods[CONST.IOU.PAYMENT_TYPE.ELSEWHERE]); - // Put the prefered payment method to the front of the array so its shown as default + // Put the preferred payment method to the front of the array so its shown as default if (paymentMethod) { - 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)); } return buttonOptions; }