From b6eae361e6572b82c5f22759227d1c5f9cfd0dcf Mon Sep 17 00:00:00 2001 From: Vit Horacek <36083550+mountiny@users.noreply.github.com> Date: Thu, 24 Oct 2024 20:18:41 +0900 Subject: [PATCH] Merge pull request #51384 from narefyev91/add-bank-urls [CP Staging] [NO QA]: Add bank urls to Company Card flow (cherry picked from commit 7e5910ee2c41b5be16698c7953fb56f31841ec35) (CP triggered by mountiny) --- src/CONST.ts | 1 + .../getCompanyCardBankConnection/index.tsx | 21 +++++++++---------- .../companyCards/addNew/AddNewCardPage.tsx | 2 +- .../addNew/BankConnection/index.native.tsx | 8 +++++-- .../addNew/BankConnection/index.tsx | 8 +++++-- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 440f942e1244..2a71858583ec 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -2635,6 +2635,7 @@ const CONST = { }, BANK_CONNECTIONS: { WELLS_FARGO: 'wellsfargo', + BANK_OF_AMERICA: 'bankofamerica', CHASE: 'chase', BREX: 'brex', CAPITAL_ONE: 'capitalone', diff --git a/src/libs/actions/getCompanyCardBankConnection/index.tsx b/src/libs/actions/getCompanyCardBankConnection/index.tsx index 0e0c0f6789b7..fb6dd9943972 100644 --- a/src/libs/actions/getCompanyCardBankConnection/index.tsx +++ b/src/libs/actions/getCompanyCardBankConnection/index.tsx @@ -1,5 +1,6 @@ import {getApiRoot} from '@libs/ApiUtils'; import * as NetworkStore from '@libs/Network/NetworkStore'; +import * as PolicyUtils from '@libs/PolicyUtils'; import CONST from '@src/CONST'; type CompanyCardBankConnection = { @@ -10,22 +11,20 @@ type CompanyCardBankConnection = { isNewDot: string; }; -// TODO remove this when BE will support bank UI callbacks -const bankUrl = 'https://secure.chase.com/web/auth/#/logon/logon/chaseOnline?redirect_url='; - -export default function getCompanyCardBankConnection(bankName?: string, domainName?: string, scrapeMinDate?: string) { +export default function getCompanyCardBankConnection(policyID?: string, bankName?: string, scrapeMinDate?: string) { const bankConnection = Object.keys(CONST.COMPANY_CARDS.BANKS).find((key) => CONST.COMPANY_CARDS.BANKS[key as keyof typeof CONST.COMPANY_CARDS.BANKS] === bankName); - // TODO remove this when BE will support bank UI callbacks - if (!domainName) { - return bankUrl; - } - - if (!bankName || !bankConnection) { + if (!bankName || !bankConnection || !policyID) { return null; } const authToken = NetworkStore.getAuthToken(); - const params: CompanyCardBankConnection = {authToken: authToken ?? '', isNewDot: 'true', domainName: domainName ?? '', isCorporate: 'true', scrapeMinDate: scrapeMinDate ?? ''}; + const params: CompanyCardBankConnection = { + authToken: authToken ?? '', + isNewDot: 'true', + domainName: PolicyUtils.getDomainNameForPolicy(policyID), + isCorporate: 'true', + scrapeMinDate: scrapeMinDate ?? '', + }; const commandURL = getApiRoot({ shouldSkipWebProxy: true, command: '', diff --git a/src/pages/workspace/companyCards/addNew/AddNewCardPage.tsx b/src/pages/workspace/companyCards/addNew/AddNewCardPage.tsx index 105c7107548d..1a3dce65788f 100644 --- a/src/pages/workspace/companyCards/addNew/AddNewCardPage.tsx +++ b/src/pages/workspace/companyCards/addNew/AddNewCardPage.tsx @@ -30,7 +30,7 @@ function AddNewCardPage({policy}: WithPolicyAndFullscreenLoadingProps) { case CONST.COMPANY_CARDS.STEP.CARD_TYPE: return ; case CONST.COMPANY_CARDS.STEP.BANK_CONNECTION: - return ; + return ; case CONST.COMPANY_CARDS.STEP.CARD_INSTRUCTIONS: return ; case CONST.COMPANY_CARDS.STEP.CARD_NAME: diff --git a/src/pages/workspace/companyCards/addNew/BankConnection/index.native.tsx b/src/pages/workspace/companyCards/addNew/BankConnection/index.native.tsx index 8de2b9baba9a..69ec5ee6586d 100644 --- a/src/pages/workspace/companyCards/addNew/BankConnection/index.native.tsx +++ b/src/pages/workspace/companyCards/addNew/BankConnection/index.native.tsx @@ -13,7 +13,11 @@ import getCompanyCardBankConnection from '@userActions/getCompanyCardBankConnect import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -function BankConnection() { +type BankConnectionStepProps = { + policyID?: string; +}; + +function BankConnection({policyID}: BankConnectionStepProps) { const {translate} = useLocalize(); const webViewRef = useRef(null); const [isWebViewOpen, setWebViewOpen] = useState(false); @@ -21,7 +25,7 @@ function BankConnection() { const authToken = session?.authToken ?? null; const [addNewCard] = useOnyx(ONYXKEYS.ADD_NEW_COMPANY_CARD); const bankName: ValueOf | undefined = addNewCard?.data?.selectedBank; - const url = getCompanyCardBankConnection(bankName); + const url = getCompanyCardBankConnection(policyID, bankName); const renderLoading = () => ; diff --git a/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx b/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx index 2b4d86f2e43b..43432760210a 100644 --- a/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx +++ b/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx @@ -19,14 +19,18 @@ import openBankConnection from './openBankConnection'; let customWindow: Window | null = null; -function BankConnection() { +type BankConnectionStepProps = { + policyID?: string; +}; + +function BankConnection({policyID}: BankConnectionStepProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); const [addNewCard] = useOnyx(ONYXKEYS.ADD_NEW_COMPANY_CARD); const bankName: ValueOf | undefined = addNewCard?.data?.selectedBank; const currentUrl = getCurrentUrl(); const isBankConnectionCompleteRoute = currentUrl.includes(ROUTES.BANK_CONNECTION_COMPLETE); - const url = getCompanyCardBankConnection(bankName); + const url = getCompanyCardBankConnection(policyID, bankName); const onOpenBankConnectionFlow = useCallback(() => { if (!url) {