@@ -87,6 +87,7 @@ import * as ReportUtils from '@libs/ReportUtils';
87
87
import { doesReportBelongToWorkspace } from '@libs/ReportUtils' ;
88
88
import shouldSkipDeepLinkNavigation from '@libs/shouldSkipDeepLinkNavigation' ;
89
89
import { getNavatticURL } from '@libs/TourUtils' ;
90
+ import { generateAccountID } from '@libs/UserUtils' ;
90
91
import Visibility from '@libs/Visibility' ;
91
92
import CONFIG from '@src/CONFIG' ;
92
93
import type { OnboardingAccounting , OnboardingCompanySize } from '@src/CONST' ;
@@ -3522,10 +3523,27 @@ function prepareOnboardingOptimisticData(
3522
3523
}
3523
3524
}
3524
3525
3526
+ // Guides are assigned and tasks are posted in the #admins room for the MANAGE_TEAM onboarding action, except for emails that have a '+'.
3527
+ const shouldPostTasksInAdminsRoom = engagementChoice === CONST . ONBOARDING_CHOICES . MANAGE_TEAM && ! currentUserEmail ?. includes ( '+' ) ;
3525
3528
const integrationName = userReportedIntegration ? CONST . ONBOARDING_ACCOUNTING_MAPPING [ userReportedIntegration ] : '' ;
3526
- const actorAccountID = CONST . ACCOUNT_ID . CONCIERGE ;
3527
- const targetChatReport = ReportUtils . getChatByParticipants ( [ actorAccountID , currentUserAccountID ] ) ;
3529
+ const adminsChatReport = ReportConnection . getAllReports ( ) ?. [ ` ${ ONYXKEYS . COLLECTION . REPORT } ${ adminsChatReportID } ` ] ;
3530
+ const targetChatReport = shouldPostTasksInAdminsRoom ? adminsChatReport : ReportUtils . getChatByParticipants ( [ CONST . ACCOUNT_ID . CONCIERGE , currentUserAccountID ] ) ;
3528
3531
const { reportID : targetChatReportID = '' , policyID : targetChatPolicyID = '' } = targetChatReport ?? { } ;
3532
+ const assignedGuideEmail = getPolicy ( targetChatPolicyID ) ?. assignedGuide ?. email ?? 'Setup Specialist' ;
3533
+ const assignedGuidePersonalDetail = Object . values ( allPersonalDetails ?? { } ) . find ( ( personalDetail ) => personalDetail ?. login === assignedGuideEmail ) ;
3534
+ let assignedGuideAccountID : number ;
3535
+ if ( assignedGuidePersonalDetail ) {
3536
+ assignedGuideAccountID = assignedGuidePersonalDetail . accountID ;
3537
+ } else {
3538
+ assignedGuideAccountID = generateAccountID ( assignedGuideEmail ) ;
3539
+ Onyx . merge ( ONYXKEYS . PERSONAL_DETAILS_LIST , {
3540
+ [ assignedGuideAccountID ] : {
3541
+ login : assignedGuideEmail ,
3542
+ displayName : assignedGuideEmail ,
3543
+ } ,
3544
+ } ) ;
3545
+ }
3546
+ const actorAccountID = shouldPostTasksInAdminsRoom ? assignedGuideAccountID : CONST . ACCOUNT_ID . CONCIERGE ;
3529
3547
3530
3548
// Text message
3531
3549
const textComment = ReportUtils . buildOptimisticAddCommentReportAction ( data . message , undefined , actorAccountID , 1 ) ;
@@ -3587,7 +3605,9 @@ function prepareOnboardingOptimisticData(
3587
3605
targetChatPolicyID ,
3588
3606
CONST . REPORT . NOTIFICATION_PREFERENCE . HIDDEN ,
3589
3607
) ;
3590
- const taskCreatedAction = ReportUtils . buildOptimisticCreatedReportAction ( CONST . EMAIL . CONCIERGE ) ;
3608
+ const emailCreatingAction =
3609
+ engagementChoice === CONST . ONBOARDING_CHOICES . MANAGE_TEAM ? allPersonalDetails ?. [ actorAccountID ] ?. login ?? CONST . EMAIL . CONCIERGE : CONST . EMAIL . CONCIERGE ;
3610
+ const taskCreatedAction = ReportUtils . buildOptimisticCreatedReportAction ( emailCreatingAction ) ;
3591
3611
const taskReportAction = ReportUtils . buildOptimisticTaskCommentReportAction (
3592
3612
currentTask . reportID ,
3593
3613
taskTitle ,
@@ -3779,13 +3799,7 @@ function prepareOnboardingOptimisticData(
3779
3799
lastMentionedTime : DateUtils . getDBTime ( ) ,
3780
3800
hasOutstandingChildTask,
3781
3801
lastVisibleActionCreated,
3782
- } ,
3783
- } ,
3784
- {
3785
- onyxMethod : Onyx . METHOD . MERGE ,
3786
- key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ targetChatReportID } ` ,
3787
- value : {
3788
- [ textCommentAction . reportActionID ] : textCommentAction as ReportAction ,
3802
+ lastActorAccountID : actorAccountID ,
3789
3803
} ,
3790
3804
} ,
3791
3805
{
@@ -3794,6 +3808,18 @@ function prepareOnboardingOptimisticData(
3794
3808
value : { choice : engagementChoice } ,
3795
3809
} ,
3796
3810
) ;
3811
+
3812
+ // If we post tasks in the #admins room, it means that a guide is assigned and all messages except tasks are handled by the backend
3813
+ if ( ! shouldPostTasksInAdminsRoom ) {
3814
+ optimisticData . push ( {
3815
+ onyxMethod : Onyx . METHOD . MERGE ,
3816
+ key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ targetChatReportID } ` ,
3817
+ value : {
3818
+ [ textCommentAction . reportActionID ] : textCommentAction as ReportAction ,
3819
+ } ,
3820
+ } ) ;
3821
+ }
3822
+
3797
3823
if ( ! wasInvited ) {
3798
3824
optimisticData . push ( {
3799
3825
onyxMethod : Onyx . METHOD . MERGE ,
@@ -3803,13 +3829,17 @@ function prepareOnboardingOptimisticData(
3803
3829
}
3804
3830
3805
3831
const successData : OnyxUpdate [ ] = [ ...tasksForSuccessData ] ;
3806
- successData . push ( {
3807
- onyxMethod : Onyx . METHOD . MERGE ,
3808
- key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ targetChatReportID } ` ,
3809
- value : {
3810
- [ textCommentAction . reportActionID ] : { pendingAction : null } ,
3811
- } ,
3812
- } ) ;
3832
+
3833
+ // If we post tasks in the #admins room, it means that a guide is assigned and all messages except tasks are handled by the backend
3834
+ if ( ! shouldPostTasksInAdminsRoom ) {
3835
+ successData . push ( {
3836
+ onyxMethod : Onyx . METHOD . MERGE ,
3837
+ key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ targetChatReportID } ` ,
3838
+ value : {
3839
+ [ textCommentAction . reportActionID ] : { pendingAction : null } ,
3840
+ } ,
3841
+ } ) ;
3842
+ }
3813
3843
3814
3844
let failureReport : Partial < Report > = {
3815
3845
lastMessageTranslationKey : '' ,
@@ -3839,21 +3869,25 @@ function prepareOnboardingOptimisticData(
3839
3869
key : `${ ONYXKEYS . COLLECTION . REPORT } ${ targetChatReportID } ` ,
3840
3870
value : failureReport ,
3841
3871
} ,
3872
+
3842
3873
{
3874
+ onyxMethod : Onyx . METHOD . MERGE ,
3875
+ key : ONYXKEYS . NVP_INTRO_SELECTED ,
3876
+ value : { choice : null } ,
3877
+ } ,
3878
+ ) ;
3879
+ // If we post tasks in the #admins room, it means that a guide is assigned and all messages except tasks are handled by the backend
3880
+ if ( ! shouldPostTasksInAdminsRoom ) {
3881
+ failureData . push ( {
3843
3882
onyxMethod : Onyx . METHOD . MERGE ,
3844
3883
key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ targetChatReportID } ` ,
3845
3884
value : {
3846
3885
[ textCommentAction . reportActionID ] : {
3847
3886
errors : ErrorUtils . getMicroSecondOnyxErrorWithTranslationKey ( 'report.genericAddCommentFailureMessage' ) ,
3848
3887
} as ReportAction ,
3849
3888
} ,
3850
- } ,
3851
- {
3852
- onyxMethod : Onyx . METHOD . MERGE ,
3853
- key : ONYXKEYS . NVP_INTRO_SELECTED ,
3854
- value : { choice : null } ,
3855
- } ,
3856
- ) ;
3889
+ } ) ;
3890
+ }
3857
3891
3858
3892
if ( ! wasInvited ) {
3859
3893
failureData . push ( {
@@ -3895,9 +3929,10 @@ function prepareOnboardingOptimisticData(
3895
3929
} ) ;
3896
3930
}
3897
3931
3898
- const guidedSetupData : GuidedSetupData = [ { type : 'message' , ...textMessage } ] ;
3932
+ // If we post tasks in the #admins room, it means that a guide is assigned and all messages except tasks are handled by the backend
3933
+ const guidedSetupData : GuidedSetupData = shouldPostTasksInAdminsRoom ? [ ] : [ { type : 'message' , ...textMessage } ] ;
3899
3934
3900
- if ( 'video' in data && data . video && videoCommentAction && videoMessage ) {
3935
+ if ( ! shouldPostTasksInAdminsRoom && 'video' in data && data . video && videoCommentAction && videoMessage ) {
3901
3936
optimisticData . push ( {
3902
3937
onyxMethod : Onyx . METHOD . MERGE ,
3903
3938
key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ targetChatReportID } ` ,
0 commit comments