From 7ea886aef231c114bfe902b6d45de004db8935c5 Mon Sep 17 00:00:00 2001 From: Hayata Suenaga Date: Fri, 15 Mar 2024 16:10:12 -0700 Subject: [PATCH 1/5] chore: fix conditional statement --- src/libs/actions/IOU.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index af5c40836c74..84c7d1b84a31 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -1259,7 +1259,7 @@ function getUpdateMoneyRequestParams( key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.parentReportID}`, value: { hasOutstandingChildRequest: - iouReport && needsToBeManuallySubmitted(iouReport) && updatedMoneyRequestReport.managerID === userAccountID && updatedMoneyRequestReport.total !== 0, + ((iouReport && needsToBeManuallySubmitted(iouReport)) || updatedMoneyRequestReport.managerID === userAccountID) && updatedMoneyRequestReport.total !== 0, }, }, ); @@ -3030,7 +3030,7 @@ function deleteMoneyRequest(transactionID: string, reportAction: OnyxTypes.Repor onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport?.reportID}`, value: { - hasOutstandingChildRequest: iouReport && needsToBeManuallySubmitted(iouReport) && updatedIOUReport?.managerID === userAccountID && updatedIOUReport.total !== 0, + hasOutstandingChildRequest: ((iouReport && needsToBeManuallySubmitted(iouReport)) || updatedIOUReport?.managerID === userAccountID) && updatedIOUReport?.total !== 0, }, }, ); From 51d5b11117af2c59d7743cb0aa986df0d8df6927 Mon Sep 17 00:00:00 2001 From: Hayata Suenaga Date: Sat, 16 Mar 2024 09:59:38 -0700 Subject: [PATCH 2/5] chore: convert to boolean --- src/libs/actions/IOU.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 84c7d1b84a31..c646203c2688 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -1259,7 +1259,7 @@ function getUpdateMoneyRequestParams( key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.parentReportID}`, value: { hasOutstandingChildRequest: - ((iouReport && needsToBeManuallySubmitted(iouReport)) || updatedMoneyRequestReport.managerID === userAccountID) && updatedMoneyRequestReport.total !== 0, + ((!!iouReport && needsToBeManuallySubmitted(iouReport)) || updatedMoneyRequestReport.managerID === userAccountID) && updatedMoneyRequestReport.total !== 0, }, }, ); @@ -3030,7 +3030,7 @@ function deleteMoneyRequest(transactionID: string, reportAction: OnyxTypes.Repor onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport?.reportID}`, value: { - hasOutstandingChildRequest: ((iouReport && needsToBeManuallySubmitted(iouReport)) || updatedIOUReport?.managerID === userAccountID) && updatedIOUReport?.total !== 0, + hasOutstandingChildRequest: ((!!iouReport && needsToBeManuallySubmitted(iouReport)) || updatedIOUReport?.managerID === userAccountID) && updatedIOUReport?.total !== 0, }, }, ); From af7f81ea347afc994d04e433bac910883f20bf88 Mon Sep 17 00:00:00 2001 From: Hayata Suenaga Date: Sat, 16 Mar 2024 10:03:21 -0700 Subject: [PATCH 3/5] chore: extract boolean const --- src/libs/actions/IOU.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index c646203c2688..10e6411d9898 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -1248,6 +1248,8 @@ function getUpdateMoneyRequestParams( } updatedMoneyRequestReport.cachedTotal = CurrencyUtils.convertToDisplayString(updatedMoneyRequestReport.total, transactionDetails?.currency); + const canChatRequireAttention = (!!iouReport && needsToBeManuallySubmitted(iouReport)) || updatedMoneyRequestReport.managerID === userAccountID; + optimisticData.push( { onyxMethod: Onyx.METHOD.MERGE, @@ -1258,8 +1260,7 @@ function getUpdateMoneyRequestParams( onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.parentReportID}`, value: { - hasOutstandingChildRequest: - ((!!iouReport && needsToBeManuallySubmitted(iouReport)) || updatedMoneyRequestReport.managerID === userAccountID) && updatedMoneyRequestReport.total !== 0, + hasOutstandingChildRequest: canChatRequireAttention && updatedMoneyRequestReport.total !== 0, }, }, ); From 1241df5fc58b46dae983568a8cd8276cae0f5dd6 Mon Sep 17 00:00:00 2001 From: Hayata Suenaga Date: Sat, 16 Mar 2024 10:05:18 -0700 Subject: [PATCH 4/5] refactor: extract boolean const --- src/libs/actions/IOU.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 10e6411d9898..a19be8ee9a03 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -3009,6 +3009,8 @@ function deleteMoneyRequest(transactionID: string, reportAction: OnyxTypes.Repor ); } + const canChatRequireAttention = (!!iouReport && needsToBeManuallySubmitted(iouReport)) || updatedIOUReport?.managerID === userAccountID; + optimisticData.push( { onyxMethod: Onyx.METHOD.MERGE, @@ -3031,7 +3033,7 @@ function deleteMoneyRequest(transactionID: string, reportAction: OnyxTypes.Repor onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport?.reportID}`, value: { - hasOutstandingChildRequest: ((!!iouReport && needsToBeManuallySubmitted(iouReport)) || updatedIOUReport?.managerID === userAccountID) && updatedIOUReport?.total !== 0, + hasOutstandingChildRequest: canChatRequireAttention && updatedIOUReport?.total !== 0, }, }, ); From 2bf09541473507b805fea87efa9370279e38b7b2 Mon Sep 17 00:00:00 2001 From: Hayata Suenaga Date: Sat, 16 Mar 2024 10:15:41 -0700 Subject: [PATCH 5/5] chore: move util function to ReportUtils.ts --- src/libs/ReportUtils.ts | 13 +++++++++++++ src/libs/actions/IOU.ts | 20 +++----------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 3e4950bc893b..77fe171f681b 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5314,6 +5314,18 @@ function shouldCreateNewMoneyRequestReport(existingIOUReport: OnyxEntry return !existingIOUReport || hasIOUWaitingOnCurrentUserBankAccount(chatReport) || !canAddOrDeleteTransactions(existingIOUReport); } +function needsToBeManuallySubmitted(iouReport: Report) { + if (isPolicyExpenseChat(iouReport)) { + const policy = getPolicy(iouReport.policyID); + const isFromPaidPolicy = PolicyUtils.isPaidGroupPolicy(policy); + + // If the scheduled submit is turned off on the policy, user needs to manually submit the report which is indicated by GBR in LHN + return isFromPaidPolicy && !policy.harvesting?.enabled; + } + + return true; +} + export { getReportParticipantsTitle, isReportMessageAttachment, @@ -5524,6 +5536,7 @@ export { isJoinRequestInAdminRoom, canAddOrDeleteTransactions, shouldCreateNewMoneyRequestReport, + needsToBeManuallySubmitted, }; export type { diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index a19be8ee9a03..b9e57b17c748 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -402,25 +402,11 @@ function getReceiptError(receipt?: Receipt, filename?: string, isScanRequest = t : ErrorUtils.getMicroSecondOnyxErrorObject({error: CONST.IOU.RECEIPT_ERROR, source: receipt.source?.toString() ?? '', filename: filename ?? ''}); } -function needsToBeManuallySubmitted(iouReport: OnyxTypes.Report) { - const isPolicyExpenseChat = ReportUtils.isExpenseReport(iouReport); - - if (isPolicyExpenseChat) { - const policy = ReportUtils.getPolicy(iouReport.policyID); - const isFromPaidPolicy = PolicyUtils.isPaidGroupPolicy(policy); - - // If the scheduled submit is turned off on the policy, user needs to manually submit the report which is indicated by GBR in LHN - return isFromPaidPolicy && !policy.harvesting?.enabled; - } - - return true; -} - /** * Return the object to update hasOutstandingChildRequest */ function getOutstandingChildRequest(policy: OnyxEntry | EmptyObject, iouReport: OnyxTypes.Report): OutstandingChildRequest { - if (!needsToBeManuallySubmitted(iouReport)) { + if (!ReportUtils.needsToBeManuallySubmitted(iouReport)) { return { hasOutstandingChildRequest: false, }; @@ -1248,7 +1234,7 @@ function getUpdateMoneyRequestParams( } updatedMoneyRequestReport.cachedTotal = CurrencyUtils.convertToDisplayString(updatedMoneyRequestReport.total, transactionDetails?.currency); - const canChatRequireAttention = (!!iouReport && needsToBeManuallySubmitted(iouReport)) || updatedMoneyRequestReport.managerID === userAccountID; + const canChatRequireAttention = (!!iouReport && ReportUtils.needsToBeManuallySubmitted(iouReport)) || updatedMoneyRequestReport.managerID === userAccountID; optimisticData.push( { @@ -3009,7 +2995,7 @@ function deleteMoneyRequest(transactionID: string, reportAction: OnyxTypes.Repor ); } - const canChatRequireAttention = (!!iouReport && needsToBeManuallySubmitted(iouReport)) || updatedIOUReport?.managerID === userAccountID; + const canChatRequireAttention = (!!iouReport && ReportUtils.needsToBeManuallySubmitted(iouReport)) || updatedIOUReport?.managerID === userAccountID; optimisticData.push( {