Skip to content

Commit bebf6d8

Browse files
authored
Merge pull request #53661 from c3024/revert-revert-move-tasks-to-admins-room
Revert revert moving tasks to admins room for "Manage my team expenses" intent
2 parents c9f324f + 824b4b3 commit bebf6d8

File tree

3 files changed

+75
-29
lines changed

3 files changed

+75
-29
lines changed

src/components/LHNOptionsList/OptionRowLHN.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Icon from '@components/Icon';
99
import * as Expensicons from '@components/Icon/Expensicons';
1010
import MultipleAvatars from '@components/MultipleAvatars';
1111
import OfflineWithFeedback from '@components/OfflineWithFeedback';
12+
import {useSession} from '@components/OnyxProvider';
1213
import PressableWithSecondaryInteraction from '@components/PressableWithSecondaryInteraction';
1314
import SubscriptAvatar from '@components/SubscriptAvatar';
1415
import Text from '@components/Text';
@@ -51,6 +52,12 @@ function OptionRowLHN({reportID, isFocused = false, onSelectRow = () => {}, opti
5152
const [isOnboardingCompleted = true] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {
5253
selector: hasCompletedGuidedSetupFlowSelector,
5354
});
55+
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
56+
const session = useSession();
57+
58+
// Guides are assigned for the MANAGE_TEAM onboarding action, except for emails that have a '+'.
59+
const isOnboardingGuideAssigned = introSelected?.choice === CONST.ONBOARDING_CHOICES.MANAGE_TEAM && !session?.email?.includes('+');
60+
const shouldShowToooltipOnThisReport = isOnboardingGuideAssigned ? ReportUtils.isAdminRoom(report) : ReportUtils.isConciergeChatReport(report);
5461
const [shouldHideGBRTooltip] = useOnyx(ONYXKEYS.NVP_SHOULD_HIDE_GBR_TOOLTIP, {initialValue: true});
5562

5663
const {translate} = useLocalize();
@@ -173,9 +180,7 @@ function OptionRowLHN({reportID, isFocused = false, onSelectRow = () => {}, opti
173180
needsOffscreenAlphaCompositing
174181
>
175182
<EducationalTooltip
176-
shouldRender={
177-
isFirstTimeNewExpensifyUser && !shouldHideGBRTooltip && isOnboardingCompleted && isScreenFocused && shouldUseNarrowLayout && ReportUtils.isConciergeChatReport(report)
178-
}
183+
shouldRender={isFirstTimeNewExpensifyUser && !shouldHideGBRTooltip && isOnboardingCompleted && isScreenFocused && shouldUseNarrowLayout && shouldShowToooltipOnThisReport}
179184
renderTooltipContent={renderGBRTooltip}
180185
anchorAlignment={{
181186
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT,

src/libs/actions/Report.ts

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ import * as ReportUtils from '@libs/ReportUtils';
8787
import {doesReportBelongToWorkspace} from '@libs/ReportUtils';
8888
import shouldSkipDeepLinkNavigation from '@libs/shouldSkipDeepLinkNavigation';
8989
import {getNavatticURL} from '@libs/TourUtils';
90+
import {generateAccountID} from '@libs/UserUtils';
9091
import Visibility from '@libs/Visibility';
9192
import CONFIG from '@src/CONFIG';
9293
import type {OnboardingAccounting, OnboardingCompanySize} from '@src/CONST';
@@ -3522,10 +3523,27 @@ function prepareOnboardingOptimisticData(
35223523
}
35233524
}
35243525

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('+');
35253528
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]);
35283531
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;
35293547

35303548
// Text message
35313549
const textComment = ReportUtils.buildOptimisticAddCommentReportAction(data.message, undefined, actorAccountID, 1);
@@ -3587,7 +3605,9 @@ function prepareOnboardingOptimisticData(
35873605
targetChatPolicyID,
35883606
CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
35893607
);
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);
35913611
const taskReportAction = ReportUtils.buildOptimisticTaskCommentReportAction(
35923612
currentTask.reportID,
35933613
taskTitle,
@@ -3779,13 +3799,7 @@ function prepareOnboardingOptimisticData(
37793799
lastMentionedTime: DateUtils.getDBTime(),
37803800
hasOutstandingChildTask,
37813801
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,
37893803
},
37903804
},
37913805
{
@@ -3794,6 +3808,18 @@ function prepareOnboardingOptimisticData(
37943808
value: {choice: engagementChoice},
37953809
},
37963810
);
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+
37973823
if (!wasInvited) {
37983824
optimisticData.push({
37993825
onyxMethod: Onyx.METHOD.MERGE,
@@ -3803,13 +3829,17 @@ function prepareOnboardingOptimisticData(
38033829
}
38043830

38053831
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+
}
38133843

38143844
let failureReport: Partial<Report> = {
38153845
lastMessageTranslationKey: '',
@@ -3839,21 +3869,25 @@ function prepareOnboardingOptimisticData(
38393869
key: `${ONYXKEYS.COLLECTION.REPORT}${targetChatReportID}`,
38403870
value: failureReport,
38413871
},
3872+
38423873
{
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({
38433882
onyxMethod: Onyx.METHOD.MERGE,
38443883
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`,
38453884
value: {
38463885
[textCommentAction.reportActionID]: {
38473886
errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('report.genericAddCommentFailureMessage'),
38483887
} as ReportAction,
38493888
},
3850-
},
3851-
{
3852-
onyxMethod: Onyx.METHOD.MERGE,
3853-
key: ONYXKEYS.NVP_INTRO_SELECTED,
3854-
value: {choice: null},
3855-
},
3856-
);
3889+
});
3890+
}
38573891

38583892
if (!wasInvited) {
38593893
failureData.push({
@@ -3895,9 +3929,10 @@ function prepareOnboardingOptimisticData(
38953929
});
38963930
}
38973931

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}];
38993934

3900-
if ('video' in data && data.video && videoCommentAction && videoMessage) {
3935+
if (!shouldPostTasksInAdminsRoom && 'video' in data && data.video && videoCommentAction && videoMessage) {
39013936
optimisticData.push({
39023937
onyxMethod: Onyx.METHOD.MERGE,
39033938
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`,

src/types/onyx/Policy.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,6 +1842,12 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback<
18421842

18431843
/** Workspace account ID configured for Expensify Card */
18441844
workspaceAccountID?: number;
1845+
1846+
/** Setup specialist guide assigned for the policy */
1847+
assignedGuide?: {
1848+
/** The guide's email */
1849+
email: string;
1850+
};
18451851
} & Partial<PendingJoinRequestPolicy>,
18461852
'addWorkspaceRoom' | keyof ACHAccount | keyof Attributes
18471853
>;

0 commit comments

Comments
 (0)