@@ -440,6 +440,83 @@ function editTaskAndNavigate(report, ownerAccountID, {title, description, assign
440
440
Navigation . dismissModal ( report . reportID ) ;
441
441
}
442
442
443
+ function editTaskAssigneeAndNavigate ( report , ownerAccountID , assigneeEmail , assigneeAccountID = 0 , assigneeChatReport = null ) {
444
+ // Create the EditedReportAction on the task
445
+ const editTaskReportAction = ReportUtils . buildOptimisticEditedTaskReportAction ( currentUserEmail ) ;
446
+ const reportName = report . reportName . trim ( ) ;
447
+
448
+ let assigneeChatReportOnyxData ;
449
+ const assigneeChatReportID = assigneeChatReport ? assigneeChatReport . reportID : 0 ;
450
+
451
+ const optimisticData = [
452
+ {
453
+ onyxMethod : Onyx . METHOD . MERGE ,
454
+ key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ report . reportID } ` ,
455
+ value : { [ editTaskReportAction . reportActionID ] : editTaskReportAction } ,
456
+ } ,
457
+ {
458
+ onyxMethod : Onyx . METHOD . MERGE ,
459
+ key : `${ ONYXKEYS . COLLECTION . REPORT } ${ report . reportID } ` ,
460
+ value : {
461
+ reportName,
462
+ managerID : assigneeAccountID || report . managerID ,
463
+ managerEmail : assigneeEmail || report . managerEmail ,
464
+ } ,
465
+ } ,
466
+ ] ;
467
+ const successData = [ ] ;
468
+ const failureData = [
469
+ {
470
+ onyxMethod : Onyx . METHOD . MERGE ,
471
+ key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ report . reportID } ` ,
472
+ value : { [ editTaskReportAction . reportActionID ] : { pendingAction : null } } ,
473
+ } ,
474
+ {
475
+ onyxMethod : Onyx . METHOD . MERGE ,
476
+ key : `${ ONYXKEYS . COLLECTION . REPORT } ${ report . reportID } ` ,
477
+ value : { assignee : report . managerEmail , assigneeAccountID : report . managerID } ,
478
+ } ,
479
+ ] ;
480
+
481
+ // If we make a change to the assignee, we want to add a comment to the assignee's chat
482
+ // Check if the assignee actually changed
483
+ if ( assigneeAccountID && assigneeAccountID !== report . managerID && assigneeAccountID !== ownerAccountID && assigneeChatReport ) {
484
+ assigneeChatReportOnyxData = ReportUtils . getTaskAssigneeChatOnyxData (
485
+ currentUserAccountID ,
486
+ assigneeEmail ,
487
+ assigneeAccountID ,
488
+ report . reportID ,
489
+ assigneeChatReportID ,
490
+ report . parentReportID ,
491
+ reportName ,
492
+ assigneeChatReport ,
493
+ ) ;
494
+ optimisticData . push ( ...assigneeChatReportOnyxData . optimisticData ) ;
495
+ successData . push ( ...assigneeChatReportOnyxData . successData ) ;
496
+ failureData . push ( ...assigneeChatReportOnyxData . failureData ) ;
497
+ }
498
+
499
+ API . write (
500
+ 'EditTaskAssignee' ,
501
+ {
502
+ taskReportID : report . reportID ,
503
+ assignee : assigneeEmail || report . managerEmail ,
504
+ assigneeAccountID : assigneeAccountID || report . managerID ,
505
+ editedTaskReportActionID : editTaskReportAction . reportActionID ,
506
+ assigneeChatReportID,
507
+ assigneeChatReportActionID :
508
+ assigneeChatReportOnyxData && assigneeChatReportOnyxData . optimisticAssigneeAddComment
509
+ ? assigneeChatReportOnyxData . optimisticAssigneeAddComment . reportAction . reportActionID
510
+ : 0 ,
511
+ assigneeChatCreatedReportActionID :
512
+ assigneeChatReportOnyxData && assigneeChatReportOnyxData . optimisticChatCreatedReportAction ? assigneeChatReportOnyxData . optimisticChatCreatedReportAction . reportActionID : 0 ,
513
+ } ,
514
+ { optimisticData, successData, failureData} ,
515
+ ) ;
516
+
517
+ Navigation . dismissModal ( report . reportID ) ;
518
+ }
519
+
443
520
/**
444
521
* Sets the report info for the task being viewed
445
522
*
@@ -739,6 +816,7 @@ function canModifyTask(taskReport, sessionAccountID) {
739
816
export {
740
817
createTaskAndNavigate ,
741
818
editTaskAndNavigate ,
819
+ editTaskAssigneeAndNavigate ,
742
820
setTitleValue ,
743
821
setDescriptionValue ,
744
822
setTaskReport ,
0 commit comments