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 1 commit
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
Prev Previous commit
Next Next commit
add dynamic policy
  • Loading branch information
narefyev91 committed Oct 24, 2024
commit 308cece2686a575bc98fe7ed03dc47244c0d2788
1 change: 0 additions & 1 deletion src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ const CONST = {
BILLABLE: 'billable',
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good, did you test atleast on one platform ?

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

Screen.Recording.2024-10-24.at.11.44.11.mov

NON_BILLABLE: 'nonBillable',
},
COMPANY_CARD_DOMAIN_NAME: 'expensify-policyABASDASDASDASDFASD.exfy',

// Note: Group and Self-DM excluded as these are not tied to a Workspace
WORKSPACE_ROOM_TYPES: [chatTypes.POLICY_ADMINS, chatTypes.POLICY_ANNOUNCE, chatTypes.DOMAIN_ALL, chatTypes.POLICY_ROOM, chatTypes.POLICY_EXPENSE_CHAT, chatTypes.INVOICE],
Expand Down
6 changes: 3 additions & 3 deletions src/libs/actions/getCompanyCardBankConnection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ type CompanyCardBankConnection = {
isNewDot: string;
};

export default function getCompanyCardBankConnection(bankName?: 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);

if (!bankName || !bankConnection) {
if (!bankName || !bankConnection || !policyID) {
return null;
}
const authToken = NetworkStore.getAuthToken();
const params: CompanyCardBankConnection = {
authToken: authToken ?? '',
isNewDot: 'true',
domainName: CONST.COMPANY_CARD_DOMAIN_NAME,
domainName: `expensify-policy${policyID}.exfy`,
narefyev91 marked this conversation as resolved.
Show resolved Hide resolved
isCorporate: 'true',
scrapeMinDate: scrapeMinDate ?? '',
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {useRoute} from '@react-navigation/native';
import React, {useEffect, useRef, useState} from 'react';
import {useOnyx} from 'react-native-onyx';
import {WebView} from 'react-native-webview';
Expand All @@ -14,14 +15,16 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';

function BankConnection() {
const params = useRoute().params as Record<string, string>;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not really the way we get route params, can you please update this , i can attach the pattern we follow below:

type WorkspaceCompanyCardDetailsPageProps = StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.COMPANY_CARD_DETAILS>;
function WorkspaceCompanyCardDetailsPage({route}: WorkspaceCompanyCardDetailsPageProps) {
const {policyID, cardID, backTo, bank} = route.params;

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 but it's not a navigation page - it's just a component

Copy link
Contributor

Choose a reason for hiding this comment

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

ummm, can't we then just pass the prop down to the component then? do we do the same thing in other component pages ? just that i saw this pattern for the first time

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 - passed inside AddNewCardPage

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 policyID = params?.policyID;
const url = getCompanyCardBankConnection(policyID, bankName);

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {useRoute} from '@react-navigation/native';
import React, {useCallback, useEffect} from 'react';
import {useOnyx} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
Expand All @@ -20,13 +21,15 @@ import openBankConnection from './openBankConnection';
let customWindow: Window | null = null;

function BankConnection() {
const params = useRoute().params as Record<string, string>;
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 policyID = params?.policyID;
const url = getCompanyCardBankConnection(policyID, bankName);

const onOpenBankConnectionFlow = useCallback(() => {
if (!url) {
Expand Down
Loading