From 8dae3a0e24e7c4576654dd0d3a7841cb0cf47114 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Wed, 1 Nov 2023 04:13:12 +0300 Subject: [PATCH 1/3] fix: optimistically adding the new assignee's account id to a report's array of participant account ids. Only if it is not present. --- src/libs/actions/Task.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 76396b1f31b8..36311ee95ce3 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -479,6 +479,11 @@ function editTaskAssigneeAndNavigate(report, ownerAccountID, assigneeEmail, assi // If we make a change to the assignee, we want to add a comment to the assignee's chat // Check if the assignee actually changed if (assigneeAccountID && assigneeAccountID !== report.managerID && assigneeAccountID !== ownerAccountID && assigneeChatReport) { + const participants = lodashGet(report, 'participantAccountIDs', []); + if (!participants.includes(assigneeAccountID)) { + optimisticData[1].value.participantAccountIDs = [...participants, assigneeAccountID]; + } + assigneeChatReportOnyxData = ReportUtils.getTaskAssigneeChatOnyxData( currentUserAccountID, assigneeEmail, From a63f39d967035d93aa216ff5991ca8958fc95f23 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Wed, 1 Nov 2023 05:39:41 +0300 Subject: [PATCH 2/3] refactor: removing extra tab for prettier code --- src/libs/actions/Task.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 36311ee95ce3..21bf8a2f2c17 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -483,7 +483,7 @@ function editTaskAssigneeAndNavigate(report, ownerAccountID, assigneeEmail, assi if (!participants.includes(assigneeAccountID)) { optimisticData[1].value.participantAccountIDs = [...participants, assigneeAccountID]; } - + assigneeChatReportOnyxData = ReportUtils.getTaskAssigneeChatOnyxData( currentUserAccountID, assigneeEmail, From 60988f817e060f2a63559dfd5d054515664651c0 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Wed, 1 Nov 2023 16:45:02 +0300 Subject: [PATCH 3/3] refactor: applying suggestion to make code look cleaner --- src/libs/actions/Task.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 21bf8a2f2c17..551b04a3a85b 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -436,6 +436,14 @@ function editTaskAssigneeAndNavigate(report, ownerAccountID, assigneeEmail, assi let assigneeChatReportOnyxData; const assigneeChatReportID = assigneeChatReport ? assigneeChatReport.reportID : 0; + const optimisticReport = { + reportName, + managerID: assigneeAccountID || report.managerID, + managerEmail: assigneeEmail || report.managerEmail, + pendingFields: { + ...(assigneeAccountID && {managerID: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}), + }, + }; const optimisticData = [ { @@ -446,14 +454,7 @@ function editTaskAssigneeAndNavigate(report, ownerAccountID, assigneeEmail, assi { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, - value: { - reportName, - managerID: assigneeAccountID || report.managerID, - managerEmail: assigneeEmail || report.managerEmail, - pendingFields: { - ...(assigneeAccountID && {managerID: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}), - }, - }, + value: optimisticReport, }, ]; const successData = [ @@ -481,7 +482,7 @@ function editTaskAssigneeAndNavigate(report, ownerAccountID, assigneeEmail, assi if (assigneeAccountID && assigneeAccountID !== report.managerID && assigneeAccountID !== ownerAccountID && assigneeChatReport) { const participants = lodashGet(report, 'participantAccountIDs', []); if (!participants.includes(assigneeAccountID)) { - optimisticData[1].value.participantAccountIDs = [...participants, assigneeAccountID]; + optimisticReport.participantAccountIDs = [...participants, assigneeAccountID]; } assigneeChatReportOnyxData = ReportUtils.getTaskAssigneeChatOnyxData(