diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index c596357585bc..d6163c98620f 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -611,6 +611,11 @@ function canSendInvoice(policies: OnyxCollection | null, currentUserLogi return getActiveAdminWorkspaces(policies, currentUserLogin).some((policy) => canSendInvoiceFromWorkspace(policy.id)); } +function hasWorkspaceWithInvoices(currentUserLogin: string | undefined): boolean { + const activePolicies = getActivePolicies(allPolicies); + return activePolicies.some((policy) => shouldShowPolicy(policy, NetworkStore.isOffline(), currentUserLogin) && policy.areInvoicesEnabled); +} + function hasDependentTags(policy: OnyxEntry, policyTagList: OnyxEntry) { if (!policy?.hasMultipleTagLists) { return false; @@ -1122,6 +1127,7 @@ export { getOwnedPaidPolicies, canSendInvoiceFromWorkspace, canSendInvoice, + hasWorkspaceWithInvoices, hasDependentTags, getXeroTenants, findCurrentXeroOrganization, diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index a62716975c01..dadcfe16dde0 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -8406,6 +8406,11 @@ function isExpenseReportWithoutParentAccess(report: OnyxEntry) { return isExpenseReport(report) && report?.hasParentAccess === false; } +function hasInvoiceReports() { + const allReports = Object.values(ReportConnection.getAllReports() ?? {}); + return allReports.some((report) => isInvoiceReport(report)); +} + export { addDomainToShortMention, completeShortMention, @@ -8731,6 +8736,7 @@ export { shouldShowViolations, getAllReportErrors, getAllReportActionsErrorsAndReportActionThatRequiresAttention, + hasInvoiceReports, }; export type { diff --git a/src/pages/Search/SearchTypeMenu.tsx b/src/pages/Search/SearchTypeMenu.tsx index 0267180c217a..6d74ccb46e21 100644 --- a/src/pages/Search/SearchTypeMenu.tsx +++ b/src/pages/Search/SearchTypeMenu.tsx @@ -20,7 +20,8 @@ import useSingleExecution from '@hooks/useSingleExecution'; import useThemeStyles from '@hooks/useThemeStyles'; import * as SearchActions from '@libs/actions/Search'; import Navigation from '@libs/Navigation/Navigation'; -import {getAllTaxRates} from '@libs/PolicyUtils'; +import {getAllTaxRates, hasWorkspaceWithInvoices} from '@libs/PolicyUtils'; +import {hasInvoiceReports} from '@libs/ReportUtils'; import * as SearchQueryUtils from '@libs/SearchQueryUtils'; import * as SearchUIUtils from '@libs/SearchUIUtils'; import variables from '@styles/variables'; @@ -63,6 +64,7 @@ function SearchTypeMenu({queryJSON, searchName}: SearchTypeMenuProps) { const [savedSearches] = useOnyx(ONYXKEYS.SAVED_SEARCHES); const [shouldShowSavedSearchRenameTooltip] = useOnyx(ONYXKEYS.SHOULD_SHOW_SAVED_SEARCH_RENAME_TOOLTIP); const {showDeleteModal, DeleteConfirmModal} = useDeleteSavedSearch(); + const [session] = useOnyx(ONYXKEYS.SESSION); const personalDetails = usePersonalDetails(); const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT); @@ -89,7 +91,10 @@ function SearchTypeMenu({queryJSON, searchName}: SearchTypeMenuProps) { return ROUTES.SEARCH_CENTRAL_PANE.getRoute({query}); }, }, - { + ]; + + if (hasWorkspaceWithInvoices(session?.email) || hasInvoiceReports()) { + typeMenuItems.push({ title: translate('workspace.common.invoices'), type: CONST.SEARCH.DATA_TYPES.INVOICE, icon: Expensicons.InvoiceGeneric, @@ -97,17 +102,17 @@ function SearchTypeMenu({queryJSON, searchName}: SearchTypeMenuProps) { const query = SearchQueryUtils.buildCannedSearchQuery({type: CONST.SEARCH.DATA_TYPES.INVOICE, status: CONST.SEARCH.STATUS.INVOICE.ALL, policyID}); return ROUTES.SEARCH_CENTRAL_PANE.getRoute({query}); }, + }); + } + typeMenuItems.push({ + title: translate('travel.trips'), + type: CONST.SEARCH.DATA_TYPES.TRIP, + icon: Expensicons.Suitcase, + getRoute: (policyID?: string) => { + const query = SearchQueryUtils.buildCannedSearchQuery({type: CONST.SEARCH.DATA_TYPES.TRIP, status: CONST.SEARCH.STATUS.TRIP.ALL, policyID}); + return ROUTES.SEARCH_CENTRAL_PANE.getRoute({query}); }, - { - title: translate('travel.trips'), - type: CONST.SEARCH.DATA_TYPES.TRIP, - icon: Expensicons.Suitcase, - getRoute: (policyID?: string) => { - const query = SearchQueryUtils.buildCannedSearchQuery({type: CONST.SEARCH.DATA_TYPES.TRIP, status: CONST.SEARCH.STATUS.TRIP.ALL, policyID}); - return ROUTES.SEARCH_CENTRAL_PANE.getRoute({query}); - }, - }, - ]; + }); const getOverflowMenu = useCallback( (itemName: string, itemHash: number, itemQuery: string) => SearchUIUtils.getOverflowMenu(itemName, itemHash, itemQuery, showDeleteModal),