From ddd452f23225c7f3409c39a9f7c2fd14145f7f89 Mon Sep 17 00:00:00 2001 From: tienifr Date: Thu, 21 Dec 2023 15:38:48 +0700 Subject: [PATCH 1/5] fix: Green dot does not appear in LHN when the request is created in workspace chat --- src/libs/actions/IOU.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 802f0f00fffd..4653ca586039 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -302,7 +302,10 @@ function buildOnyxDataForMoneyRequest( optimisticPolicyRecentlyUsedTags, isNewChatReport, isNewIOUReport, + policyID, ) { + const isPolicyAdmin = ReportUtils.getPolicy(policyID).role === CONST.POLICY.ROLE.ADMIN; + const optimisticData = [ { // Use SET for new reports because it doesn't exist yet, is faster and we need the data to be available when we navigate to the chat page @@ -313,6 +316,7 @@ function buildOnyxDataForMoneyRequest( lastReadTime: DateUtils.getDBTime(), lastMessageTranslationKey: '', iouReportID: iouReport.reportID, + ...(isPolicyAdmin ? {hasOutstandingChildRequest: true} : {}), ...(isNewChatReport ? {pendingFields: {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}} : {}), }, }, @@ -459,6 +463,7 @@ function buildOnyxDataForMoneyRequest( iouReportID: chatReport.iouReportID, lastReadTime: chatReport.lastReadTime, pendingFields: null, + ...(isPolicyAdmin ? {hasOutstandingChildRequest: chatReport.hasOutstandingChildRequest} : {}), ...(isNewChatReport ? { errorFields: { @@ -752,6 +757,7 @@ function getMoneyRequestInformation( optimisticPolicyRecentlyUsedTags, isNewChatReport, isNewIOUReport, + participant.policyID, ); return { @@ -1430,6 +1436,7 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco optimisticPolicyRecentlyUsedTags, isNewOneOnOneChatReport, shouldCreateNewOneOnOneIOUReport, + participant.policyID, ); const individualSplit = { @@ -1955,6 +1962,7 @@ function completeSplitBill(chatReportID, reportAction, updatedTransaction, sessi {}, isNewOneOnOneChatReport, shouldCreateNewOneOnOneIOUReport, + participant.policyID, ); splits.push({ From 1aaf1689389b7ea515a59ab405ff41545ea8ff5f Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 5 Jan 2024 17:12:22 +0700 Subject: [PATCH 2/5] add js docs --- src/libs/actions/IOU.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index a5e6ab492bdc..efd7ec594cc2 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -322,6 +322,7 @@ function getReceiptError(receipt, filename, isScanRequest = true) { * @param {Array} optimisticPolicyRecentlyUsedTags * @param {boolean} isNewChatReport * @param {boolean} isNewIOUReport + * @param {String} policyID * @param {Object} policy - May be undefined, an empty object, or an object matching the Policy type (src/types/onyx/Policy.ts) * @param {Array} policyTags * @param {Array} policyCategories From a1f468ca1176b27202d461a9c83f7ae97c92948a Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 17 Jan 2024 12:26:33 +0700 Subject: [PATCH 3/5] fix hasOutstandingChildRequest --- src/libs/actions/IOU.js | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 06adaab3c28f..93fd4d5827ad 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -311,6 +311,27 @@ function getReceiptError(receipt, filename, isScanRequest = true) { : ErrorUtils.getMicroSecondOnyxErrorObject({error: CONST.IOU.RECEIPT_ERROR, source: receipt.source, filename}); } +/** + * @param {Object} [policy] + * @param {Boolean} needsToBeManuallySubmitted + * @returns {Object} + */ +function getOutstandingChildRequest(policy, needsToBeManuallySubmitted) { + if (!needsToBeManuallySubmitted) { + return { + hasOutstandingChildRequest: false, + }; + } + + if (PolicyUtils.isPolicyAdmin(policy)) { + return { + hasOutstandingChildRequest: true, + }; + } + + return {}; +} + /** * Builds the Onyx data for a money request. * @@ -329,7 +350,7 @@ function getReceiptError(receipt, filename, isScanRequest = true) { * @param {Object} policy - May be undefined, an empty object, or an object matching the Policy type (src/types/onyx/Policy.ts) * @param {Array} policyTags * @param {Array} policyCategories - * @param {Boolean} hasOutstandingChildRequest + * @param {Boolean} needsToBeManuallySubmitted * @returns {Array} - An array containing the optimistic data, success data, and failure data. */ function buildOnyxDataForMoneyRequest( @@ -348,11 +369,10 @@ function buildOnyxDataForMoneyRequest( policy, policyTags, policyCategories, - hasOutstandingChildRequest = false, + needsToBeManuallySubmitted = true, ) { - const isPolicyAdmin = PolicyUtils.isPolicyAdmin(policy); - const isScanRequest = TransactionUtils.isScanRequest(transaction); + const hasOutstandingChildRequest = getOutstandingChildRequest(needsToBeManuallySubmitted, policy); const optimisticData = [ { // Use SET for new reports because it doesn't exist yet, is faster and we need the data to be available when we navigate to the chat page @@ -363,7 +383,6 @@ function buildOnyxDataForMoneyRequest( lastReadTime: DateUtils.getDBTime(), lastMessageTranslationKey: '', iouReportID: iouReport.reportID, - ...(isPolicyAdmin ? {hasOutstandingChildRequest: true} : {}), hasOutstandingChildRequest, ...(isNewChatReport ? {pendingFields: {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}} : {}), }, @@ -509,7 +528,7 @@ function buildOnyxDataForMoneyRequest( iouReportID: chatReport.iouReportID, lastReadTime: chatReport.lastReadTime, pendingFields: null, - ...(isPolicyAdmin ? {hasOutstandingChildRequest: chatReport.hasOutstandingChildRequest} : {}), + hasOutstandingChildRequest: chatReport.hasOutstandingChildRequest, ...(isNewChatReport ? { errorFields: { @@ -691,7 +710,7 @@ function getMoneyRequestInformation( let iouReport = isNewIOUReport ? null : allReports[`${ONYXKEYS.COLLECTION.REPORT}${chatReport.iouReportID}`]; // Check if the Scheduled Submit is enabled in case of expense report - let needsToBeManuallySubmitted = false; + let needsToBeManuallySubmitted = true; let isFromPaidPolicy = false; if (isPolicyExpenseChat) { isFromPaidPolicy = PolicyUtils.isPaidGroupPolicy(policy); @@ -810,10 +829,6 @@ function getMoneyRequestInformation( } : undefined; - // The policy expense chat should have the GBR only when its a paid policy and the scheduled submit is turned off - // so the employee has to submit to their manager manually. - const hasOutstandingChildRequest = isPolicyExpenseChat && needsToBeManuallySubmitted; - // STEP 5: Build Onyx Data const [optimisticData, successData, failureData] = buildOnyxDataForMoneyRequest( chatReport, @@ -831,7 +846,7 @@ function getMoneyRequestInformation( policy, policyTags, policyCategories, - hasOutstandingChildRequest, + needsToBeManuallySubmitted, ); return { From 26768e3d6a6bf113e26d0c230e23432fa4e6caf9 Mon Sep 17 00:00:00 2001 From: tienifr Date: Thu, 25 Jan 2024 16:20:31 +0700 Subject: [PATCH 4/5] add comment --- src/libs/actions/IOU.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 38fb43a3ebe6..d26316b04e66 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -312,6 +312,7 @@ function getReceiptError(receipt, filename, isScanRequest = true) { } /** + * Return the object to update hasOutstandingChildRequest * @param {Object} [policy] * @param {Boolean} needsToBeManuallySubmitted * @returns {Object} @@ -329,6 +330,7 @@ function getOutstandingChildRequest(policy, needsToBeManuallySubmitted) { }; } + // We don't need to update hasOutstandingChildRequest in this case return {}; } @@ -372,7 +374,7 @@ function buildOnyxDataForMoneyRequest( needsToBeManuallySubmitted = true, ) { const isScanRequest = TransactionUtils.isScanRequest(transaction); - const hasOutstandingChildRequest = getOutstandingChildRequest(needsToBeManuallySubmitted, policy); + const outstandingChildRequest = getOutstandingChildRequest(needsToBeManuallySubmitted, policy); const optimisticData = [ { // Use SET for new reports because it doesn't exist yet, is faster and we need the data to be available when we navigate to the chat page @@ -383,7 +385,7 @@ function buildOnyxDataForMoneyRequest( lastReadTime: DateUtils.getDBTime(), lastMessageTranslationKey: '', iouReportID: iouReport.reportID, - hasOutstandingChildRequest, + ...outstandingChildRequest, ...(isNewChatReport ? {pendingFields: {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}} : {}), }, }, From b118e62ff3284ab179c81732a57e17f9884c9a56 Mon Sep 17 00:00:00 2001 From: tienifr Date: Thu, 25 Jan 2024 18:13:05 +0700 Subject: [PATCH 5/5] lint fix --- src/libs/actions/IOU.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index d26316b04e66..e6aa9398c05b 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -312,7 +312,7 @@ function getReceiptError(receipt, filename, isScanRequest = true) { } /** - * Return the object to update hasOutstandingChildRequest + * Return the object to update hasOutstandingChildRequest * @param {Object} [policy] * @param {Boolean} needsToBeManuallySubmitted * @returns {Object}