Skip to content

Commit

Permalink
Merge pull request #52148 from jaydamani/search/remove-invoice-from-l…
Browse files Browse the repository at this point in the history
…hn--51620

feature(search): hide invoice type from search LHN
  • Loading branch information
luacmartins authored Nov 8, 2024
2 parents e4cdb42 + 5cc8fff commit 45a19bf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
6 changes: 6 additions & 0 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,11 @@ function canSendInvoice(policies: OnyxCollection<Policy> | 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<Policy>, policyTagList: OnyxEntry<PolicyTagLists>) {
if (!policy?.hasMultipleTagLists) {
return false;
Expand Down Expand Up @@ -1133,6 +1138,7 @@ export {
getOwnedPaidPolicies,
canSendInvoiceFromWorkspace,
canSendInvoice,
hasWorkspaceWithInvoices,
hasDependentTags,
getXeroTenants,
findCurrentXeroOrganization,
Expand Down
6 changes: 6 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8408,6 +8408,11 @@ function isExpenseReportWithoutParentAccess(report: OnyxEntry<Report>) {
return isExpenseReport(report) && report?.hasParentAccess === false;
}

function hasInvoiceReports() {
const allReports = Object.values(ReportConnection.getAllReports() ?? {});
return allReports.some((report) => isInvoiceReport(report));
}

export {
addDomainToShortMention,
completeShortMention,
Expand Down Expand Up @@ -8733,6 +8738,7 @@ export {
shouldShowViolations,
getAllReportErrors,
getAllReportActionsErrorsAndReportActionThatRequiresAttention,
hasInvoiceReports,
};

export type {
Expand Down
29 changes: 17 additions & 12 deletions src/pages/Search/SearchTypeMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand All @@ -89,25 +91,28 @@ 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,
getRoute: (policyID?: string) => {
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),
Expand Down

0 comments on commit 45a19bf

Please sign in to comment.