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

[CP Staging] [NO QA]: Add bank urls to Company Card flow #51384

Merged
merged 7 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
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,4 +1,5 @@
import {getApiRoot} from '@libs/ApiUtils';
import getPolicyDomainName from '@libs/getPolicyDomainName';
import * as NetworkStore from '@libs/Network/NetworkStore';
import CONST from '@src/CONST';

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: getPolicyDomainName(policyID),
isCorporate: 'true',
scrapeMinDate: scrapeMinDate ?? '',
};
const commandURL = getApiRoot({
shouldSkipWebProxy: true,
command: '',
Expand Down
3 changes: 3 additions & 0 deletions src/libs/getPolicyDomainName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function getPolicyDomainName(policyID: string): string {
return `expensify-policy${policyID}.exfy`;
Copy link
Contributor

Choose a reason for hiding this comment

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

@narefyev91 actually relaized, this has to be lowercase, can you make sure the returned string is made lowercase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mountiny you mean policyID value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

Copy link
Contributor

@mountiny mountiny Oct 24, 2024

Choose a reason for hiding this comment

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

Yeah the entire thing but the policyID in there would be passed as uppercase

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah i found already existed util function for that

}
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB: but in future PR can you please move this to the existing policy utils file?

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
Loading