Skip to content

Commit

Permalink
fixes bad commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ishpaul777 committed Nov 18, 2024
1 parent 79bf01c commit bbb4ea2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
9 changes: 9 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8433,6 +8433,14 @@ function hasInvoiceReports() {
return allReports.some((report) => isInvoiceReport(report));
}

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

export {
addDomainToShortMention,
completeShortMention,
Expand Down Expand Up @@ -8760,6 +8768,7 @@ export {
getAllReportErrors,
getAllReportActionsErrorsAndReportActionThatRequiresAttention,
hasInvoiceReports,
areAllGroupPoliciesExpenseChatDisabled,
};

export type {
Expand Down
8 changes: 3 additions & 5 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 ConfirmModal from '@components/ConfirmModal';
import DotIndicatorMessage from '@components/DotIndicatorMessage';
import EmptyStateComponent from '@components/EmptyStateComponent';
Expand All @@ -25,6 +26,7 @@ import * as IOU from '@userActions/IOU';
import * as Link from '@userActions/Link';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type * as OnyxTypes from '@src/types/onyx';
import type {SearchDataTypes} from '@src/types/onyx/SearchResults';

type EmptySearchViewProps = {
Expand All @@ -50,11 +52,7 @@ function EmptySearchView({type}: EmptySearchViewProps) {
const [modalVisible, setModalVisible] = useState(false);
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
const shouldRedirectToExpensifyClassic = useMemo(() => {
const groupPolicies = Object.values(allPolicies ?? {}).filter((policy) => ReportUtils.isGroupPolicy(policy?.type ?? ''));
if (groupPolicies.length === 0) {
return false;
}
return !groupPolicies.some((policy) => !!policy?.isPolicyExpenseChatEnabled);
return ReportUtils.areAllGroupPoliciesExpenseChatDisabled((allPolicies as OnyxCollection<OnyxTypes.Policy>) ?? {});
}, [allPolicies]);

const [ctaErrorMessage, setCtaErrorMessage] = useState('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl

const {canUseSpotnanaTravel, canUseCombinedTrackSubmit} = usePermissions();
const canSendInvoice = useMemo(() => PolicyUtils.canSendInvoice(allPolicies as OnyxCollection<OnyxTypes.Policy>, session?.email), [allPolicies, session?.email]);
const isValidReport = !(isEmptyObject(quickActionReport) || ReportUtils.isArchivedRoom(quickActionReport, reportNameValuePairs));
const {environment} = useEnvironment();
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
const navatticURL = getNavatticURL(environment, introSelected?.choice);
Expand All @@ -191,19 +190,15 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
* 2. none of the group policies they are a member of have isPolicyExpenseChatEnabled=true
*/
const shouldRedirectToExpensifyClassic = useMemo(() => {
const groupPolicies = Object.values(allPolicies ?? {}).filter((policy) => ReportUtils.isGroupPolicy(policy?.type ?? ''));
if (groupPolicies.length === 0) {
return false;
}
return !groupPolicies.some((policy) => !!policy?.isPolicyExpenseChatEnabled);
return ReportUtils.areAllGroupPoliciesExpenseChatDisabled((allPolicies as OnyxCollection<OnyxTypes.Policy>) ?? {});
}, [allPolicies]);

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

const quickActionAvatars = useMemo(() => {
if (isValidReport) {
if (quickActionReport) {
const avatars = ReportUtils.getIcons(quickActionReport, personalDetails);
return avatars.length <= 1 || ReportUtils.isPolicyExpenseChat(quickActionReport) ? avatars : avatars.filter((avatar) => avatar.id !== session?.accountID);
}
Expand Down Expand Up @@ -238,15 +233,15 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
}, [quickAction, translate, quickActionAvatars, quickActionReport]);

const hideQABSubtitle = useMemo(() => {
if (!isValidReport) {
if (isEmptyObject(quickActionReport)) {
return true;
}
if (quickActionAvatars.length === 0) {
return false;
}
const displayName = personalDetails?.[quickActionAvatars.at(0)?.id ?? -1]?.firstName ?? '';
return quickAction?.action === CONST.QUICK_ACTIONS.SEND_MONEY && displayName.length === 0;
}, [isValidReport, quickActionAvatars, personalDetails, quickAction?.action]);
}, [personalDetails, quickActionReport, quickAction?.action, quickActionAvatars]);

const selectOption = useCallback(
(onSelected: () => void, shouldRestrictAction: boolean) => {
Expand All @@ -260,6 +255,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
);

const navigateToQuickAction = useCallback(() => {
const isValidReport = !(isEmptyObject(quickActionReport) || ReportUtils.isArchivedRoom(quickActionReport, reportNameValuePairs));
const quickActionReportID = isValidReport ? quickActionReport?.reportID ?? '-1' : ReportUtils.generateReportID();

switch (quickAction?.action) {
Expand Down Expand Up @@ -288,7 +284,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
break;
default:
}
}, [isValidReport, quickAction?.action, quickAction?.targetAccountID, quickActionReport?.reportID, selectOption]);
}, [quickAction, quickActionReport, reportNameValuePairs, selectOption]);

/**
* Check if LHN status changed from active to inactive.
Expand Down Expand Up @@ -476,6 +472,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
onSelected: () =>
interceptAnonymousUser(() => {
selectOption(() => {
const isValidReport = !(isEmptyObject(policyChatForActivePolicy) || ReportUtils.isArchivedRoom(policyChatForActivePolicy, reportNameValuePairs));
const quickActionReportID = isValidReport ? policyChatForActivePolicy?.reportID ?? '-1' : ReportUtils.generateReportID();
IOU.startMoneyRequest(CONST.IOU.TYPE.SUBMIT, quickActionReportID ?? '-1', CONST.IOU.REQUEST_TYPE.SCAN, true);
}, true);
Expand All @@ -502,7 +499,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
quickActionReport,
navigateToQuickAction,
selectOption,
isValidReport,
reportNameValuePairs,
]);

return (
Expand Down

0 comments on commit bbb4ea2

Please sign in to comment.