Repository navigation
Block any attempts to connect to feed with collect limitation #74557
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
Merged
mountiny
merged 19 commits into
Expensify:main
from
callstack-internal:block-any-attempts-to-connect-to-feed-with-collect-limitation
Nov 19, 2025
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
17a397c
fix ts
narefyev91 2c7724d
Merge branch 'refs/heads/main' into block-any-attempts-to-connect-to-…
narefyev91 36edfc8
cherry pick changes
narefyev91 52954ab
add correct prop
narefyev91 e95e431
Merge branch 'refs/heads/main' into block-any-attempts-to-connect-to-…
narefyev91 65afe30
update logic for catching feeds
narefyev91 e51a6ee
Merge branch 'refs/heads/main' into block-any-attempts-to-connect-to-…
narefyev91 820c709
Update src/hooks/useIsBlockedToAddFeed.ts
narefyev91 7fe9ef4
Update src/pages/workspace/companyCards/BankConnection/index.tsx
narefyev91 31eb1a4
Update src/pages/workspace/companyCards/BankConnection/index.tsx
narefyev91 eb9f101
Update src/pages/workspace/companyCards/BankConnection/index.tsx
narefyev91 82a4590
Update src/pages/workspace/companyCards/addNew/AddNewCardPage.tsx
narefyev91 c7ca02d
Update src/pages/workspace/companyCards/BankConnection/index.native.tsx
narefyev91 2ad6531
Update src/pages/workspace/companyCards/BankConnection/index.native.tsx
narefyev91 c77ed25
fix comments
narefyev91 3f568f8
Merge branch 'refs/heads/main' into block-any-attempts-to-connect-to-…
narefyev91 6e35f10
merge conflicts
narefyev91 b477dfe
Merge branch 'main' into block-any-attempts-to-connect-to-feed-with-c…
narefyev91 33a10dc
revert changes after merge
narefyev91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import {useEffect, useState} from 'react'; | ||
| import {getCompanyFeeds, getSelectedFeed} from '@libs/CardUtils'; | ||
| import {isCollectPolicy} from '@libs/PolicyUtils'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import {isEmptyObject} from '@src/types/utils/EmptyObject'; | ||
| import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue'; | ||
| import useCardFeeds from './useCardFeeds'; | ||
| import useCardsList from './useCardsList'; | ||
| import useOnyx from './useOnyx'; | ||
| import usePolicy from './usePolicy'; | ||
|
|
||
| /** | ||
| * Hook to determine if a workspace on the Collect plan should be blocked from adding additional company card feeds. | ||
| * | ||
| * Collect plan workspaces are limited to one company card feed. This hook checks if the workspace already has | ||
| * a feed and returns whether users should be blocked from adding more feeds. | ||
| * | ||
| * @param policyID - The ID of the workspace/policy to check | ||
| * @returns An object containing: | ||
| * - isBlockedToAddNewFeeds: true if the workspace should be blocked from adding new feeds (Collect plan with 1+ existing feeds) | ||
| * - isAllFeedsResultLoading: true if feed data is still being loaded | ||
| */ | ||
| function useIsBlockedToAddFeed(policyID?: string) { | ||
| const policy = usePolicy(policyID); | ||
|
narefyev91 marked this conversation as resolved.
Resolved
|
||
| const [cardFeeds, allFeedsResult, defaultFeed] = useCardFeeds(policyID); | ||
| const [lastSelectedFeed] = useOnyx(`${ONYXKEYS.COLLECTION.LAST_SELECTED_FEED}${policyID}`, {canBeMissing: true}); | ||
|
narefyev91 marked this conversation as resolved.
Resolved
|
||
| const companyFeeds = getCompanyFeeds(cardFeeds, true); | ||
| const isCollect = isCollectPolicy(policy); | ||
| const isAllFeedsResultLoading = isLoadingOnyxValue(allFeedsResult); | ||
| const selectedFeed = getSelectedFeed(lastSelectedFeed, cardFeeds); | ||
|
narefyev91 marked this conversation as resolved.
Resolved
|
||
| const [cardsList] = useCardsList(policyID, selectedFeed); | ||
| const [prevCompanyFeedsLength, setPrevCompanyFeedsLength] = useState(0); | ||
|
|
||
| const isLoading = !cardFeeds || (!!cardFeeds.isLoading && isEmptyObject(cardsList)) || !!defaultFeed?.isLoading; | ||
|
|
||
| useEffect(() => { | ||
|
narefyev91 marked this conversation as resolved.
Resolved
|
||
| if (isLoading) { | ||
| return; | ||
| } | ||
| const connectedFeeds = Object.entries(companyFeeds)?.length; | ||
| setPrevCompanyFeedsLength(connectedFeeds); | ||
| // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps -- we don't want this effect to run again | ||
| }, [isLoading]); | ||
|
|
||
| return { | ||
| isBlockedToAddNewFeeds: isCollect && !isLoading && prevCompanyFeedsLength >= 1, | ||
| isAllFeedsResultLoading: isCollect && (isLoading || isAllFeedsResultLoading), | ||
| }; | ||
| } | ||
|
|
||
| export default useIsBlockedToAddFeed; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,12 +3,13 @@ import ActivityIndicator from '@components/ActivityIndicator'; | |
| import BlockingView from '@components/BlockingViews/BlockingView'; | ||
| import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOfflineBlockingView'; | ||
| import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
| import {PendingBank} from '@components/Icon/Illustrations'; | ||
| import ScreenWrapper from '@components/ScreenWrapper'; | ||
| import Text from '@components/Text'; | ||
| import TextLink from '@components/TextLink'; | ||
| import useCardFeeds from '@hooks/useCardFeeds'; | ||
| import useImportPlaidAccounts from '@hooks/useImportPlaidAccounts'; | ||
| import useIsBlockedToAddFeed from '@hooks/useIsBlockedToAddFeed'; | ||
| import {useMemoizedLazyIllustrations} from '@hooks/useLazyAsset'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useNetwork from '@hooks/useNetwork'; | ||
| import useOnyx from '@hooks/useOnyx'; | ||
|
|
@@ -54,6 +55,7 @@ function BankConnection({policyID: policyIDFromProps, feed, route}: BankConnecti | |
| const policyID = policyIDFromProps ?? policyIDFromRoute; | ||
| const [cardFeeds] = useCardFeeds(policyID); | ||
| const prevFeedsData = usePrevious(cardFeeds?.settings?.oAuthAccountDetails); | ||
| const illustrations = useMemoizedLazyIllustrations(['PendingBank'] as const); | ||
| const [shouldBlockWindowOpen, setShouldBlockWindowOpen] = useState(false); | ||
| const selectedBank = addNewCard?.data?.selectedBank; | ||
| const bankName = feed ? getBankName(feed) : (bankNameFromRoute ?? addNewCard?.data?.plaidConnectedFeed ?? selectedBank); | ||
|
|
@@ -73,6 +75,7 @@ function BankConnection({policyID: policyIDFromProps, feed, route}: BankConnecti | |
| const headerTitle = feed ? translate('workspace.companyCards.assignCard') : headerTitleAddCards; | ||
| const isNewFeedHasError = !!(newFeed && cardFeeds?.settings?.oAuthAccountDetails?.[newFeed]?.errors); | ||
| const onImportPlaidAccounts = useImportPlaidAccounts(policyID); | ||
| const {isBlockedToAddNewFeeds, isAllFeedsResultLoading} = useIsBlockedToAddFeed(policyID); | ||
|
|
||
| const onOpenBankConnectionFlow = useCallback(() => { | ||
| if (!url) { | ||
|
|
@@ -82,6 +85,15 @@ function BankConnection({policyID: policyIDFromProps, feed, route}: BankConnecti | |
| customWindow = openBankConnection(url); | ||
| }, [url]); | ||
|
|
||
| useEffect(() => { | ||
|
narefyev91 marked this conversation as resolved.
Resolved
|
||
| if (!policyID || !isBlockedToAddNewFeeds) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also add the check for direct feed to prevent showing the Upgrade page while reauthentication is required. Context: #80799 (comment) |
||
| return; | ||
| } | ||
| Navigation.navigate(ROUTES.WORKSPACE_UPGRADE.getRoute(policyID, CONST.UPGRADE_FEATURE_INTRO_MAPPING.companyCards.alias, ROUTES.WORKSPACE_COMPANY_CARDS.getRoute(policyID)), { | ||
| forceReplace: true, | ||
| }); | ||
| }, [isBlockedToAddNewFeeds, policyID]); | ||
|
|
||
| const handleBackButtonPress = () => { | ||
| customWindow?.close(); | ||
|
|
||
|
|
@@ -118,7 +130,7 @@ function BankConnection({policyID: policyIDFromProps, feed, route}: BankConnecti | |
| ); | ||
|
narefyev91 marked this conversation as resolved.
Resolved
|
||
|
|
||
| useEffect(() => { | ||
| if ((!url && !isPlaid) || isOffline || isNewFeedHasError) { | ||
| if ((!url && !isPlaid) || isOffline || isNewFeedHasError || isAllFeedsResultLoading || isBlockedToAddNewFeeds) { | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -177,7 +189,9 @@ function BankConnection({policyID: policyIDFromProps, feed, route}: BankConnecti | |
| } | ||
| }, [ | ||
| isNewFeedConnected, | ||
| isAllFeedsResultLoading, | ||
| shouldBlockWindowOpen, | ||
| isBlockedToAddNewFeeds, | ||
| newFeed, | ||
| policyID, | ||
| url, | ||
|
|
@@ -201,10 +215,10 @@ function BankConnection({policyID: policyIDFromProps, feed, route}: BankConnecti | |
| /> | ||
| ); | ||
| } | ||
| if (!isPlaid) { | ||
| if (!isPlaid && !isAllFeedsResultLoading && !isBlockedToAddNewFeeds) { | ||
| return ( | ||
| <BlockingView | ||
| icon={PendingBank} | ||
| icon={illustrations.PendingBank} | ||
| iconWidth={styles.pendingBankCardIllustration.width} | ||
| iconHeight={styles.pendingBankCardIllustration.height} | ||
| title={translate('workspace.moreFeatures.companyCards.pendingBankTitle')} | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.