Skip to content

Commit

Permalink
Merge pull request #51384 from narefyev91/add-bank-urls
Browse files Browse the repository at this point in the history
[CP Staging] [NO QA]: Add bank urls to Company Card flow

(cherry picked from commit 7e5910e)

(CP triggered by mountiny)
  • Loading branch information
mountiny authored and OSBotify committed Oct 24, 2024
1 parent cb45d58 commit b6eae36
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2635,6 +2635,7 @@ const CONST = {
},
BANK_CONNECTIONS: {
WELLS_FARGO: 'wellsfargo',
BANK_OF_AMERICA: 'bankofamerica',
CHASE: 'chase',
BREX: 'brex',
CAPITAL_ONE: 'capitalone',
Expand Down
21 changes: 10 additions & 11 deletions src/libs/actions/getCompanyCardBankConnection/index.tsx
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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: '',
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/companyCards/addNew/AddNewCardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function AddNewCardPage({policy}: WithPolicyAndFullscreenLoadingProps) {
case CONST.COMPANY_CARDS.STEP.CARD_TYPE:
return <CardTypeStep />;
case CONST.COMPANY_CARDS.STEP.BANK_CONNECTION:
return <BankConnection />;
return <BankConnection policyID={policyID} />;
case CONST.COMPANY_CARDS.STEP.CARD_INSTRUCTIONS:
return <CardInstructionsStep policyID={policyID} />;
case CONST.COMPANY_CARDS.STEP.CARD_NAME:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ 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<WebView>(null);
const [isWebViewOpen, setWebViewOpen] = useState(false);
const [session] = useOnyx(ONYXKEYS.SESSION);
const authToken = session?.authToken ?? null;
const [addNewCard] = useOnyx(ONYXKEYS.ADD_NEW_COMPANY_CARD);
const bankName: ValueOf<typeof CONST.COMPANY_CARDS.BANKS> | undefined = addNewCard?.data?.selectedBank;
const url = getCompanyCardBankConnection(bankName);
const url = getCompanyCardBankConnection(policyID, bankName);

const renderLoading = () => <FullScreenLoadingIndicator />;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof CONST.COMPANY_CARDS.BANKS> | 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) {
Expand Down

0 comments on commit b6eae36

Please sign in to comment.