@@ -1205,25 +1205,44 @@ function createTypeMenuSections(session: OnyxTypes.Session | undefined, policies
12051205 // Begin adding conditional sections, based on the policies the user has access to
12061206 const showSubmitSuggestion = Object . values ( policies ) . filter ( ( p ) => isPaidGroupPolicy ( p ) ) . length > 0 ;
12071207
1208- const showApproveSuggestion =
1209- Object . values ( policies ) . filter < OnyxTypes . Policy > ( ( policy ) : policy is OnyxTypes . Policy => {
1210- if ( ! policy || ! email || ! isPaidGroupPolicy ( policy ) ) {
1211- return false ;
1212- }
1208+ const showPaySuggestion = Object . values ( policies ) . some ( ( policy ) : policy is OnyxTypes . Policy => {
1209+ if ( ! policy || ! isPaidGroupPolicy ( policy ) ) {
1210+ return false ;
1211+ }
12131212
1214- const isPolicyApprover = policy . approver === email ;
1215- const isSubmittedTo = Object . values ( policy . employeeList ?? { } ) . some ( ( employee ) => {
1216- return employee . submitsTo === email || employee . forwardsTo === email ;
1217- } ) ;
1213+ const reimburser = policy . reimburser ;
1214+ const isReimburser = reimburser === email ;
1215+ const isAdmin = policy . role === CONST . POLICY . ROLE . ADMIN ;
1216+
1217+ if ( policy . reimbursementChoice === CONST . POLICY . REIMBURSEMENT_CHOICES . REIMBURSEMENT_YES ) {
1218+ return reimburser ? isReimburser : isAdmin ;
1219+ }
1220+
1221+ if ( policy . reimbursementChoice === CONST . POLICY . REIMBURSEMENT_CHOICES . REIMBURSEMENT_MANUAL ) {
1222+ return isAdmin ;
1223+ }
1224+
1225+ return false ;
1226+ } ) ;
12181227
1219- return isPolicyApprover || isSubmittedTo ;
1220- } ) . length > 0 ;
1228+ const showApproveSuggestion = Object . values ( policies ) . some ( ( policy ) : policy is OnyxTypes . Policy => {
1229+ if ( ! policy || ! email || ! isPaidGroupPolicy ( policy ) ) {
1230+ return false ;
1231+ }
1232+
1233+ const isPolicyApprover = policy . approver === email ;
1234+ const isSubmittedTo = Object . values ( policy . employeeList ?? { } ) . some ( ( employee ) => {
1235+ return employee . submitsTo === email || employee . forwardsTo === email ;
1236+ } ) ;
1237+
1238+ return isPolicyApprover || isSubmittedTo ;
1239+ } ) ;
12211240
12221241 // TODO: This option will be enabled soon (removing the && false). We are waiting on changes to support this
12231242 // feature fully, but lets keep the code here for simplicity
12241243 // https://github.com/Expensify/Expensify/issues/505933
12251244 const showExportSuggestion =
1226- Object . values ( policies ) . filter < OnyxTypes . Policy > ( ( policy ) : policy is OnyxTypes . Policy => {
1245+ Object . values ( policies ) . some ( ( policy ) : policy is OnyxTypes . Policy => {
12271246 if ( ! policy || ! email ) {
12281247 return false ;
12291248 }
@@ -1235,9 +1254,13 @@ function createTypeMenuSections(session: OnyxTypes.Session | undefined, policies
12351254 const isXeroExporter = policy . connections ?. xero ?. config ?. export ?. exporter === email ;
12361255
12371256 return isIntacctExporter || isNetSuiteExporter || isQuickbooksDesktopExporter || isQuickbooksOnlineExporter || isXeroExporter ;
1238- } ) . length > 0 && false ;
1257+ } ) && false ;
12391258
1240- if ( session ) {
1259+ // We suggest specific filters for users based on their access in specific policies. Show the todo section
1260+ // only if any of these items are available
1261+ const showTodoSection = showSubmitSuggestion || showApproveSuggestion || showPaySuggestion || showExportSuggestion ;
1262+
1263+ if ( showTodoSection && session ) {
12411264 const section : SearchTypeMenuSection = {
12421265 translationPath : 'common.todo' ,
12431266 menuItems : [ ] ,
@@ -1320,26 +1343,28 @@ function createTypeMenuSections(session: OnyxTypes.Session | undefined, policies
13201343 } ) ;
13211344 }
13221345
1323- // Always show pay, since any user can pay p2p requests
1324- section . menuItems . push ( {
1325- translationPath : 'search.bulkActions.pay' ,
1326- type : CONST . SEARCH . DATA_TYPES . EXPENSE ,
1327- icon : Expensicons . MoneyBag ,
1328- emptyState : {
1329- headerMedia : DotLottieAnimations . Fireworks ,
1330- title : 'search.searchResults.emptyPayResults.title' ,
1331- subtitle : 'search.searchResults.emptyPayResults.subtitle' ,
1332- } ,
1333- getSearchQuery : ( ) => {
1334- const queryString = buildQueryStringFromFilterFormValues ( {
1335- type : CONST . SEARCH . DATA_TYPES . EXPENSE ,
1336- groupBy : CONST . SEARCH . GROUP_BY . REPORTS ,
1337- action : CONST . SEARCH . ACTION . PAY ,
1338- payer : session . accountID ?. toString ( ) ,
1339- } ) ;
1340- return queryString ;
1341- } ,
1342- } ) ;
1346+ if ( showPaySuggestion ) {
1347+ section . menuItems . push ( {
1348+ translationPath : 'search.bulkActions.pay' ,
1349+ type : CONST . SEARCH . DATA_TYPES . EXPENSE ,
1350+ icon : Expensicons . MoneyBag ,
1351+ emptyState : {
1352+ headerMedia : DotLottieAnimations . Fireworks ,
1353+ title : 'search.searchResults.emptyPayResults.title' ,
1354+ subtitle : 'search.searchResults.emptyPayResults.subtitle' ,
1355+ } ,
1356+ getSearchQuery : ( ) => {
1357+ const queryString = buildQueryStringFromFilterFormValues ( {
1358+ type : CONST . SEARCH . DATA_TYPES . EXPENSE ,
1359+ groupBy : CONST . SEARCH . GROUP_BY . REPORTS ,
1360+ action : CONST . SEARCH . ACTION . PAY ,
1361+ reimbursable : CONST . SEARCH . BOOLEAN . YES ,
1362+ payer : session . accountID ?. toString ( ) ,
1363+ } ) ;
1364+ return queryString ;
1365+ } ,
1366+ } ) ;
1367+ }
13431368
13441369 if ( showExportSuggestion ) {
13451370 section . menuItems . push ( {
0 commit comments