11import type { OnyxCollection } from 'react-native-onyx' ;
22import type { ValueOf } from 'type-fest' ;
33import CONST from '@src/CONST' ;
4- import type { Policy , Report , Transaction , TransactionViolation } from '@src/types/onyx' ;
4+ import type { Policy , Report , ReportNameValuePairs , Transaction , TransactionViolation } from '@src/types/onyx' ;
55import { isApprover as isApproverUtils } from './actions/Policy/Member' ;
66import { getCurrentUserAccountID } from './actions/Report' ;
77import {
@@ -15,9 +15,9 @@ import {
1515} from './PolicyUtils' ;
1616import { getAllReportActions , getOneTransactionThreadReportID } from './ReportActionsUtils' ;
1717import {
18+ canAddTransaction as canAddTransactionUtil ,
1819 getMoneyRequestSpendBreakdown ,
1920 getParentReport ,
20- getReportNameValuePairs ,
2121 isArchivedReport ,
2222 isClosedReport as isClosedReportUtils ,
2323 isCurrentUserSubmitter ,
@@ -42,6 +42,14 @@ import {
4242 shouldShowBrokenConnectionViolation as shouldShowBrokenConnectionViolationTransactionUtils ,
4343} from './TransactionUtils' ;
4444
45+ function isAddExpenseAction ( report : Report , reportTransactions : Transaction [ ] ) {
46+ const isExpenseReport = isExpenseReportUtils ( report ) ;
47+ const isReportSubmitter = isCurrentUserSubmitter ( report . reportID ) ;
48+ const canAddTransaction = canAddTransactionUtil ( report ) ;
49+
50+ return isExpenseReport && canAddTransaction && isReportSubmitter && reportTransactions . length === 0 ;
51+ }
52+
4553function isSubmitAction ( report : Report , reportTransactions : Transaction [ ] , policy ?: Policy ) {
4654 const isExpenseReport = isExpenseReportUtils ( report ) ;
4755 const isReportSubmitter = isCurrentUserSubmitter ( report . reportID ) ;
@@ -92,7 +100,7 @@ function isApproveAction(report: Report, reportTransactions: Transaction[], poli
92100 return false ;
93101}
94102
95- function isPayAction ( report : Report , policy ?: Policy ) {
103+ function isPayAction ( report : Report , policy ?: Policy , reportNameValuePairs ?: ReportNameValuePairs ) {
96104 const isExpenseReport = isExpenseReportUtils ( report ) ;
97105 const isReportPayer = isPayer ( getSession ( ) , report , false , policy ) ;
98106 const arePaymentsEnabled = arePaymentsEnabledUtils ( policy ) ;
@@ -106,7 +114,6 @@ function isPayAction(report: Report, policy?: Policy) {
106114 const isReportFinished = ( isReportApproved && ! report . isWaitingOnBankAccount ) || isSubmittedWithoutApprovalsEnabled || isReportClosed ;
107115 const { reimbursableSpend} = getMoneyRequestSpendBreakdown ( report ) ;
108116
109- const reportNameValuePairs = getReportNameValuePairs ( report . chatReportID ) ;
110117 const isChatReportArchived = isArchivedReport ( reportNameValuePairs ) ;
111118
112119 if ( isChatReportArchived ) {
@@ -248,7 +255,12 @@ function getReportPrimaryAction(
248255 reportTransactions : Transaction [ ] ,
249256 violations : OnyxCollection < TransactionViolation [ ] > ,
250257 policy ?: Policy ,
258+ reportNameValuePairs ?: ReportNameValuePairs ,
251259) : ValueOf < typeof CONST . REPORT . PRIMARY_ACTIONS > | '' {
260+ if ( isAddExpenseAction ( report , reportTransactions ) ) {
261+ return CONST . REPORT . PRIMARY_ACTIONS . ADD_EXPENSE ;
262+ }
263+
252264 if ( isReviewDuplicatesAction ( report , reportTransactions , policy ) ) {
253265 return CONST . REPORT . PRIMARY_ACTIONS . REVIEW_DUPLICATES ;
254266 }
@@ -265,7 +277,7 @@ function getReportPrimaryAction(
265277 return CONST . REPORT . PRIMARY_ACTIONS . APPROVE ;
266278 }
267279
268- if ( isPayAction ( report , policy ) ) {
280+ if ( isPayAction ( report , policy , reportNameValuePairs ) ) {
269281 return CONST . REPORT . PRIMARY_ACTIONS . PAY ;
270282 }
271283
0 commit comments