Skip to content

Commit 963b4e9

Browse files
authored
Merge pull request Expensify#74369 from mkzie2/mkzie2-issue/73336
Fallback avatar remains when new user is assignee
2 parents 17fb17f + 2d5a37a commit 963b4e9

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

src/libs/ReportUtils.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10033,6 +10033,7 @@ function getTaskAssigneeChatOnyxData(
1003310033
parentReportID: string | undefined,
1003410034
title: string,
1003510035
assigneeChatReport: OnyxEntry<Report>,
10036+
isOptimisticAssigneeChatReport?: boolean,
1003610037
): OnyxDataTaskAssigneeChat {
1003710038
// Set if we need to add a comment to the assignee chat notifying them that they have been assigned a task
1003810039
let optimisticAssigneeAddComment: OptimisticReportAction | undefined;
@@ -10046,7 +10047,7 @@ function getTaskAssigneeChatOnyxData(
1004610047

1004710048
// You're able to assign a task to someone you haven't chatted with before - so we need to optimistically create the chat and the chat reportActions
1004810049
// Only add the assignee chat report to onyx if we haven't already set it optimistically
10049-
if (assigneeChatReportMetadata?.isOptimisticReport && assigneeChatReport?.pendingFields?.createChat !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
10050+
if ((isOptimisticAssigneeChatReport ?? assigneeChatReportMetadata?.isOptimisticReport) && assigneeChatReport?.pendingFields?.createChat !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
1005010051
optimisticChatCreatedReportAction = buildOptimisticCreatedReportAction(assigneeChatReportID);
1005110052
optimisticData.push(
1005210053
{
@@ -10100,6 +10101,15 @@ function getTaskAssigneeChatOnyxData(
1010010101
},
1010110102
);
1010210103

10104+
// If task assignee is created optimistically, we need to clear the optimistic personal details to prevent duplication with real data sent from BE.
10105+
successData.push({
10106+
onyxMethod: Onyx.METHOD.MERGE,
10107+
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
10108+
value: {
10109+
[assigneeAccountID]: null,
10110+
},
10111+
});
10112+
1010310113
failureData.push(
1010410114
{
1010510115
onyxMethod: Onyx.METHOD.SET,

src/libs/actions/Task.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ function editTaskAssignee(
656656
currentUserAccountID: number,
657657
assigneeAccountID: number | null = 0,
658658
assigneeChatReport?: OnyxEntry<OnyxTypes.Report>,
659+
isOptimisticReport?: boolean,
659660
) {
660661
// Create the EditedReportAction on the task
661662
const editTaskReportAction = ReportUtils.buildOptimisticChangedTaskAssigneeReportAction(assigneeAccountID ?? CONST.DEFAULT_NUMBER_ID);
@@ -771,6 +772,7 @@ function editTaskAssignee(
771772
report.parentReportID,
772773
reportName ?? '',
773774
assigneeChatReport,
775+
isOptimisticReport,
774776
);
775777

776778
if (assigneeChatReportMetadata?.isOptimisticReport && assigneeChatReport.pendingFields?.createChat !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
@@ -875,8 +877,9 @@ function setAssigneeValue(
875877
chatReport?: OnyxEntry<OnyxTypes.Report>,
876878
isCurrentUser = false,
877879
skipShareDestination = false,
878-
): OnyxEntry<OnyxTypes.Report> | undefined {
880+
): {report: OnyxEntry<OnyxTypes.Report> | undefined; isOptimisticReport: boolean} {
879881
let report: OnyxEntry<OnyxTypes.Report> | undefined = chatReport;
882+
let reportMetadata: OnyxEntry<OnyxTypes.ReportMetadata> | undefined;
880883
if (isCurrentUser) {
881884
const selfDMReportID = ReportUtils.findSelfDMReportID();
882885
// If there is no share destination set, automatically set it to the assignee chat report
@@ -893,7 +896,7 @@ function setAssigneeValue(
893896
if (!report) {
894897
report = setNewOptimisticAssignee(currentUserAccountID, assigneePersonalDetails).assigneeReport;
895898
}
896-
const reportMetadata = ReportUtils.getReportMetadata(report?.reportID);
899+
reportMetadata = ReportUtils.getReportMetadata(report?.reportID);
897900

898901
// The optimistic field may not exist in the existing report and it can be overridden by the optimistic field of previous report data when merging the assignee chat report
899902
// Therefore, we should add these optimistic fields here to prevent incorrect merging, which could lead to the creation of duplicate actions for an existing report
@@ -916,10 +919,12 @@ function setAssigneeValue(
916919
// This is only needed for creation of a new task and so it should only be stored locally
917920
Onyx.merge(ONYXKEYS.TASK, {assignee: assigneePersonalDetails?.login ?? '', assigneeAccountID: assigneePersonalDetails.accountID});
918921

922+
const isOptimisticAssigneeChatReport = reportMetadata ? (reportMetadata.isOptimisticReport ?? false) : true;
923+
919924
// When we're editing the assignee, we immediately call editTaskAssignee. Since setting the assignee is async,
920925
// the chatReport is not yet set when editTaskAssignee is called. So we return the chatReport here so that
921926
// editTaskAssignee can use it.
922-
return report;
927+
return {report, isOptimisticReport: isOptimisticAssigneeChatReport};
923928
}
924929

925930
/**

src/pages/tasks/TaskAssigneeSelectorModal.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ function TaskAssigneeSelectorModal() {
158158
// Check to see if we're editing a task and if so, update the assignee
159159
if (report) {
160160
if (option.accountID !== report.managerID) {
161-
const assigneeChatReport = setAssigneeValue(
161+
const {report: assigneeChatReport, isOptimisticReport} = setAssigneeValue(
162162
currentUserPersonalDetails.accountID,
163163
assigneePersonalDetails,
164164
report.reportID,
@@ -173,6 +173,7 @@ function TaskAssigneeSelectorModal() {
173173
currentUserPersonalDetails.accountID,
174174
option?.accountID,
175175
assigneeChatReport,
176+
isOptimisticReport,
176177
);
177178
}
178179
// eslint-disable-next-line @typescript-eslint/no-deprecated

0 commit comments

Comments
 (0)