From e12f06053ed5dbbe3feac9c3c279fe224315d72d Mon Sep 17 00:00:00 2001 From: gijoe0295 Date: Wed, 31 Jul 2024 13:10:13 +0700 Subject: [PATCH 1/4] fix: not redirect to workspace chat when pay iou with business account --- src/components/KYCWall/BaseKYCWall.tsx | 10 +++++++--- src/libs/actions/Policy/Policy.ts | 10 ++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/components/KYCWall/BaseKYCWall.tsx b/src/components/KYCWall/BaseKYCWall.tsx index 818b4aff6b00..dcad0e0ba533 100644 --- a/src/components/KYCWall/BaseKYCWall.tsx +++ b/src/components/KYCWall/BaseKYCWall.tsx @@ -18,6 +18,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type {BankAccountList, FundList, ReimbursementAccount, UserWallet, WalletTerms} from '@src/types/onyx'; import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage'; +import {isEmptyObject} from '@src/types/utils/EmptyObject'; import viewRef from '@src/types/utils/viewRef'; import type {AnchorPosition, DomRect, KYCWallProps, PaymentMethod} from './types'; @@ -67,7 +68,7 @@ function KYCWall({ source, userWallet, walletTerms, - shouldShowPersonalBankAccountOption = false, + shouldShowPersonalBankAccountOption = true, }: BaseKYCWallProps) { const anchorRef = useRef(null); const transferBalanceButtonRef = useRef(null); @@ -127,7 +128,10 @@ function KYCWall({ Navigation.navigate(addDebitCardRoute); } else if (paymentMethod === CONST.PAYMENT_METHODS.BUSINESS_BANK_ACCOUNT) { if (iouReport && ReportUtils.isIOUReport(iouReport)) { - const policyID = Policy.createWorkspaceFromIOUPayment(iouReport); + const {policyID, workspaceChatReportID, reportPreviewReportActionID} = Policy.createWorkspaceFromIOUPayment(iouReport) ?? {}; + if (workspaceChatReportID) { + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(workspaceChatReportID, reportPreviewReportActionID)); + } // Navigate to the bank account set up flow for this specific policy Navigation.navigate(ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute('', policyID)); @@ -172,7 +176,7 @@ function KYCWall({ // Check to see if user has a valid payment method on file and display the add payment popover if they don't if ( (isExpenseReport && reimbursementAccount?.achData?.state !== CONST.BANK_ACCOUNT.STATE.OPEN) || - (!isExpenseReport && bankAccountList !== null && !PaymentUtils.hasExpensifyPaymentMethod(paymentCardList, bankAccountList, shouldIncludeDebitCard)) + (!isExpenseReport && isEmptyObject(bankAccountList) && !PaymentUtils.hasExpensifyPaymentMethod(paymentCardList, bankAccountList, shouldIncludeDebitCard)) ) { Log.info('[KYC Wallet] User does not have valid payment method'); diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index 1bce525e22bf..49f6d8d03a73 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -107,6 +107,12 @@ type NewCustomUnit = { rates: Rate; }; +type WorkspaceFromIOUCreationData = { + policyID: string; + workspaceChatReportID: string; + reportPreviewReportActionID?: string; +}; + const allPolicies: OnyxCollection = {}; Onyx.connect({ key: ONYXKEYS.COLLECTION.POLICY, @@ -2066,7 +2072,7 @@ function dismissAddedWithPrimaryLoginMessages(policyID: string) { * * @returns policyID of the workspace we have created */ -function createWorkspaceFromIOUPayment(iouReport: OnyxEntry): string | undefined { +function createWorkspaceFromIOUPayment(iouReport: OnyxEntry): WorkspaceFromIOUCreationData | undefined { // This flow only works for IOU reports if (!ReportUtils.isIOUReportUsingReport(iouReport)) { return; @@ -2499,7 +2505,7 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry): string | u API.write(WRITE_COMMANDS.CREATE_WORKSPACE_FROM_IOU_PAYMENT, params, {optimisticData, successData, failureData}); - return policyID; + return {policyID, workspaceChatReportID: memberData.workspaceChatReportID, reportPreviewReportActionID: reportPreview?.reportActionID}; } function enablePolicyConnections(policyID: string, enabled: boolean) { From 87834223b13ef182a7ddc79a43fee1362568912b Mon Sep 17 00:00:00 2001 From: gijoe0295 Date: Wed, 31 Jul 2024 13:11:21 +0700 Subject: [PATCH 2/4] fix: business bank account is always selected when pay with expensify --- src/components/AddPaymentMethodMenu.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/AddPaymentMethodMenu.tsx b/src/components/AddPaymentMethodMenu.tsx index 451979b92efa..bd437cbb062d 100644 --- a/src/components/AddPaymentMethodMenu.tsx +++ b/src/components/AddPaymentMethodMenu.tsx @@ -74,7 +74,7 @@ function AddPaymentMethodMenu({ // We temporarily disabled P2P debit cards so we will automatically select the personal bank account option if there is no other option to select. useEffect(() => { - if (!isVisible) { + if (!isVisible || !isPersonalOnlyOption) { return; } From 57a157d15cbb70202dbaf92d595dedb55f3df4bc Mon Sep 17 00:00:00 2001 From: gijoe0295 Date: Wed, 31 Jul 2024 13:51:36 +0700 Subject: [PATCH 3/4] revert redundant changes --- src/components/KYCWall/BaseKYCWall.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/components/KYCWall/BaseKYCWall.tsx b/src/components/KYCWall/BaseKYCWall.tsx index dcad0e0ba533..fd681546c470 100644 --- a/src/components/KYCWall/BaseKYCWall.tsx +++ b/src/components/KYCWall/BaseKYCWall.tsx @@ -18,7 +18,6 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type {BankAccountList, FundList, ReimbursementAccount, UserWallet, WalletTerms} from '@src/types/onyx'; import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage'; -import {isEmptyObject} from '@src/types/utils/EmptyObject'; import viewRef from '@src/types/utils/viewRef'; import type {AnchorPosition, DomRect, KYCWallProps, PaymentMethod} from './types'; @@ -68,7 +67,7 @@ function KYCWall({ source, userWallet, walletTerms, - shouldShowPersonalBankAccountOption = true, + shouldShowPersonalBankAccountOption = false, }: BaseKYCWallProps) { const anchorRef = useRef(null); const transferBalanceButtonRef = useRef(null); @@ -176,7 +175,7 @@ function KYCWall({ // Check to see if user has a valid payment method on file and display the add payment popover if they don't if ( (isExpenseReport && reimbursementAccount?.achData?.state !== CONST.BANK_ACCOUNT.STATE.OPEN) || - (!isExpenseReport && isEmptyObject(bankAccountList) && !PaymentUtils.hasExpensifyPaymentMethod(paymentCardList, bankAccountList, shouldIncludeDebitCard)) + (!isExpenseReport && bankAccountList !== null && !PaymentUtils.hasExpensifyPaymentMethod(paymentCardList, bankAccountList, shouldIncludeDebitCard)) ) { Log.info('[KYC Wallet] User does not have valid payment method'); From 754fc97b056d9c403251ad81be27ac0b68fe91ca Mon Sep 17 00:00:00 2001 From: gijoe0295 Date: Thu, 1 Aug 2024 00:41:52 +0700 Subject: [PATCH 4/4] Revert "fix: business bank account is always selected when pay with expensify" This reverts commit 87834223b13ef182a7ddc79a43fee1362568912b. --- src/components/AddPaymentMethodMenu.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/AddPaymentMethodMenu.tsx b/src/components/AddPaymentMethodMenu.tsx index bd437cbb062d..451979b92efa 100644 --- a/src/components/AddPaymentMethodMenu.tsx +++ b/src/components/AddPaymentMethodMenu.tsx @@ -74,7 +74,7 @@ function AddPaymentMethodMenu({ // We temporarily disabled P2P debit cards so we will automatically select the personal bank account option if there is no other option to select. useEffect(() => { - if (!isVisible || !isPersonalOnlyOption) { + if (!isVisible) { return; }