Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
17a397c
fix ts
narefyev91 Nov 7, 2025
2c7724d
Merge branch 'refs/heads/main' into block-any-attempts-to-connect-to-…
narefyev91 Nov 7, 2025
36edfc8
cherry pick changes
narefyev91 Nov 7, 2025
52954ab
add correct prop
narefyev91 Nov 7, 2025
e95e431
Merge branch 'refs/heads/main' into block-any-attempts-to-connect-to-…
narefyev91 Nov 7, 2025
65afe30
update logic for catching feeds
narefyev91 Nov 12, 2025
e51a6ee
Merge branch 'refs/heads/main' into block-any-attempts-to-connect-to-…
narefyev91 Nov 12, 2025
820c709
Update src/hooks/useIsBlockedToAddFeed.ts
narefyev91 Nov 13, 2025
7fe9ef4
Update src/pages/workspace/companyCards/BankConnection/index.tsx
narefyev91 Nov 13, 2025
31eb1a4
Update src/pages/workspace/companyCards/BankConnection/index.tsx
narefyev91 Nov 13, 2025
eb9f101
Update src/pages/workspace/companyCards/BankConnection/index.tsx
narefyev91 Nov 13, 2025
82a4590
Update src/pages/workspace/companyCards/addNew/AddNewCardPage.tsx
narefyev91 Nov 13, 2025
c7ca02d
Update src/pages/workspace/companyCards/BankConnection/index.native.tsx
narefyev91 Nov 13, 2025
2ad6531
Update src/pages/workspace/companyCards/BankConnection/index.native.tsx
narefyev91 Nov 13, 2025
c77ed25
fix comments
narefyev91 Nov 13, 2025
3f568f8
Merge branch 'refs/heads/main' into block-any-attempts-to-connect-to-…
narefyev91 Nov 17, 2025
6e35f10
merge conflicts
narefyev91 Nov 17, 2025
b477dfe
Merge branch 'main' into block-any-attempts-to-connect-to-feed-with-c…
narefyev91 Nov 18, 2025
33a10dc
revert changes after merge
narefyev91 Nov 18, 2025
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
2 changes: 2 additions & 0 deletions src/components/Icon/chunks/illustrations.chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Company Cards
import type {SvgProps} from 'react-native-svg';
import CompanyCardsEmptyState from '@assets/images/companyCards/emptystate__card-pos.svg';
import PendingBank from '@assets/images/companyCards/pending-bank.svg';
// Other assets
import Computer from '@assets/images/computer.svg';
import ExpensifyCardImage from '@assets/images/expensify-card.svg';
Expand Down Expand Up @@ -39,6 +40,7 @@ import Workflows from '@assets/images/simple-illustrations/simple-illustration__
const Illustrations = {
// Company Cards
CompanyCardsEmptyState,
PendingBank,

// Other assets
Computer,
Expand Down
51 changes: 51 additions & 0 deletions src/hooks/useIsBlockedToAddFeed.ts
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';

Comment thread
narefyev91 marked this conversation as resolved.
Resolved
/**
* 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);
Comment thread
narefyev91 marked this conversation as resolved.
Resolved
const [cardFeeds, allFeedsResult, defaultFeed] = useCardFeeds(policyID);
const [lastSelectedFeed] = useOnyx(`${ONYXKEYS.COLLECTION.LAST_SELECTED_FEED}${policyID}`, {canBeMissing: true});
Comment thread
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);
Comment thread
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(() => {
Comment thread
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;
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import useCardFeeds from '@hooks/useCardFeeds';
import useImportPlaidAccounts from '@hooks/useImportPlaidAccounts';
import useIsBlockedToAddFeed from '@hooks/useIsBlockedToAddFeed';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePermissions from '@hooks/usePermissions';
Expand Down Expand Up @@ -71,9 +72,19 @@ function BankConnection({policyID: policyIDFromProps, feed, route}: BankConnecti
const onImportPlaidAccounts = useImportPlaidAccounts(policyID);
const {updateBrokenConnection, isFeedConnectionBroken} = useUpdateFeedBrokenConnection({policyID, feed});
const isNewFeedHasError = !!(newFeed && cardFeeds?.settings?.oAuthAccountDetails?.[newFeed]?.errors);
const {isBlockedToAddNewFeeds, isAllFeedsResultLoading} = useIsBlockedToAddFeed(policyID);

const renderLoading = () => <FullScreenLoadingIndicator />;
Comment thread
narefyev91 marked this conversation as resolved.
Resolved

useEffect(() => {
if (!policyID || !isBlockedToAddNewFeeds) {
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 = () => {
// Handle assign card flow
if (feed) {
Expand Down Expand Up @@ -169,7 +180,7 @@ function BankConnection({policyID: policyIDFromProps, feed, route}: BankConnecti
onBackButtonPress={handleBackButtonPress}
/>
<FullPageOfflineBlockingView addBottomSafeAreaPadding>
{!!url && !isConnectionCompleted && !isPlaid && !isNewFeedHasError && (
{!!url && !isConnectionCompleted && !isPlaid && !isNewFeedHasError && !isAllFeedsResultLoading && !isBlockedToAddNewFeeds && (
<WebView
ref={webViewRef}
source={{
Expand All @@ -185,7 +196,7 @@ function BankConnection({policyID: policyIDFromProps, feed, route}: BankConnecti
renderLoading={renderLoading}
/>
)}
{(isConnectionCompleted || isPlaid) && !isNewFeedHasError && (
{(isAllFeedsResultLoading || isBlockedToAddNewFeeds || isConnectionCompleted || isPlaid) && !isNewFeedHasError && (
<ActivityIndicator
size={CONST.ACTIVITY_INDICATOR_SIZE.LARGE}
style={styles.flex1}
Expand Down
22 changes: 18 additions & 4 deletions src/pages/workspace/companyCards/BankConnection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -82,6 +85,15 @@ function BankConnection({policyID: policyIDFromProps, feed, route}: BankConnecti
customWindow = openBankConnection(url);
}, [url]);

useEffect(() => {
Comment thread
narefyev91 marked this conversation as resolved.
Resolved
if (!policyID || !isBlockedToAddNewFeeds) {

@hungvu193 hungvu193 Mar 6, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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();

Expand Down Expand Up @@ -118,7 +130,7 @@ function BankConnection({policyID: policyIDFromProps, feed, route}: BankConnecti
);
Comment thread
narefyev91 marked this conversation as resolved.
Resolved

useEffect(() => {
if ((!url && !isPlaid) || isOffline || isNewFeedHasError) {
if ((!url && !isPlaid) || isOffline || isNewFeedHasError || isAllFeedsResultLoading || isBlockedToAddNewFeeds) {
return;
}

Expand Down Expand Up @@ -177,7 +189,9 @@ function BankConnection({policyID: policyIDFromProps, feed, route}: BankConnecti
}
}, [
isNewFeedConnected,
isAllFeedsResultLoading,
shouldBlockWindowOpen,
isBlockedToAddNewFeeds,
newFeed,
policyID,
url,
Expand All @@ -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')}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React from 'react';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import MenuItem from '@components/MenuItem';
import PlaidCardFeedIcon from '@components/PlaidCardFeedIcon';
import ScreenWrapper from '@components/ScreenWrapper';
import SelectionList from '@components/SelectionList';
import RadioListItem from '@components/SelectionList/ListItem/RadioListItem';
import type {ListItem} from '@components/SelectionList/types';
import useCardFeeds from '@hooks/useCardFeeds';
import useIsBlockedToAddFeed from '@hooks/useIsBlockedToAddFeed';
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePolicy from '@hooks/usePolicy';
Expand All @@ -26,7 +27,6 @@ import {
} from '@libs/CardUtils';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {SettingsNavigatorParamList} from '@libs/Navigation/types';
import {isCollectPolicy} from '@libs/PolicyUtils';
import Navigation from '@navigation/Navigation';
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
import variables from '@styles/variables';
Expand Down Expand Up @@ -58,7 +58,8 @@ function WorkspaceCompanyCardFeedSelectorPage({route}: WorkspaceCompanyCardFeedS
const [lastSelectedFeed] = useOnyx(`${ONYXKEYS.COLLECTION.LAST_SELECTED_FEED}${policyID}`, {canBeMissing: true});
const selectedFeed = getSelectedFeed(lastSelectedFeed, cardFeeds);
const companyFeeds = getCompanyFeeds(cardFeeds);
const isCollect = isCollectPolicy(policy);
const {isBlockedToAddNewFeeds} = useIsBlockedToAddFeed(policyID);
Comment thread
narefyev91 marked this conversation as resolved.
Resolved
const icons = useMemoizedLazyExpensifyIcons(['Plus'] as const);

const feeds: CardFeedListItem[] = Object.entries(companyFeeds).map(([key, feedSettings]) => {
const feed = key as CompanyCardFeed;
Expand Down Expand Up @@ -95,7 +96,7 @@ function WorkspaceCompanyCardFeedSelectorPage({route}: WorkspaceCompanyCardFeedS

const onAddCardsPress = () => {
clearAddNewCardFlow();
if (isCollect && feeds.length === 1) {
if (isBlockedToAddNewFeeds) {
Navigation.navigate(
ROUTES.WORKSPACE_UPGRADE.getRoute(policyID, CONST.UPGRADE_FEATURE_INTRO_MAPPING.companyCards.alias, ROUTES.WORKSPACE_COMPANY_CARDS_SELECT_FEED.getRoute(policyID)),
);
Expand Down Expand Up @@ -136,7 +137,7 @@ function WorkspaceCompanyCardFeedSelectorPage({route}: WorkspaceCompanyCardFeedS
listFooterContent={
<MenuItem
title={translate('workspace.companyCards.addCards')}
icon={Expensicons.Plus}
icon={icons.Plus}
onPress={onAddCardsPress}
/>
}
Expand Down
15 changes: 14 additions & 1 deletion src/pages/workspace/companyCards/addNew/AddNewCardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ import ConfirmModal from '@components/ConfirmModal';
import DelegateNoAccessWrapper from '@components/DelegateNoAccessWrapper';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import ScreenWrapper from '@components/ScreenWrapper';
import useIsBlockedToAddFeed from '@hooks/useIsBlockedToAddFeed';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePermissions from '@hooks/usePermissions';
import useThemeStyles from '@hooks/useThemeStyles';
import useWorkspaceAccountID from '@hooks/useWorkspaceAccountID';
import {navigateToConciergeChat} from '@libs/actions/Report';
import Navigation from '@navigation/Navigation';
import BankConnection from '@pages/workspace/companyCards/BankConnection';
import withPolicyAndFullscreenLoading from '@pages/workspace/withPolicyAndFullscreenLoading';
import type {WithPolicyAndFullscreenLoadingProps} from '@pages/workspace/withPolicyAndFullscreenLoading';
import {clearAddNewCardFlow, openPolicyAddCardFeedPage} from '@userActions/CompanyCards';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';
import AmexCustomFeed from './AmexCustomFeed';
import CardInstructionsStep from './CardInstructionsStep';
Expand All @@ -37,13 +40,23 @@ function AddNewCardPage({policy}: WithPolicyAndFullscreenLoadingProps) {
const [addNewCardFeed, addNewCardFeedMetadata] = useOnyx(ONYXKEYS.ADD_NEW_COMPANY_CARD, {canBeMissing: false});
const {currentStep} = addNewCardFeed ?? {};
const {isBetaEnabled} = usePermissions();
const {isBlockedToAddNewFeeds, isAllFeedsResultLoading} = useIsBlockedToAddFeed(policyID);
const [isModalVisible, setIsModalVisible] = useState(false);
const {translate} = useLocalize();

const [isActingAsDelegate] = useOnyx(ONYXKEYS.ACCOUNT, {selector: isActingAsDelegateSelector, canBeMissing: false});

const isAddCardFeedLoading = isLoadingOnyxValue(addNewCardFeedMetadata);

useEffect(() => {
Comment thread
narefyev91 marked this conversation as resolved.
Resolved
if (!policyID || !isBlockedToAddNewFeeds) {
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]);

useEffect(() => {
return () => {
clearAddNewCardFlow();
Expand All @@ -60,7 +73,7 @@ function AddNewCardPage({policy}: WithPolicyAndFullscreenLoadingProps) {
openPolicyAddCardFeedPage(policyID);
Comment thread
narefyev91 marked this conversation as resolved.
Resolved
}, [workspaceAccountID, policyID]);

if (isAddCardFeedLoading) {
if (isAddCardFeedLoading || isAllFeedsResultLoading || isBlockedToAddNewFeeds) {
return <FullScreenLoadingIndicator />;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SelectionList from '@components/SelectionListWithSections';
import RadioListItem from '@components/SelectionListWithSections/RadioListItem';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import usePermissions from '@hooks/usePermissions';
import useThemeIllustrations from '@hooks/useThemeIllustrations';
Expand All @@ -30,6 +31,7 @@ function SelectBankStep() {
const styles = useThemeStyles();
const illustrations = useThemeIllustrations();
const {isBetaEnabled} = usePermissions();
const {isOffline} = useNetwork();

const [addNewCard] = useOnyx(ONYXKEYS.ADD_NEW_COMPANY_CARD, {canBeMissing: true});
const [bankSelected, setBankSelected] = useState<ValueOf<typeof CONST.COMPANY_CARDS.BANKS> | null>();
Expand Down Expand Up @@ -97,7 +99,6 @@ function SelectBankStep() {
title={translate('workspace.companyCards.addCards')}
onBackButtonPress={handleBackButtonPress}
/>

<Text style={[styles.textHeadlineLineHeightXXL, styles.ph5, styles.mv3]}>{translate('workspace.companyCards.addNewCard.whoIsYourBankAccount')}</Text>
<SelectionList
ListItem={RadioListItem}
Expand All @@ -112,6 +113,7 @@ function SelectBankStep() {
showConfirmButton
confirmButtonText={translate('common.next')}
onConfirm={submit}
isConfirmButtonDisabled={isOffline}
confirmButtonStyles={!hasError && styles.mt5}
addBottomSafeAreaPadding
>
Expand Down
Loading