From 89ab6d0bab19f0453a4cf0a5b1b696dfab637729 Mon Sep 17 00:00:00 2001 From: Artem Makushov Date: Wed, 22 Jan 2025 02:13:58 +0700 Subject: [PATCH] update web behaviour of bank connection --- .../assignCard/BankConnection/index.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/pages/workspace/companyCards/assignCard/BankConnection/index.tsx b/src/pages/workspace/companyCards/assignCard/BankConnection/index.tsx index 32093b6d0279..fe17807c2ab1 100644 --- a/src/pages/workspace/companyCards/assignCard/BankConnection/index.tsx +++ b/src/pages/workspace/companyCards/assignCard/BankConnection/index.tsx @@ -1,4 +1,5 @@ import React, {useCallback, useEffect} from 'react'; +import {useOnyx} from 'react-native-onyx'; import BlockingView from '@components/BlockingViews/BlockingView'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import * as Illustrations from '@components/Icon/Illustrations'; @@ -8,12 +9,12 @@ import TextLink from '@components/TextLink'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import {setAssignCardStepAndData} from '@libs/actions/CompanyCards'; -import {getBankName} from '@libs/CardUtils'; +import {getBankName, isSelectedFeedExpired} from '@libs/CardUtils'; import Navigation from '@libs/Navigation/Navigation'; -import getCurrentUrl from '@navigation/currentUrl'; +import {getWorkspaceAccountID} from '@libs/PolicyUtils'; import getCompanyCardBankConnection from '@userActions/getCompanyCardBankConnection'; import CONST from '@src/CONST'; -import ROUTES from '@src/ROUTES'; +import ONYXKEYS from '@src/ONYXKEYS'; import type {CompanyCardFeed} from '@src/types/onyx'; import openBankConnection from './openBankConnection'; @@ -31,9 +32,10 @@ function BankConnection({policyID, feed}: BankConnectionStepProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); const bankName = getBankName(feed); - const currentUrl = getCurrentUrl(); - const isBankConnectionCompleteRoute = currentUrl.includes(ROUTES.BANK_CONNECTION_COMPLETE); + const workspaceAccountID = getWorkspaceAccountID(policyID); + const [cardFeeds] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`); const url = getCompanyCardBankConnection(policyID, bankName); + const isFeedExpired = isSelectedFeedExpired(cardFeeds?.settings?.oAuthAccountDetails?.[feed]); const onOpenBankConnectionFlow = useCallback(() => { if (!url) { @@ -57,7 +59,7 @@ function BankConnection({policyID, feed}: BankConnectionStepProps) { if (!url) { return; } - if (isBankConnectionCompleteRoute) { + if (!isFeedExpired) { customWindow?.close(); setAssignCardStepAndData({ currentStep: CONST.COMPANY_CARD.STEP.ASSIGNEE, @@ -66,7 +68,7 @@ function BankConnection({policyID, feed}: BankConnectionStepProps) { return; } customWindow = openBankConnection(url); - }, [isBankConnectionCompleteRoute, policyID, url]); + }, [isFeedExpired, policyID, url]); return (