From 8620f6302f517e9d6416681ae2a0af65ff51e819 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 6 May 2024 16:01:20 +0700 Subject: [PATCH] change assigneeAccountID to require param --- src/libs/actions/Task.ts | 13 ++++++------- src/pages/home/report/ReportFooter.tsx | 4 +++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/libs/actions/Task.ts b/src/libs/actions/Task.ts index e2eb504dd342..329119d688c9 100644 --- a/src/libs/actions/Task.ts +++ b/src/libs/actions/Task.ts @@ -650,9 +650,8 @@ function setAssigneeChatReport(chatReport: OnyxTypes.Report) { Onyx.merge(ONYXKEYS.TASK, {assigneeChatReport: chatReport}); } -function setNewOptimisticAssignee(assigneeLogin: string, assigneeAccountID: number | undefined = undefined) { - const currentAssigneeAccountID = assigneeAccountID ?? UserUtils.generateAccountID(assigneeLogin); - const report: ReportUtils.OptimisticChatReport = ReportUtils.buildOptimisticChatReport([currentAssigneeAccountID]); +function setNewOptimisticAssignee(assigneeLogin: string, assigneeAccountID: number) { + const report: ReportUtils.OptimisticChatReport = ReportUtils.buildOptimisticChatReport([assigneeAccountID]); // When assigning a task to a new user, by default we share the task in their DM // However, the DM doesn't exist yet - and will be created optimistically once the task is created @@ -662,12 +661,12 @@ function setNewOptimisticAssignee(assigneeLogin: string, assigneeAccountID: numb Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report); const optimisticPersonalDetailsListAction: OnyxTypes.PersonalDetails = { - accountID: currentAssigneeAccountID, - avatar: allPersonalDetails?.[currentAssigneeAccountID]?.avatar ?? UserUtils.getDefaultAvatarURL(currentAssigneeAccountID), - displayName: allPersonalDetails?.[currentAssigneeAccountID]?.displayName ?? assigneeLogin, + accountID: assigneeAccountID, + avatar: allPersonalDetails?.[assigneeAccountID]?.avatar ?? UserUtils.getDefaultAvatarURL(assigneeAccountID), + displayName: allPersonalDetails?.[assigneeAccountID]?.displayName ?? assigneeLogin, login: assigneeLogin, }; - Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, {[currentAssigneeAccountID]: optimisticPersonalDetailsListAction}); + Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, {[assigneeAccountID]: optimisticPersonalDetailsListAction}); return {assignee: optimisticPersonalDetailsListAction, assigneeReport: report}; } diff --git a/src/pages/home/report/ReportFooter.tsx b/src/pages/home/report/ReportFooter.tsx index 2d7c8142f9ac..b128b83f88fc 100644 --- a/src/pages/home/report/ReportFooter.tsx +++ b/src/pages/home/report/ReportFooter.tsx @@ -12,6 +12,7 @@ import useNetwork from '@hooks/useNetwork'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; import * as ReportUtils from '@libs/ReportUtils'; +import * as UserUtils from '@libs/UserUtils'; import variables from '@styles/variables'; import * as Report from '@userActions/Report'; import * as Task from '@userActions/Task'; @@ -114,7 +115,8 @@ function ReportFooter({ if (mentionWithDomain) { assignee = Object.values(allPersonalDetails).find((value) => value?.login === mentionWithDomain) ?? {}; if (!Object.keys(assignee).length) { - const optimisticDataForNewAssignee = Task.setNewOptimisticAssignee(mentionWithDomain); + const assigneeAccountID = UserUtils.generateAccountID(mentionWithDomain); + const optimisticDataForNewAssignee = Task.setNewOptimisticAssignee(mentionWithDomain, assigneeAccountID); assignee = optimisticDataForNewAssignee.assignee; assigneeChatReport = optimisticDataForNewAssignee.assigneeReport; }