From 910f999dfc865eb2509a57869f6b15ab52848093 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Tue, 5 Nov 2024 16:00:32 +0700 Subject: [PATCH 01/13] redirect to feed after completing the bank connection --- .../workspace/companyCards/addNew/BankConnection/index.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx b/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx index 43432760210a..9f4e0252b173 100644 --- a/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx +++ b/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx @@ -16,11 +16,12 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import openBankConnection from './openBankConnection'; +import Navigation from '@libs/Navigation/Navigation'; let customWindow: Window | null = null; type BankConnectionStepProps = { - policyID?: string; + policyID: string; }; function BankConnection({policyID}: BankConnectionStepProps) { @@ -65,10 +66,11 @@ function BankConnection({policyID}: BankConnectionStepProps) { } if (isBankConnectionCompleteRoute) { customWindow?.close(); + Navigation.navigate(ROUTES.WORKSPACE_COMPANY_CARDS.getRoute(policyID)); return; } customWindow = openBankConnection(url); - }, [isBankConnectionCompleteRoute, url]); + }, [isBankConnectionCompleteRoute, policyID, url]); return ( From 7a0b5534c0780af31f90adf885ad3e2c14cfd652 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Tue, 5 Nov 2024 16:05:26 +0700 Subject: [PATCH 02/13] lint fix --- src/pages/workspace/companyCards/addNew/AddNewCardPage.tsx | 2 +- .../workspace/companyCards/addNew/BankConnection/index.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/workspace/companyCards/addNew/AddNewCardPage.tsx b/src/pages/workspace/companyCards/addNew/AddNewCardPage.tsx index 1a3dce65788f..0d88f98dbe40 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.tsx b/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx index 9f4e0252b173..41bf99375d5a 100644 --- a/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx +++ b/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx @@ -9,6 +9,7 @@ import Text from '@components/Text'; import TextLink from '@components/TextLink'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; +import Navigation from '@libs/Navigation/Navigation'; import getCurrentUrl from '@navigation/currentUrl'; import * as CompanyCards from '@userActions/CompanyCards'; import getCompanyCardBankConnection from '@userActions/getCompanyCardBankConnection'; @@ -16,7 +17,6 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import openBankConnection from './openBankConnection'; -import Navigation from '@libs/Navigation/Navigation'; let customWindow: Window | null = null; From 60699227c1b8a5536f08b14fb91db79049102e9a Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 6 Nov 2024 13:20:46 +0700 Subject: [PATCH 03/13] update customWindow close logic --- .../companyCards/addNew/BankConnection/index.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx b/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx index 41bf99375d5a..0c57bacddb2d 100644 --- a/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx +++ b/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx @@ -10,12 +10,14 @@ import TextLink from '@components/TextLink'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; +import * as PolicyUtils from '@libs/PolicyUtils'; import getCurrentUrl from '@navigation/currentUrl'; import * as CompanyCards from '@userActions/CompanyCards'; import getCompanyCardBankConnection from '@userActions/getCompanyCardBankConnection'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; +import {isEmptyObject} from '@src/types/utils/EmptyObject'; import openBankConnection from './openBankConnection'; let customWindow: Window | null = null; @@ -29,6 +31,12 @@ function BankConnection({policyID}: BankConnectionStepProps) { const {translate} = useLocalize(); const [addNewCard] = useOnyx(ONYXKEYS.ADD_NEW_COMPANY_CARD); const bankName: ValueOf | undefined = addNewCard?.data?.selectedBank; + const workspaceAccountID = PolicyUtils.getWorkspaceAccountID(policyID ?? '-1'); + const [cardFeeds] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`); + const bankKey = Object.keys(CONST.COMPANY_CARDS.BANKS).find((value) => CONST.COMPANY_CARDS.BANKS[value] === bankName); + const feedName = CONST.COMPANY_CARD.FEED_BANK_NAME[bankKey]; + const connectedBank = cardFeeds?.settings?.oAuthAccountDetails?.[feedName] ?? undefined; + const currentUrl = getCurrentUrl(); const isBankConnectionCompleteRoute = currentUrl.includes(ROUTES.BANK_CONNECTION_COMPLETE); const url = getCompanyCardBankConnection(policyID, bankName); @@ -64,13 +72,17 @@ function BankConnection({policyID}: BankConnectionStepProps) { if (!url) { return; } - if (isBankConnectionCompleteRoute) { + if (connectedBank && !isEmptyObject(connectedBank) && customWindow) { customWindow?.close(); Navigation.navigate(ROUTES.WORKSPACE_COMPANY_CARDS.getRoute(policyID)); return; } + if (isBankConnectionCompleteRoute) { + customWindow?.close(); + return; + } customWindow = openBankConnection(url); - }, [isBankConnectionCompleteRoute, policyID, url]); + }, [connectedBank, isBankConnectionCompleteRoute, policyID, url]); return ( From 4193bf9734c18b9bd91fee49d149569d0ba244d4 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 6 Nov 2024 13:23:33 +0700 Subject: [PATCH 04/13] update the policy d --- src/pages/workspace/companyCards/addNew/AddNewCardPage.tsx | 2 +- .../workspace/companyCards/addNew/BankConnection/index.tsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/workspace/companyCards/addNew/AddNewCardPage.tsx b/src/pages/workspace/companyCards/addNew/AddNewCardPage.tsx index 0d88f98dbe40..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.tsx b/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx index 0c57bacddb2d..0a399a9473c8 100644 --- a/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx +++ b/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx @@ -23,7 +23,7 @@ import openBankConnection from './openBankConnection'; let customWindow: Window | null = null; type BankConnectionStepProps = { - policyID: string; + policyID?: string; }; function BankConnection({policyID}: BankConnectionStepProps) { @@ -74,7 +74,7 @@ function BankConnection({policyID}: BankConnectionStepProps) { } if (connectedBank && !isEmptyObject(connectedBank) && customWindow) { customWindow?.close(); - Navigation.navigate(ROUTES.WORKSPACE_COMPANY_CARDS.getRoute(policyID)); + Navigation.navigate(ROUTES.WORKSPACE_COMPANY_CARDS.getRoute(policyID ?? '-1')); return; } if (isBankConnectionCompleteRoute) { From 468f6e45a744f6eba8df96ad7d5584963ba0770f Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 6 Nov 2024 13:30:12 +0700 Subject: [PATCH 05/13] lint fix --- .../workspace/companyCards/addNew/BankConnection/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx b/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx index 0a399a9473c8..f765647fe1fc 100644 --- a/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx +++ b/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx @@ -34,8 +34,8 @@ function BankConnection({policyID}: BankConnectionStepProps) { const workspaceAccountID = PolicyUtils.getWorkspaceAccountID(policyID ?? '-1'); const [cardFeeds] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`); const bankKey = Object.keys(CONST.COMPANY_CARDS.BANKS).find((value) => CONST.COMPANY_CARDS.BANKS[value] === bankName); - const feedName = CONST.COMPANY_CARD.FEED_BANK_NAME[bankKey]; - const connectedBank = cardFeeds?.settings?.oAuthAccountDetails?.[feedName] ?? undefined; + const feedName = bankKey ? CONST.COMPANY_CARD.FEED_BANK_NAME?.[bankKey] : undefined; + const connectedBank = feedName ? cardFeeds?.settings?.oAuthAccountDetails?.[feedName] : undefined; const currentUrl = getCurrentUrl(); const isBankConnectionCompleteRoute = currentUrl.includes(ROUTES.BANK_CONNECTION_COMPLETE); From 78e616c841e6ddbdc6de672f1e5fb9124f089ad9 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 6 Nov 2024 14:23:36 +0700 Subject: [PATCH 06/13] lint fix --- .../workspace/companyCards/addNew/BankConnection/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx b/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx index f765647fe1fc..3f171d1e658b 100644 --- a/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx +++ b/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx @@ -33,8 +33,8 @@ function BankConnection({policyID}: BankConnectionStepProps) { const bankName: ValueOf | undefined = addNewCard?.data?.selectedBank; const workspaceAccountID = PolicyUtils.getWorkspaceAccountID(policyID ?? '-1'); const [cardFeeds] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`); - const bankKey = Object.keys(CONST.COMPANY_CARDS.BANKS).find((value) => CONST.COMPANY_CARDS.BANKS[value] === bankName); - const feedName = bankKey ? CONST.COMPANY_CARD.FEED_BANK_NAME?.[bankKey] : undefined; + const bankKey = Object.keys(CONST.COMPANY_CARDS.BANKS).find((value) => CONST.COMPANY_CARDS.BANKS?.[value as keyof typeof CONST.COMPANY_CARDS.BANKS] === bankName); + const feedName = bankKey && bankKey !== CONST.COMPANY_CARDS.BANKS.OTHER ? CONST.COMPANY_CARD.FEED_BANK_NAME?.[bankKey as keyof typeof CONST.COMPANY_CARD.FEED_BANK_NAME] : undefined; const connectedBank = feedName ? cardFeeds?.settings?.oAuthAccountDetails?.[feedName] : undefined; const currentUrl = getCurrentUrl(); From 6986fd1da5a36adf48d07d59bb687fb3042cab22 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 6 Nov 2024 19:31:52 +0700 Subject: [PATCH 07/13] update selected feed --- .../workspace/companyCards/addNew/BankConnection/index.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx b/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx index 3f171d1e658b..f8ea39627ea9 100644 --- a/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx +++ b/src/pages/workspace/companyCards/addNew/BankConnection/index.tsx @@ -12,6 +12,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; import * as PolicyUtils from '@libs/PolicyUtils'; import getCurrentUrl from '@navigation/currentUrl'; +import * as Card from '@userActions/Card'; import * as CompanyCards from '@userActions/CompanyCards'; import getCompanyCardBankConnection from '@userActions/getCompanyCardBankConnection'; import CONST from '@src/CONST'; @@ -74,6 +75,9 @@ function BankConnection({policyID}: BankConnectionStepProps) { } if (connectedBank && !isEmptyObject(connectedBank) && customWindow) { customWindow?.close(); + if (feedName && policyID) { + Card.updateSelectedFeed(feedName, policyID); + } Navigation.navigate(ROUTES.WORKSPACE_COMPANY_CARDS.getRoute(policyID ?? '-1')); return; } @@ -82,7 +86,7 @@ function BankConnection({policyID}: BankConnectionStepProps) { return; } customWindow = openBankConnection(url); - }, [connectedBank, isBankConnectionCompleteRoute, policyID, url]); + }, [connectedBank, feedName, isBankConnectionCompleteRoute, policyID, url]); return ( From e1700f3426f40d67701e515f5f9cf85236866546 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 6 Nov 2024 21:01:44 +0700 Subject: [PATCH 08/13] update feed selection object --- src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx b/src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx index 05ba39335ee8..9e812a7c0a95 100644 --- a/src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx +++ b/src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx @@ -36,7 +36,7 @@ function WorkspaceCompanyCardPage({route}: WorkspaceCompanyCardPageProps) { const isLoading = !cardFeeds || !!(cardFeeds.isLoading && !cardFeeds.settings); const companyCards = CardUtils.removeExpensifyCardFromCompanyCards(cardFeeds?.settings?.companyCards); - const selectedCompanyCard = companyCards[selectedFeed ?? ''] ?? null; + const selectedCompanyCard = companyCards[selectedFeed ?? ''] ?? cardFeeds?.settings?.oAuthAccountDetails?.[selectedFeed ?? ''] ?? null; const isNoFeed = !selectedCompanyCard; const isPending = !!selectedCompanyCard?.pending; const isFeedAdded = !isPending && !isNoFeed; From b6e893ebf09611b7690b3c52d97fb5d1f43d68d7 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 6 Nov 2024 22:28:29 +0700 Subject: [PATCH 09/13] remove loading indicator --- .../companyCards/WorkspaceCompanyCardsList.tsx | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/pages/workspace/companyCards/WorkspaceCompanyCardsList.tsx b/src/pages/workspace/companyCards/WorkspaceCompanyCardsList.tsx index fd2c73ddb402..39e94d610f76 100644 --- a/src/pages/workspace/companyCards/WorkspaceCompanyCardsList.tsx +++ b/src/pages/workspace/companyCards/WorkspaceCompanyCardsList.tsx @@ -88,16 +88,6 @@ function WorkspaceCompanyCardsList({cardsList, policyID}: WorkspaceCompanyCardsL [styles, translate], ); - if (!cardsList) { - return ( - - ); - } - if (sortedCards.length === 0) { return ; } From 43f1c11cde57492d4a9af36226420e4bb953c5e1 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 6 Nov 2024 22:31:53 +0700 Subject: [PATCH 10/13] remove loading indicator --- .../workspace/companyCards/WorkspaceCompanyCardsList.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/pages/workspace/companyCards/WorkspaceCompanyCardsList.tsx b/src/pages/workspace/companyCards/WorkspaceCompanyCardsList.tsx index 39e94d610f76..667289360ac8 100644 --- a/src/pages/workspace/companyCards/WorkspaceCompanyCardsList.tsx +++ b/src/pages/workspace/companyCards/WorkspaceCompanyCardsList.tsx @@ -1,13 +1,12 @@ import React, {useCallback, useMemo} from 'react'; import type {ListRenderItemInfo} from 'react-native'; -import {ActivityIndicator, FlatList, View} from 'react-native'; +import {FlatList, View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import type {OnyxEntry} from 'react-native-onyx'; import OfflineWithFeedback from '@components/OfflineWithFeedback'; import {PressableWithFeedback} from '@components/Pressable'; import Text from '@components/Text'; import useLocalize from '@hooks/useLocalize'; -import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import * as CardUtils from '@libs/CardUtils'; import Navigation from '@navigation/Navigation'; @@ -28,7 +27,6 @@ type WorkspaceCompanyCardsListProps = { function WorkspaceCompanyCardsList({cardsList, policyID}: WorkspaceCompanyCardsListProps) { const styles = useThemeStyles(); - const theme = useTheme(); const {translate} = useLocalize(); const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); const [customCardNames] = useOnyx(ONYXKEYS.NVP_EXPENSIFY_COMPANY_CARDS_CUSTOM_NAMES); From d99a2ea7b8c2356dc721ccbebd1a1087ede03f18 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 6 Nov 2024 22:39:51 +0700 Subject: [PATCH 11/13] enable assign card button in direct feed --- .../companyCards/WorkspaceCompanyCardsListHeaderButtons.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/companyCards/WorkspaceCompanyCardsListHeaderButtons.tsx b/src/pages/workspace/companyCards/WorkspaceCompanyCardsListHeaderButtons.tsx index 1d5f2bd6dde5..e4c2681dac46 100644 --- a/src/pages/workspace/companyCards/WorkspaceCompanyCardsListHeaderButtons.tsx +++ b/src/pages/workspace/companyCards/WorkspaceCompanyCardsListHeaderButtons.tsx @@ -41,7 +41,7 @@ function WorkspaceCompanyCardsListHeaderButtons({policyID, selectedFeed}: Worksp const formattedFeedName = translate('workspace.companyCards.feedName', {feedName}); const isCustomFeed = CONST.COMPANY_CARD.FEED_BANK_NAME.MASTER_CARD === selectedFeed || CONST.COMPANY_CARD.FEED_BANK_NAME.VISA === selectedFeed || CONST.COMPANY_CARD.FEED_BANK_NAME.AMEX === selectedFeed; - const currentFeedData = cardFeeds?.settings?.companyCards?.[selectedFeed] ?? {pending: true, errors: {}}; + const currentFeedData = cardFeeds?.settings?.companyCards?.[selectedFeed] ?? cardFeeds?.settings?.oAuthAccountDetails?.[selectedFeed] ?? {pending: true, errors: {}}; return ( Date: Wed, 6 Nov 2024 22:47:47 +0700 Subject: [PATCH 12/13] lint fix --- .../companyCards/WorkspaceCompanyCardsListHeaderButtons.tsx | 1 + src/types/onyx/CardFeeds.ts | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/pages/workspace/companyCards/WorkspaceCompanyCardsListHeaderButtons.tsx b/src/pages/workspace/companyCards/WorkspaceCompanyCardsListHeaderButtons.tsx index e4c2681dac46..9c09abd5646f 100644 --- a/src/pages/workspace/companyCards/WorkspaceCompanyCardsListHeaderButtons.tsx +++ b/src/pages/workspace/companyCards/WorkspaceCompanyCardsListHeaderButtons.tsx @@ -79,6 +79,7 @@ function WorkspaceCompanyCardsListHeaderButtons({policyID, selectedFeed}: Worksp