diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 943361d31bc5..4e060faa8eff 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -520,8 +520,6 @@ type OptionData = { isConciergeChat?: boolean; isBold?: boolean; lastIOUCreationDate?: string; - isChatRoom?: boolean; - participantsList?: PersonalDetails[]; icons?: Icon[]; iouReportAmount?: number; displayName?: string; @@ -6352,7 +6350,7 @@ function shouldDisplayViolationsRBRInLHN(report: OnyxEntry, transactionV // - Belong to the same workspace // And if any have a violation, then it should have a RBR const allReports = Object.values(ReportConnection.getAllReports() ?? {}) as Report[]; - const potentialReports = allReports.filter((r) => r?.ownerAccountID === currentUserAccountID && (r?.stateNum ?? 0) <= 1 && r?.policyID === report.policyID); + const potentialReports = allReports.filter((r) => r.ownerAccountID === currentUserAccountID && (r.stateNum ?? 0) <= 1 && r.policyID === report.policyID); return potentialReports.some( (potentialReport) => hasViolations(potentialReport.reportID, transactionViolations) || hasWarningTypeViolations(potentialReport.reportID, transactionViolations), ); @@ -6425,23 +6423,21 @@ function getAllReportActionsErrorsAndReportActionThatRequiresAttention(report: O ? undefined : allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID ?? '-1'}`]?.[report.parentReportActionID ?? '-1']; - if (!isArchivedRoom(report)) { - if (ReportActionsUtils.wasActionTakenByCurrentUser(parentReportAction) && ReportActionsUtils.isTransactionThread(parentReportAction)) { - const transactionID = ReportActionsUtils.isMoneyRequestAction(parentReportAction) ? ReportActionsUtils.getOriginalMessage(parentReportAction)?.IOUTransactionID : null; - const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; - if (TransactionUtils.hasMissingSmartscanFields(transaction ?? null) && !isSettled(transaction?.reportID)) { - reportActionErrors.smartscan = ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericSmartscanFailureMessage'); - reportAction = undefined; - } - } else if ((isIOUReport(report) || isExpenseReport(report)) && report?.ownerAccountID === currentUserAccountID) { - if (shouldShowRBRForMissingSmartscanFields(report?.reportID ?? '-1') && !isSettled(report?.reportID)) { - reportActionErrors.smartscan = ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericSmartscanFailureMessage'); - reportAction = getReportActionWithMissingSmartscanFields(report?.reportID ?? '-1'); - } - } else if (hasSmartscanError(reportActionsArray)) { + if (ReportActionsUtils.wasActionTakenByCurrentUser(parentReportAction) && ReportActionsUtils.isTransactionThread(parentReportAction)) { + const transactionID = ReportActionsUtils.isMoneyRequestAction(parentReportAction) ? ReportActionsUtils.getOriginalMessage(parentReportAction)?.IOUTransactionID : null; + const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; + if (TransactionUtils.hasMissingSmartscanFields(transaction ?? null) && !isSettled(transaction?.reportID)) { + reportActionErrors.smartscan = ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericSmartscanFailureMessage'); + reportAction = undefined; + } + } else if ((isIOUReport(report) || isExpenseReport(report)) && report?.ownerAccountID === currentUserAccountID) { + if (shouldShowRBRForMissingSmartscanFields(report?.reportID ?? '-1') && !isSettled(report?.reportID)) { reportActionErrors.smartscan = ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericSmartscanFailureMessage'); - reportAction = getReportActionWithSmartscanError(reportActionsArray); + reportAction = getReportActionWithMissingSmartscanFields(report?.reportID ?? '-1'); } + } else if (hasSmartscanError(reportActionsArray)) { + reportActionErrors.smartscan = ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericSmartscanFailureMessage'); + reportAction = getReportActionWithSmartscanError(reportActionsArray); } return { @@ -7944,30 +7940,6 @@ function getOptimisticDataForParentReportAction(reportID: string, lastVisibleAct }); } -function getQuickActionDetails( - quickActionReport: Report, - personalDetails: PersonalDetailsList | undefined, - policyChatForActivePolicy: Report | undefined, - reportNameValuePairs: ReportNameValuePairs, -): {quickActionAvatars: Icon[]; hideQABSubtitle: boolean} { - const isValidQuickActionReport = !(isEmptyObject(quickActionReport) || isArchivedRoom(quickActionReport, reportNameValuePairs)); - let hideQABSubtitle = false; - let quickActionAvatars: Icon[] = []; - if (isValidQuickActionReport) { - const avatars = getIcons(quickActionReport, personalDetails); - quickActionAvatars = avatars.length <= 1 || isPolicyExpenseChat(quickActionReport) ? avatars : avatars.filter((avatar) => avatar.id !== currentUserAccountID); - } else { - hideQABSubtitle = true; - } - if (!isEmptyObject(policyChatForActivePolicy)) { - quickActionAvatars = getIcons(policyChatForActivePolicy, personalDetails); - } - return { - quickActionAvatars, - hideQABSubtitle, - }; -} - function canBeAutoReimbursed(report: OnyxInputOrEntry, policy: OnyxInputOrEntry): boolean { if (isEmptyObject(policy)) { return false; @@ -8433,6 +8405,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, @@ -8590,7 +8570,6 @@ export { getInvoicePayerName, getInvoicesChatName, getPayeeName, - getQuickActionDetails, hasActionsWithErrors, hasAutomatedExpensifyAccountIDs, hasExpensifyGuidesEmails, @@ -8760,6 +8739,7 @@ export { getAllReportErrors, getAllReportActionsErrorsAndReportActionThatRequiresAttention, hasInvoiceReports, + areAllGroupPoliciesExpenseChatDisabled }; export type { diff --git a/src/pages/Search/EmptySearchView.tsx b/src/pages/Search/EmptySearchView.tsx index 33b67e9aae18..82ecc3d010d4 100644 --- a/src/pages/Search/EmptySearchView.tsx +++ b/src/pages/Search/EmptySearchView.tsx @@ -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'; @@ -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 = { @@ -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) ?? {}); }, [allPolicies]); const [ctaErrorMessage, setCtaErrorMessage] = useState(''); diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx index 82985c38c2ae..5e02844957a2 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx @@ -178,7 +178,6 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl const {canUseSpotnanaTravel, canUseCombinedTrackSubmit} = usePermissions(); const canSendInvoice = useMemo(() => PolicyUtils.canSendInvoice(allPolicies as OnyxCollection, 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); @@ -191,11 +190,7 @@ 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) ?? {}); }, [allPolicies]); const shouldShowNewWorkspaceButton = Object.values(allPolicies ?? {}).every( @@ -203,7 +198,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl ); 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); } @@ -238,7 +233,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl }, [quickAction, translate, quickActionAvatars, quickActionReport]); const hideQABSubtitle = useMemo(() => { - if (!isValidReport) { + if (isEmptyObject(quickActionReport)) { return true; } if (quickActionAvatars.length === 0) { @@ -246,7 +241,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl } 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) => { @@ -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) { @@ -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. @@ -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); @@ -502,7 +499,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl quickActionReport, navigateToQuickAction, selectOption, - isValidReport, + reportNameValuePairs, ]); return (