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
9 changes: 9 additions & 0 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,14 @@ function isPolicyAccessible(policy: OnyxEntry<Policy>): boolean {
);
}

function areAllGroupPoliciesExpenseChatDisabled(policies = allPolicies) {
const groupPolicies = Object.values(policies ?? {}).filter((policy) => isPaidGroupPolicy(policy));
if (groupPolicies.length === 0) {
return false;
}
return !groupPolicies.some((policy) => !!policy?.isPolicyExpenseChatEnabled);
}

function getGroupPaidPoliciesWithExpenseChatEnabled(policies: OnyxCollection<Policy> | null = allPolicies) {
if (isEmptyObject(policies)) {
return CONST.EMPTY_ARRAY;
Expand Down Expand Up @@ -1490,6 +1498,7 @@ export {
getManagerAccountID,
isPrefferedExporter,
isAutoSyncEnabled,
areAllGroupPoliciesExpenseChatDisabled,
};

export type {MemberEmailsToAccountIDs};
6 changes: 4 additions & 2 deletions src/pages/Search/EmptySearchView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {useMemo, useState} from 'react';
import {Linking, View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import type {OnyxCollection} from 'react-native-onyx';
import BookTravelButton from '@components/BookTravelButton';
import ConfirmModal from '@components/ConfirmModal';
import EmptyStateComponent from '@components/EmptyStateComponent';
Expand All @@ -23,12 +24,13 @@ import {canActionTask, canModifyTask, completeTask} from '@libs/actions/Task';
import {setSelfTourViewed} from '@libs/actions/Welcome';
import interceptAnonymousUser from '@libs/interceptAnonymousUser';
import {hasSeenTourSelector} from '@libs/onboardingSelectors';
import {getGroupPaidPoliciesWithExpenseChatEnabled} from '@libs/PolicyUtils';
import {areAllGroupPoliciesExpenseChatDisabled} from '@libs/PolicyUtils';
import {generateReportID} from '@libs/ReportUtils';
import {getNavatticURL} from '@libs/TourUtils';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Policy} from '@src/types/onyx';
import type {SearchDataTypes} from '@src/types/onyx/SearchResults';

type EmptySearchViewProps = {
Expand All @@ -55,7 +57,7 @@ function EmptySearchView({type, hasResults}: EmptySearchViewProps) {
const [modalVisible, setModalVisible] = useState(false);
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
const shouldRedirectToExpensifyClassic = useMemo(() => {
return getGroupPaidPoliciesWithExpenseChatEnabled(allPolicies).length === 0;
return areAllGroupPoliciesExpenseChatDisabled((allPolicies as OnyxCollection<Policy>) ?? {});
}, [allPolicies]);

const tripViewChildren = useMemo(() => {
Expand Down
14 changes: 10 additions & 4 deletions src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ import interceptAnonymousUser from '@libs/interceptAnonymousUser';
import navigateAfterInteraction from '@libs/Navigation/navigateAfterInteraction';
import Navigation from '@libs/Navigation/Navigation';
import {hasSeenTourSelector} from '@libs/onboardingSelectors';
import {canSendInvoice as canSendInvoicePolicyUtils, getGroupPaidPoliciesWithExpenseChatEnabled, isPaidGroupPolicy, shouldShowPolicy} from '@libs/PolicyUtils';
import {
areAllGroupPoliciesExpenseChatDisabled,
canSendInvoice as canSendInvoicePolicyUtils,
getGroupPaidPoliciesWithExpenseChatEnabled,
isPaidGroupPolicy,
shouldShowPolicy,
} from '@libs/PolicyUtils';
import {canCreateRequest, generateReportID, getDisplayNameForParticipant, getIcons, getReportName, getWorkspaceChats, isArchivedReport, isPolicyExpenseChat} from '@libs/ReportUtils';
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
import {getNavatticURL} from '@libs/TourUtils';
Expand Down Expand Up @@ -220,8 +226,8 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, isT
* 2. none of the group policies they are a member of have isPolicyExpenseChatEnabled=true
*/
const shouldRedirectToExpensifyClassic = useMemo(() => {
return groupPoliciesWithChatEnabled.length === 0;
}, [groupPoliciesWithChatEnabled.length]);
return areAllGroupPoliciesExpenseChatDisabled((allPolicies as OnyxCollection<OnyxTypes.Policy>) ?? {});
}, [allPolicies]);

const shouldShowNewWorkspaceButton = Object.values(allPolicies ?? {}).every((policy) => !shouldShowPolicy(policy as OnyxEntry<OnyxTypes.Policy>, !!isOffline, session?.email));

Expand Down Expand Up @@ -479,7 +485,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, isT
text: translate('report.newReport.createReport'),
onSelected: () => {
interceptAnonymousUser(() => {
if (shouldRedirectToExpensifyClassic) {
if (groupPoliciesWithChatEnabled.length === 0) {
setModalVisible(true);
return;
}
Expand Down