Skip to content

Commit

Permalink
Merge pull request #39215 from nexarvo/fix/39049-shortcut-self-dm-task
Browse files Browse the repository at this point in the history
Fix/39049 shortcut self dm task

(cherry picked from commit 196d245)
  • Loading branch information
yuwenmemon authored and OSBotify committed Mar 28, 2024
1 parent b411661 commit 3183101
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
41 changes: 25 additions & 16 deletions src/libs/actions/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,23 +649,32 @@ function setAssigneeChatReport(chatReport: OnyxTypes.Report) {
* If there is no existing chat, it creates an optimistic chat report
* It also sets the shareDestination as that chat report if a share destination isn't already set
*/
function setAssigneeValue(assigneeEmail: string, assigneeAccountID: number, shareDestination: string, isCurrentUser = false): OnyxEntry<OnyxTypes.Report> {
let chatReport: OnyxEntry<OnyxTypes.Report> = null;

function setAssigneeValue(
assigneeEmail: string,
assigneeAccountID: number,
shareToReportID: string,
chatReport: OnyxEntry<OnyxTypes.Report>,
isCurrentUser = false,
): OnyxEntry<OnyxTypes.Report> {
let report = chatReport;
if (!isCurrentUser) {
chatReport = ReportUtils.getChatByParticipants([assigneeAccountID]);
if (!chatReport) {
chatReport = ReportUtils.buildOptimisticChatReport([assigneeAccountID]);
chatReport.isOptimisticReport = true;
// Check for the chatReport by participants IDs
if (!report) {
report = ReportUtils.getChatByParticipants([assigneeAccountID]);
}
// If chat report is still not found we need to build new optimistic chat report
if (!report) {
report = ReportUtils.buildOptimisticChatReport([assigneeAccountID]);
report.isOptimisticReport = true;

// 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
// We don't want to show the new DM yet, because if you select an assignee and then change the assignee, the previous DM will still be shown
// So here, we create it optimistically to share it with the assignee, but we have to hide it until the task is created
if (chatReport) {
chatReport.isHidden = true;
if (report) {
report.isHidden = true;
}
Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, chatReport);
Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report);

// If this is an optimistic report, we likely don't have their personal details yet so we set it here optimistically as well
const optimisticPersonalDetailsListAction = {
Expand All @@ -677,12 +686,12 @@ function setAssigneeValue(assigneeEmail: string, assigneeAccountID: number, shar
Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, {[assigneeAccountID]: optimisticPersonalDetailsListAction});
}

setAssigneeChatReport(chatReport);
setAssigneeChatReport(report);

// If there is no share destination set, automatically set it to the assignee chat report
// This allows for a much quicker process when creating a new task and is likely the desired share destination most times
if (!shareDestination) {
setShareDestinationValue(chatReport?.reportID ?? '');
if (!shareToReportID) {
setShareDestinationValue(report?.reportID ?? '');
}
}

Expand All @@ -692,7 +701,7 @@ function setAssigneeValue(assigneeEmail: string, assigneeAccountID: number, shar
// When we're editing the assignee, we immediately call editTaskAssignee. Since setting the assignee is async,
// the chatReport is not yet set when editTaskAssignee is called. So we return the chatReport here so that
// editTaskAssignee can use it.
return chatReport;
return report;
}

/**
Expand All @@ -706,14 +715,14 @@ function setParentReportID(parentReportID: string) {
/**
* Clears out the task info from the store and navigates to the NewTaskDetails page
*/
function clearOutTaskInfoAndNavigate(reportID: string, accountID = 0) {
function clearOutTaskInfoAndNavigate(reportID: string, chatReport: OnyxEntry<OnyxTypes.Report>, accountID = 0) {
clearOutTaskInfo();
if (reportID && reportID !== '0') {
setParentReportID(reportID);
}
if (accountID > 0) {
const accountLogin = allPersonalDetails?.[accountID]?.login ?? '';
setAssigneeValue(accountLogin, accountID, reportID);
setAssigneeValue(accountLogin, accountID, reportID, chatReport);
}
Navigation.navigate(ROUTES.NEW_TASK_DETAILS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function AttachmentPickerWithMenuItems({
{
icon: Expensicons.Task,
text: translate('newTaskPage.assignTask'),
onSelected: () => Task.clearOutTaskInfoAndNavigate(reportID),
onSelected: () => Task.clearOutTaskInfoAndNavigate(reportID, report),
},
];
}, [report, reportID, translate]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ function FloatingActionButtonAndPopover(props) {
IOU.startMoneyRequest(CONST.IOU.TYPE.SEND, props.quickAction.chatReportID);
return;
case CONST.QUICK_ACTIONS.ASSIGN_TASK:
Task.clearOutTaskInfoAndNavigate(props.quickAction.chatReportID, _.get(props.quickAction, 'targetAccountID', 0));
Task.clearOutTaskInfoAndNavigate(props.quickAction.chatReportID, quickActionReport, _.get(props.quickAction, 'targetAccountID', 0));
return;
default:
return '';
Expand Down
2 changes: 2 additions & 0 deletions src/pages/tasks/TaskAssigneeSelectorModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ function TaskAssigneeSelectorModal({reports, task}: TaskAssigneeSelectorModalPro
option?.login ?? '',
option?.accountID ?? -1,
report.reportID,
report,
OptionsListUtils.isCurrentUser({...option, accountID: option?.accountID ?? -1, login: option?.login ?? ''}),
);

Expand All @@ -193,6 +194,7 @@ function TaskAssigneeSelectorModal({reports, task}: TaskAssigneeSelectorModalPro
option?.login ?? '',
option.accountID,
task?.shareDestination ?? '',
report,
OptionsListUtils.isCurrentUser({...option, accountID: option?.accountID ?? -1, login: option?.login ?? undefined}),
);
Navigation.goBack(ROUTES.NEW_TASK);
Expand Down

0 comments on commit 3183101

Please sign in to comment.