@@ -98,15 +98,7 @@ import isSearchTopmostFullScreenRoute from './Navigation/helpers/isSearchTopmost
9898import Navigation from './Navigation/Navigation' ;
9999import Parser from './Parser' ;
100100import { getDisplayNameOrDefault } from './PersonalDetailsUtils' ;
101- import {
102- arePaymentsEnabled ,
103- canSendInvoice ,
104- getCommaSeparatedTagNameWithSanitizedColons ,
105- getGroupPaidPoliciesWithExpenseChatEnabled ,
106- getSubmitToAccountID ,
107- isPaidGroupPolicy ,
108- isPolicyPayer ,
109- } from './PolicyUtils' ;
101+ import { arePaymentsEnabled , canSendInvoice , getCommaSeparatedTagNameWithSanitizedColons , getSubmitToAccountID , isPaidGroupPolicy , isPolicyPayer } from './PolicyUtils' ;
110102import {
111103 getIOUActionForReportID ,
112104 getOriginalMessage ,
@@ -356,6 +348,13 @@ function formatBadgeText(count: number): string {
356348 return count > CONST . SEARCH . TODO_BADGE_MAX_COUNT ? `${ CONST . SEARCH . TODO_BADGE_MAX_COUNT } +` : count . toString ( ) ;
357349}
358350
351+ function getItemBadgeText ( itemKey : string , reportCounts : Record < string , number > ) : string | undefined {
352+ if ( itemKey in reportCounts ) {
353+ return formatBadgeText ( reportCounts [ itemKey ] ) ;
354+ }
355+ return undefined ;
356+ }
357+
359358function getExpenseStatusOptions ( translate : LocalizedTranslate ) : Array < MultiSelectItem < SingularSearchStatus > > {
360359 return [
361360 { text : translate ( 'common.unreported' ) , value : CONST . SEARCH . STATUS . EXPENSE . UNREPORTED } ,
@@ -852,7 +851,7 @@ function getSuggestedSearchesVisibility(
852851 cardFeedsByPolicy : Record < string , CardFeedForDisplay [ ] > ,
853852 policies : OnyxCollection < OnyxTypes . Policy > ,
854853 defaultExpensifyCard : CardFeedForDisplay | undefined ,
855- ) : Record < ValueOf < typeof CONST . SEARCH . SEARCH_KEYS > , boolean > {
854+ ) : { visibility : Record < ValueOf < typeof CONST . SEARCH . SEARCH_KEYS > , boolean > ; hasGroupPoliciesWithExpenseChat : boolean } {
856855 let shouldShowSubmitSuggestion = false ;
857856 let shouldShowPaySuggestion = false ;
858857 let shouldShowApproveSuggestion = false ;
@@ -864,6 +863,7 @@ function getSuggestedSearchesVisibility(
864863 let shouldShowTopSpendersSuggestion = false ;
865864 let shouldShowTopCategoriesSuggestion = false ;
866865 let shouldShowTopMerchantsSuggestion = false ;
866+ let hasGroupPoliciesWithExpenseChat = false ;
867867 let shouldShowSpendOverTimeSuggestion = false ;
868868
869869 const hasCardFeed = Object . values ( cardFeedsByPolicy ?? { } ) . some ( ( feeds ) => feeds . length > 0 ) ;
@@ -916,6 +916,12 @@ function getSuggestedSearchesVisibility(
916916 shouldShowTopSpendersSuggestion ||= isEligibleForTopSpendersSuggestion ;
917917 shouldShowTopCategoriesSuggestion ||= isEligibleForTopCategoriesSuggestion ;
918918 shouldShowTopMerchantsSuggestion ||= isEligibleForTopMerchantsSuggestion ;
919+ hasGroupPoliciesWithExpenseChat ||=
920+ isPaidPolicy &&
921+ ! ! policy . isPolicyExpenseChatEnabled &&
922+ ! policy . isJoinRequestPending &&
923+ ( policy . pendingAction !== CONST . RED_BRICK_ROAD_PENDING_ACTION . DELETE || Object . keys ( policy . errors ?? { } ) . length > 0 ) &&
924+ ! ! policy . role ;
919925 shouldShowSpendOverTimeSuggestion ||= isEligibleForSpendOverTimeSuggestion ;
920926
921927 // We don't need to check the rest of the policies if we already determined that all suggestions should be displayed
@@ -930,26 +936,30 @@ function getSuggestedSearchesVisibility(
930936 shouldShowReconciliationSuggestion &&
931937 shouldShowTopSpendersSuggestion &&
932938 shouldShowTopCategoriesSuggestion &&
933- shouldShowTopMerchantsSuggestion
939+ shouldShowTopMerchantsSuggestion &&
940+ hasGroupPoliciesWithExpenseChat
934941 ) ;
935942 } ) ;
936943
937944 return {
938- [ CONST . SEARCH . SEARCH_KEYS . EXPENSES ] : true ,
939- [ CONST . SEARCH . SEARCH_KEYS . REPORTS ] : true ,
940- [ CONST . SEARCH . SEARCH_KEYS . CHATS ] : true ,
941- [ CONST . SEARCH . SEARCH_KEYS . SUBMIT ] : shouldShowSubmitSuggestion ,
942- [ CONST . SEARCH . SEARCH_KEYS . PAY ] : shouldShowPaySuggestion ,
943- [ CONST . SEARCH . SEARCH_KEYS . APPROVE ] : shouldShowApproveSuggestion ,
944- [ CONST . SEARCH . SEARCH_KEYS . EXPORT ] : shouldShowExportSuggestion ,
945- [ CONST . SEARCH . SEARCH_KEYS . STATEMENTS ] : shouldShowStatementsSuggestion ,
946- [ CONST . SEARCH . SEARCH_KEYS . UNAPPROVED_CASH ] : shouldShowUnapprovedCashSuggestion ,
947- [ CONST . SEARCH . SEARCH_KEYS . UNAPPROVED_CARD ] : shouldShowUnapprovedCardSuggestion ,
948- [ CONST . SEARCH . SEARCH_KEYS . RECONCILIATION ] : shouldShowReconciliationSuggestion ,
949- [ CONST . SEARCH . SEARCH_KEYS . TOP_SPENDERS ] : shouldShowTopSpendersSuggestion ,
950- [ CONST . SEARCH . SEARCH_KEYS . TOP_CATEGORIES ] : shouldShowTopCategoriesSuggestion ,
951- [ CONST . SEARCH . SEARCH_KEYS . TOP_MERCHANTS ] : shouldShowTopMerchantsSuggestion ,
952- [ CONST . SEARCH . SEARCH_KEYS . SPEND_OVER_TIME ] : shouldShowSpendOverTimeSuggestion ,
945+ visibility : {
946+ [ CONST . SEARCH . SEARCH_KEYS . EXPENSES ] : true ,
947+ [ CONST . SEARCH . SEARCH_KEYS . REPORTS ] : true ,
948+ [ CONST . SEARCH . SEARCH_KEYS . CHATS ] : true ,
949+ [ CONST . SEARCH . SEARCH_KEYS . SUBMIT ] : shouldShowSubmitSuggestion ,
950+ [ CONST . SEARCH . SEARCH_KEYS . PAY ] : shouldShowPaySuggestion ,
951+ [ CONST . SEARCH . SEARCH_KEYS . APPROVE ] : shouldShowApproveSuggestion ,
952+ [ CONST . SEARCH . SEARCH_KEYS . EXPORT ] : shouldShowExportSuggestion ,
953+ [ CONST . SEARCH . SEARCH_KEYS . STATEMENTS ] : shouldShowStatementsSuggestion ,
954+ [ CONST . SEARCH . SEARCH_KEYS . UNAPPROVED_CASH ] : shouldShowUnapprovedCashSuggestion ,
955+ [ CONST . SEARCH . SEARCH_KEYS . UNAPPROVED_CARD ] : shouldShowUnapprovedCardSuggestion ,
956+ [ CONST . SEARCH . SEARCH_KEYS . RECONCILIATION ] : shouldShowReconciliationSuggestion ,
957+ [ CONST . SEARCH . SEARCH_KEYS . TOP_SPENDERS ] : shouldShowTopSpendersSuggestion ,
958+ [ CONST . SEARCH . SEARCH_KEYS . TOP_CATEGORIES ] : shouldShowTopCategoriesSuggestion ,
959+ [ CONST . SEARCH . SEARCH_KEYS . TOP_MERCHANTS ] : shouldShowTopMerchantsSuggestion ,
960+ [ CONST . SEARCH . SEARCH_KEYS . SPEND_OVER_TIME ] : shouldShowSpendOverTimeSuggestion ,
961+ } ,
962+ hasGroupPoliciesWithExpenseChat,
953963 } ;
954964}
955965
@@ -3417,7 +3427,6 @@ function isTodoSearch(hash: number, suggestedSearches: Record<string, SearchType
34173427 return ! ! matchedSearchKey && TODO_KEYS . includes ( matchedSearchKey ) ;
34183428}
34193429
3420- // eslint-disable-next-line @typescript-eslint/max-params
34213430function createTypeMenuSections (
34223431 icons : Record < 'Document' | 'Send' | 'ThumbsUp' , IconAsset > ,
34233432 currentUserEmail : string | undefined ,
@@ -3429,13 +3438,11 @@ function createTypeMenuSections(
34293438 isOffline : boolean ,
34303439 defaultExpensifyCard : CardFeedForDisplay | undefined ,
34313440 shouldRedirectToExpensifyClassic : boolean ,
3432- draftTransactions : OnyxCollection < OnyxTypes . Transaction > ,
3433- reportCounts : { [ CONST . SEARCH . SEARCH_KEYS . SUBMIT ] : number ; [ CONST . SEARCH . SEARCH_KEYS . APPROVE ] : number ; [ CONST . SEARCH . SEARCH_KEYS . PAY ] : number ; [ CONST . SEARCH . SEARCH_KEYS . EXPORT ] : number } ,
34343441) : SearchTypeMenuSection [ ] {
34353442 const typeMenuSections : SearchTypeMenuSection [ ] = [ ] ;
34363443
34373444 const suggestedSearches = getSuggestedSearches ( currentUserAccountID , defaultCardFeed ?. id , icons ) ;
3438- const suggestedSearchesVisibility = getSuggestedSearchesVisibility ( currentUserEmail , cardFeedsByPolicy , policies , defaultExpensifyCard ) ;
3445+ const { visibility : suggestedSearchesVisibility , hasGroupPoliciesWithExpenseChat } = getSuggestedSearchesVisibility ( currentUserEmail , cardFeedsByPolicy , policies , defaultExpensifyCard ) ;
34393446
34403447 // Todo section
34413448 {
@@ -3445,39 +3452,35 @@ function createTypeMenuSections(
34453452 } ;
34463453
34473454 if ( suggestedSearchesVisibility [ CONST . SEARCH . SEARCH_KEYS . SUBMIT ] ) {
3448- const groupPoliciesWithChatEnabled = getGroupPaidPoliciesWithExpenseChatEnabled ( policies ) ;
34493455 todoSection . menuItems . push ( {
34503456 ...suggestedSearches [ CONST . SEARCH . SEARCH_KEYS . SUBMIT ] ,
3451- badgeText : formatBadgeText ( reportCounts [ CONST . SEARCH . SEARCH_KEYS . SUBMIT ] ) ,
34523457 emptyState : {
34533458 title : 'search.searchResults.emptySubmitResults.title' ,
34543459 subtitle : 'search.searchResults.emptySubmitResults.subtitle' ,
3455- buttons :
3456- groupPoliciesWithChatEnabled . length > 0
3457- ? [
3458- {
3459- success : true ,
3460- buttonText : 'report.newReport.createExpense' ,
3461- buttonAction : ( ) => {
3462- interceptAnonymousUser ( ( ) => {
3463- if ( shouldRedirectToExpensifyClassic ) {
3464- setIsOpenConfirmNavigateExpensifyClassicModalOpen ( true ) ;
3465- return ;
3466- }
3467-
3468- startMoneyRequest ( CONST . IOU . TYPE . CREATE , generateReportID ( ) , CONST . IOU . REQUEST_TYPE . SCAN , false , undefined , draftTransactions ) ;
3469- } ) ;
3470- } ,
3460+ buttons : hasGroupPoliciesWithExpenseChat
3461+ ? [
3462+ {
3463+ success : true ,
3464+ buttonText : 'report.newReport.createExpense' ,
3465+ buttonAction : ( ) => {
3466+ interceptAnonymousUser ( ( ) => {
3467+ if ( shouldRedirectToExpensifyClassic ) {
3468+ setIsOpenConfirmNavigateExpensifyClassicModalOpen ( true ) ;
3469+ return ;
3470+ }
3471+
3472+ startMoneyRequest ( CONST . IOU . TYPE . CREATE , generateReportID ( ) , CONST . IOU . REQUEST_TYPE . SCAN ) ;
3473+ } ) ;
34713474 } ,
3472- ]
3473- : [ ] ,
3475+ } ,
3476+ ]
3477+ : [ ] ,
34743478 } ,
34753479 } ) ;
34763480 }
34773481 if ( suggestedSearchesVisibility [ CONST . SEARCH . SEARCH_KEYS . APPROVE ] ) {
34783482 todoSection . menuItems . push ( {
34793483 ...suggestedSearches [ CONST . SEARCH . SEARCH_KEYS . APPROVE ] ,
3480- badgeText : formatBadgeText ( reportCounts [ CONST . SEARCH . SEARCH_KEYS . APPROVE ] ) ,
34813484 emptyState : {
34823485 title : 'search.searchResults.emptyApproveResults.title' ,
34833486 subtitle : 'search.searchResults.emptyApproveResults.subtitle' ,
@@ -3487,7 +3490,6 @@ function createTypeMenuSections(
34873490 if ( suggestedSearchesVisibility [ CONST . SEARCH . SEARCH_KEYS . PAY ] ) {
34883491 todoSection . menuItems . push ( {
34893492 ...suggestedSearches [ CONST . SEARCH . SEARCH_KEYS . PAY ] ,
3490- badgeText : formatBadgeText ( reportCounts [ CONST . SEARCH . SEARCH_KEYS . PAY ] ) ,
34913493 emptyState : {
34923494 title : 'search.searchResults.emptyPayResults.title' ,
34933495 subtitle : 'search.searchResults.emptyPayResults.subtitle' ,
@@ -3497,7 +3499,6 @@ function createTypeMenuSections(
34973499 if ( suggestedSearchesVisibility [ CONST . SEARCH . SEARCH_KEYS . EXPORT ] ) {
34983500 todoSection . menuItems . push ( {
34993501 ...suggestedSearches [ CONST . SEARCH . SEARCH_KEYS . EXPORT ] ,
3500- badgeText : formatBadgeText ( reportCounts [ CONST . SEARCH . SEARCH_KEYS . EXPORT ] ) ,
35013502 emptyState : {
35023503 title : 'search.searchResults.emptyExportResults.title' ,
35033504 subtitle : 'search.searchResults.emptyExportResults.subtitle' ,
@@ -4389,6 +4390,8 @@ export {
43894390 isTaskListItemType ,
43904391 getActions ,
43914392 createTypeMenuSections ,
4393+ formatBadgeText ,
4394+ getItemBadgeText ,
43924395 createBaseSavedSearchMenuItem ,
43934396 shouldShowEmptyState ,
43944397 compareValues ,
0 commit comments