From 56012ec29bd811730d309da5c314c50249d48990 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 12 Nov 2024 13:53:55 -0700 Subject: [PATCH 1/2] fix condition for approval button --- src/libs/ReportUtils.ts | 4 ++-- src/libs/SearchUIUtils.ts | 2 +- src/types/onyx/SearchResults.ts | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 73721d094ebe..e0c0cf28dcf2 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7983,8 +7983,8 @@ function isReportOwner(report: OnyxInputOrEntry): boolean { return report?.ownerAccountID === currentUserPersonalDetails?.accountID; } -function isAllowedToApproveExpenseReport(report: OnyxEntry, approverAccountID?: number): boolean { - const policy = getPolicy(report?.policyID); +function isAllowedToApproveExpenseReport(report: OnyxEntry, approverAccountID?: number, reportPolicy?: OnyxEntry | SearchPolicy): boolean { + const policy = reportPolicy ?? getPolicy(report?.policyID); const isOwner = (approverAccountID ?? currentUserAccountID) === report?.ownerAccountID; return !(policy?.preventSelfApproval && isOwner); } diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index 29537b9c8368..d431bd1164d6 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -292,7 +292,7 @@ function getAction(data: OnyxTypes.SearchResults['data'], key: string): SearchTr return CONST.SEARCH.ACTION_TYPES.PAY; } - if (IOU.canApproveIOU(report, policy)) { + if (IOU.canApproveIOU(report, policy) && !ReportUtils.isAllowedToApproveExpenseReport(report, undefined, policy)) { return CONST.SEARCH.ACTION_TYPES.APPROVE; } diff --git a/src/types/onyx/SearchResults.ts b/src/types/onyx/SearchResults.ts index 56ae9cc62379..1d7abe7d63cf 100644 --- a/src/types/onyx/SearchResults.ts +++ b/src/types/onyx/SearchResults.ts @@ -222,6 +222,9 @@ type SearchPolicy = { /** The auto reimbursement limit */ limit: number; }; + + /** Whether the self approval or submitting is enabled */ + preventSelfApproval?: boolean; }; /** Model of transaction search result */ From bb0a11523832af3ee47d69a52a8b5d3b0d672e35 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 12 Nov 2024 14:13:56 -0700 Subject: [PATCH 2/2] fix lint --- src/libs/SearchUIUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index d431bd1164d6..3fe5faef7299 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -292,7 +292,7 @@ function getAction(data: OnyxTypes.SearchResults['data'], key: string): SearchTr return CONST.SEARCH.ACTION_TYPES.PAY; } - if (IOU.canApproveIOU(report, policy) && !ReportUtils.isAllowedToApproveExpenseReport(report, undefined, policy)) { + if (IOU.canApproveIOU(report, policy) && ReportUtils.isAllowedToApproveExpenseReport(report, undefined, policy)) { return CONST.SEARCH.ACTION_TYPES.APPROVE; }