Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion src/components/Navigation/DebugTabView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function DebugTabView({selectedTab, chatTabBrickRoad}: DebugTabViewProps) {
}
}, [selectedTab, chatTabBrickRoad, orderedReportIDs, reportAttributes, status, reimbursementAccount, policyIDWithErrors]);

if (!([NAVIGATION_TABS.INBOX, NAVIGATION_TABS.SETTINGS, NAVIGATION_TABS.WORKSPACES] as string[]).includes(selectedTab ?? '') || !indicator) {
if (!([NAVIGATION_TABS.INBOX, NAVIGATION_TABS.SETTINGS, NAVIGATION_TABS.WORKSPACES] as string[]).includes(selectedTab ?? '') || !indicator || !message) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useNavigationTabBarIndicatorChecks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function useNavigationTabBarIndicatorChecks(): NavigationTabBarChecksResult {
// we only care if a single error / info condition exists anywhere.
const accountChecks: Partial<Record<IndicatorStatus, boolean>> = {
[CONST.INDICATOR_STATUS.HAS_USER_WALLET_ERRORS]: Object.keys(userWallet?.errors ?? {}).length > 0,
[CONST.INDICATOR_STATUS.HAS_PAYMENT_METHOD_ERROR]: hasPaymentMethodError(bankAccountList, fundList, allCards),
[CONST.INDICATOR_STATUS.HAS_PAYMENT_METHOD_ERROR]: hasPaymentMethodError(bankAccountList, fundList, allCards, session, policies),
[CONST.INDICATOR_STATUS.HAS_SUBSCRIPTION_ERRORS]: hasSubscriptionRedDotError(
stripeCustomerId,
retryBillingSuccessful,
Expand Down
37 changes: 30 additions & 7 deletions src/libs/actions/PaymentMethods.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {RefObject} from 'react';
import type {OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import type {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import type {KYCWallRef} from '@components/KYCWall/types';
Expand All @@ -18,14 +18,17 @@ import * as CardUtils from '@libs/CardUtils';
import GoogleTagManager from '@libs/GoogleTagManager';
import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
import {isPolicyUser} from '@libs/PolicyUtils';
import {getCardForSubscriptionBilling} from '@libs/SubscriptionUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Route} from '@src/ROUTES';
import INPUT_IDS from '@src/types/form/AddPaymentCardForm';
import type {BankAccountList, CardList, FundList} from '@src/types/onyx';
import type PaymentMethod from '@src/types/onyx/PaymentMethod';
import type Policy from '@src/types/onyx/Policy';
import type {OnyxData} from '@src/types/onyx/Request';
import type Session from '@src/types/onyx/Session';
import type {FilterMethodPaymentType} from '@src/types/onyx/WalletTransfer';

/**
Expand Down Expand Up @@ -409,13 +412,33 @@ function dismissSuccessfulTransferBalancePage() {
}

/**
* Looks through each payment method to see if there is an existing error
*
* Looks through each payment method to see if there is an existing error.
* When session and policies are provided, card list errors are only counted if the current user
* is a member of that card's workspace (for company cards) or always counted for personal cards.
* Only cards with non-empty errors are considered (error cards).
*/
function hasPaymentMethodError(bankList: OnyxEntry<BankAccountList>, fundList: OnyxEntry<FundList>, cardList: OnyxEntry<CardList>): boolean {
const combinedPaymentMethods = {...bankList, ...fundList, ...cardList};

return Object.values(combinedPaymentMethods).some((item) => Object.keys(item.errors ?? {}).length);
function hasPaymentMethodError(
bankList: OnyxEntry<BankAccountList>,
fundList: OnyxEntry<FundList>,
cardList: OnyxEntry<CardList>,
session?: OnyxEntry<Session>,
policies?: OnyxCollection<Policy>,
): boolean {
const hasBankOrFundError = Object.values({...(bankList ?? {}), ...(fundList ?? {})}).some((item) => Object.keys(item?.errors ?? {}).length > 0);
const currentUserLogin = session?.email;
const cardsWithErrors = Object.values(cardList ?? {}).filter((card) => Object.keys(card?.errors ?? {}).length > 0);

const policyList = Object.values(policies ?? {}).filter(Boolean);
const hasRelevantCardError = cardsWithErrors.some((card) => {
if (CardUtils.isPersonalCard(card)) {
return true;
}
const workspaceAccountID = Number(card?.fundID);
const policy = policyList.find((p) => p?.workspaceAccountID === workspaceAccountID);
return !!policy && isPolicyUser(policy, currentUserLogin);
});
// If there is card with errors, we should display the RBR if user is a member of the workspace.
return hasRelevantCardError || hasBankOrFundError;
}

type PaymentListKey =
Expand Down
5 changes: 1 addition & 4 deletions src/pages/settings/InitialSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,15 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr
const shouldDisplayLHB = !shouldUseNarrowLayout;

const {
all: {shouldShowRBR},
personalCard: {shouldShowRBR: shouldShowRBRForPersonalCard},
} = useCardFeedErrors();

const hasPendingCardAction = hasPendingExpensifyCardAction(allCards, privatePersonalDetails);
let walletBrickRoadIndicator;
if (
hasPaymentMethodError(bankAccountList, fundList, allCards) ||
hasPaymentMethodError(bankAccountList, fundList, allCards, session, policies) ||
!isEmptyObject(userWallet?.errors) ||
!isEmptyObject(walletTerms?.errors) ||
!isEmptyObject(unsharedBankAccount?.errors) ||
shouldShowRBR ||
shouldShowRBRForPersonalCard
) {
walletBrickRoadIndicator = CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR;
Expand Down
Loading