From ff470f653ee24474976505f67d0f44f95c6300d1 Mon Sep 17 00:00:00 2001 From: Nathalie Kuoch Date: Thu, 16 Oct 2025 11:40:44 +0200 Subject: [PATCH 1/2] Allow to refresh plaid accountList with existing accessToken when trying to assign --- src/hooks/useImportPlaidAccounts.ts | 2 +- .../API/parameters/ImportPlaidAccountsParams.ts | 1 + src/libs/actions/Plaid.ts | 2 ++ .../companyCards/WorkspaceCompanyCardsPage.tsx | 14 ++++++++++++-- .../companyCards/addNew/PlaidConnectionStep.tsx | 1 + src/types/onyx/CardFeeds.ts | 3 +++ 6 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/hooks/useImportPlaidAccounts.ts b/src/hooks/useImportPlaidAccounts.ts index 4a4de355374a..da3a7b697dc0 100644 --- a/src/hooks/useImportPlaidAccounts.ts +++ b/src/hooks/useImportPlaidAccounts.ts @@ -20,6 +20,6 @@ export default function useImportPlaidAccounts(policyID?: string) { if (!policyID || !plaidToken || !plaidFeed || !plaidFeedName || !country || !plaidAccounts?.length) { return; } - importPlaidAccounts(plaidToken, plaidFeed, plaidFeedName, country, getDomainNameForPolicy(policyID), JSON.stringify(plaidAccounts), statementPeriodEnd, statementPeriodEndDay); + importPlaidAccounts(plaidToken, plaidFeed, plaidFeedName, country, getDomainNameForPolicy(policyID), JSON.stringify(plaidAccounts), statementPeriodEnd, statementPeriodEndDay, ''); }, [statementPeriodEnd, statementPeriodEndDay, country, plaidAccounts, plaidFeed, plaidFeedName, plaidToken, policyID]); } diff --git a/src/libs/API/parameters/ImportPlaidAccountsParams.ts b/src/libs/API/parameters/ImportPlaidAccountsParams.ts index a03a1cc541f5..bc13b5b0dfee 100644 --- a/src/libs/API/parameters/ImportPlaidAccountsParams.ts +++ b/src/libs/API/parameters/ImportPlaidAccountsParams.ts @@ -9,6 +9,7 @@ type ImportPlaidAccountsParams = { plaidAccounts: string; statementPeriodEnd?: StatementPeriodEnd; statementPeriodEndDay?: StatementPeriodEndDay; + plaidAccessToken?: string; }; export default ImportPlaidAccountsParams; diff --git a/src/libs/actions/Plaid.ts b/src/libs/actions/Plaid.ts index b9dd3df186db..ddfd73c563c7 100644 --- a/src/libs/actions/Plaid.ts +++ b/src/libs/actions/Plaid.ts @@ -126,6 +126,7 @@ function importPlaidAccounts( plaidAccounts: string, statementPeriodEnd: StatementPeriodEnd | undefined, statementPeriodEndDay: StatementPeriodEndDay | undefined, + plaidAccessToken: string | undefined, ) { const parameters: ImportPlaidAccountsParams = { publicToken, @@ -136,6 +137,7 @@ function importPlaidAccounts( plaidAccounts, statementPeriodEnd, statementPeriodEndDay, + plaidAccessToken, }; API.write(WRITE_COMMANDS.IMPORT_PLAID_ACCOUNTS, parameters); diff --git a/src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx b/src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx index e814886842e6..8e6a221dc84c 100644 --- a/src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx +++ b/src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx @@ -27,10 +27,11 @@ import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import type {WorkspaceSplitNavigatorParamList} from '@libs/Navigation/types'; import {getPersonalDetailByEmail} from '@libs/PersonalDetailsUtils'; -import {isDeletedPolicyEmployee} from '@libs/PolicyUtils'; +import {getDomainNameForPolicy, isDeletedPolicyEmployee} from '@libs/PolicyUtils'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; import WorkspacePageWithSections from '@pages/workspace/WorkspacePageWithSections'; import {clearAddNewCardFlow, openPolicyCompanyCardsFeed, openPolicyCompanyCardsPage, setAddNewCompanyCardStepAndData, setAssignCardStepAndData} from '@userActions/CompanyCards'; +import {importPlaidAccounts} from '@userActions/Plaid'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; @@ -122,7 +123,16 @@ function WorkspaceCompanyCardsPage({route}: WorkspaceCompanyCardsPageProps) { let currentStep: AssignCardStep = CONST.COMPANY_CARD.STEP.ASSIGNEE; const employeeList = Object.values(policy?.employeeList ?? {}).filter((employee) => !isDeletedPolicyEmployee(employee, isOffline)); - const isFeedExpired = isSelectedFeedExpired(selectedFeed ? cardFeeds?.settings?.oAuthAccountDetails?.[selectedFeed] : undefined); + const selectedFeedCompanyCardsData = selectedFeed ? cardFeeds?.settings?.companyCards?.[selectedFeed] : undefined; + const selectedFeedOAuthData = selectedFeed ? cardFeeds?.settings?.oAuthAccountDetails?.[selectedFeed] : undefined; + const isFeedExpired = isSelectedFeedExpired(selectedFeedOAuthData); + const plaidAccessToken = selectedFeedCompanyCardsData?.plaidAccessToken; + + // Refetch plaid card list if we somehow lost the selected feed data + if (plaidAccessToken && !selectedFeedOAuthData) { + const country = selectedFeedCompanyCardsData?.country ?? ''; + importPlaidAccounts('', selectedFeed, '', country, getDomainNameForPolicy(policyID), '', undefined, undefined, plaidAccessToken); + } if (employeeList.length === 1) { const userEmail = Object.keys(policy?.employeeList ?? {}).at(0) ?? ''; diff --git a/src/pages/workspace/companyCards/addNew/PlaidConnectionStep.tsx b/src/pages/workspace/companyCards/addNew/PlaidConnectionStep.tsx index d77bb54536ea..38ed852a0426 100644 --- a/src/pages/workspace/companyCards/addNew/PlaidConnectionStep.tsx +++ b/src/pages/workspace/companyCards/addNew/PlaidConnectionStep.tsx @@ -130,6 +130,7 @@ function PlaidConnectionStep({feed, policyID}: {feed?: CompanyCardFeed; policyID JSON.stringify(metadata?.accounts), addNewCard.data.statementPeriodEnd, addNewCard.data.statementPeriodEndDay, + '', ); // eslint-disable-next-line @typescript-eslint/no-deprecated InteractionManager.runAfterInteractions(() => { diff --git a/src/types/onyx/CardFeeds.ts b/src/types/onyx/CardFeeds.ts index 189a71068157..33a179bf1f9a 100644 --- a/src/types/onyx/CardFeeds.ts +++ b/src/types/onyx/CardFeeds.ts @@ -61,6 +61,9 @@ type CustomCardFeedData = OnyxCommon.OnyxValueWithOfflineFeedback<{ /** Preferred policy */ preferredPolicy?: string; + /** Country associated with this feed (ISO 3166-1 alpha-2 code) */ + country?: string; + /** The id of the domain the feed relates to */ domainID?: number; From 75a240d62b10e94f1c232b9c0d629ca3da246aeb Mon Sep 17 00:00:00 2001 From: Nathalie Kuoch Date: Sun, 19 Oct 2025 18:20:05 +0200 Subject: [PATCH 2/2] Refresh plaid card list when opening assign panel --- .../workspace/companyCards/WorkspaceCompanyCardsPage.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx b/src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx index 8e6a221dc84c..abc84ed0d2a8 100644 --- a/src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx +++ b/src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx @@ -128,8 +128,8 @@ function WorkspaceCompanyCardsPage({route}: WorkspaceCompanyCardsPageProps) { const isFeedExpired = isSelectedFeedExpired(selectedFeedOAuthData); const plaidAccessToken = selectedFeedCompanyCardsData?.plaidAccessToken; - // Refetch plaid card list if we somehow lost the selected feed data - if (plaidAccessToken && !selectedFeedOAuthData) { + // Refetch plaid card list + if (!isFeedExpired && plaidAccessToken) { const country = selectedFeedCompanyCardsData?.country ?? ''; importPlaidAccounts('', selectedFeed, '', country, getDomainNameForPolicy(policyID), '', undefined, undefined, plaidAccessToken); }