Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert revert moving tasks to admins room for "Manage my team expenses" intent #53661

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/components/LHNOptionsList/OptionRowLHN.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import MultipleAvatars from '@components/MultipleAvatars';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import {useSession} from '@components/OnyxProvider';
import PressableWithSecondaryInteraction from '@components/PressableWithSecondaryInteraction';
import SubscriptAvatar from '@components/SubscriptAvatar';
import Text from '@components/Text';
Expand Down Expand Up @@ -51,6 +52,12 @@ function OptionRowLHN({reportID, isFocused = false, onSelectRow = () => {}, opti
const [isOnboardingCompleted = true] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {
selector: hasCompletedGuidedSetupFlowSelector,
});
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
const session = useSession();

// Guides are assigned for the MANAGE_TEAM onboarding action, except for emails that have a '+'.
const isOnboardingGuideAssigned = introSelected?.choice === CONST.ONBOARDING_CHOICES.MANAGE_TEAM && !session?.email?.includes('+');
const shouldShowToooltipOnThisReport = isOnboardingGuideAssigned ? ReportUtils.isAdminRoom(report) : ReportUtils.isConciergeChatReport(report);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only should show tooltips in the onboarding admin room

ref: #55483

const [shouldHideGBRTooltip] = useOnyx(ONYXKEYS.NVP_SHOULD_HIDE_GBR_TOOLTIP, {initialValue: true});

const {translate} = useLocalize();
Expand Down Expand Up @@ -173,9 +180,7 @@ function OptionRowLHN({reportID, isFocused = false, onSelectRow = () => {}, opti
needsOffscreenAlphaCompositing
>
<EducationalTooltip
shouldRender={
isFirstTimeNewExpensifyUser && !shouldHideGBRTooltip && isOnboardingCompleted && isScreenFocused && shouldUseNarrowLayout && ReportUtils.isConciergeChatReport(report)
}
shouldRender={isFirstTimeNewExpensifyUser && !shouldHideGBRTooltip && isOnboardingCompleted && isScreenFocused && shouldUseNarrowLayout && shouldShowToooltipOnThisReport}
renderTooltipContent={renderGBRTooltip}
anchorAlignment={{
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT,
Expand Down
87 changes: 61 additions & 26 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ import * as ReportUtils from '@libs/ReportUtils';
import {doesReportBelongToWorkspace} from '@libs/ReportUtils';
import shouldSkipDeepLinkNavigation from '@libs/shouldSkipDeepLinkNavigation';
import {getNavatticURL} from '@libs/TourUtils';
import {generateAccountID} from '@libs/UserUtils';
import Visibility from '@libs/Visibility';
import CONFIG from '@src/CONFIG';
import type {OnboardingAccounting, OnboardingCompanySize} from '@src/CONST';
Expand Down Expand Up @@ -3522,10 +3523,27 @@ function prepareOnboardingOptimisticData(
}
}

// Guides are assigned and tasks are posted in the #admins room for the MANAGE_TEAM onboarding action, except for emails that have a '+'.
const shouldPostTasksInAdminsRoom = engagementChoice === CONST.ONBOARDING_CHOICES.MANAGE_TEAM && !currentUserEmail?.includes('+');
const integrationName = userReportedIntegration ? CONST.ONBOARDING_ACCOUNTING_MAPPING[userReportedIntegration] : '';
const actorAccountID = CONST.ACCOUNT_ID.CONCIERGE;
const targetChatReport = ReportUtils.getChatByParticipants([actorAccountID, currentUserAccountID]);
const adminsChatReport = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${adminsChatReportID}`];
const targetChatReport = shouldPostTasksInAdminsRoom ? adminsChatReport : ReportUtils.getChatByParticipants([CONST.ACCOUNT_ID.CONCIERGE, currentUserAccountID]);
const {reportID: targetChatReportID = '', policyID: targetChatPolicyID = ''} = targetChatReport ?? {};
const assignedGuideEmail = getPolicy(targetChatPolicyID)?.assignedGuide?.email ?? 'Setup Specialist';
const assignedGuidePersonalDetail = Object.values(allPersonalDetails ?? {}).find((personalDetail) => personalDetail?.login === assignedGuideEmail);
let assignedGuideAccountID: number;
if (assignedGuidePersonalDetail) {
assignedGuideAccountID = assignedGuidePersonalDetail.accountID;
} else {
assignedGuideAccountID = generateAccountID(assignedGuideEmail);
Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, {
[assignedGuideAccountID]: {
login: assignedGuideEmail,
displayName: assignedGuideEmail,
},
});
}
const actorAccountID = shouldPostTasksInAdminsRoom ? assignedGuideAccountID : CONST.ACCOUNT_ID.CONCIERGE;

// Text message
const textComment = ReportUtils.buildOptimisticAddCommentReportAction(data.message, undefined, actorAccountID, 1);
Expand Down Expand Up @@ -3587,7 +3605,9 @@ function prepareOnboardingOptimisticData(
targetChatPolicyID,
CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
);
const taskCreatedAction = ReportUtils.buildOptimisticCreatedReportAction(CONST.EMAIL.CONCIERGE);
const emailCreatingAction =
engagementChoice === CONST.ONBOARDING_CHOICES.MANAGE_TEAM ? allPersonalDetails?.[actorAccountID]?.login ?? CONST.EMAIL.CONCIERGE : CONST.EMAIL.CONCIERGE;
const taskCreatedAction = ReportUtils.buildOptimisticCreatedReportAction(emailCreatingAction);
const taskReportAction = ReportUtils.buildOptimisticTaskCommentReportAction(
currentTask.reportID,
taskTitle,
Expand Down Expand Up @@ -3779,13 +3799,7 @@ function prepareOnboardingOptimisticData(
lastMentionedTime: DateUtils.getDBTime(),
hasOutstandingChildTask,
lastVisibleActionCreated,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`,
value: {
[textCommentAction.reportActionID]: textCommentAction as ReportAction,
lastActorAccountID: actorAccountID,
},
},
{
Expand All @@ -3794,6 +3808,18 @@ function prepareOnboardingOptimisticData(
value: {choice: engagementChoice},
},
);

// 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
if (!shouldPostTasksInAdminsRoom) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`,
value: {
[textCommentAction.reportActionID]: textCommentAction as ReportAction,
},
});
}

if (!wasInvited) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -3803,13 +3829,17 @@ function prepareOnboardingOptimisticData(
}

const successData: OnyxUpdate[] = [...tasksForSuccessData];
successData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`,
value: {
[textCommentAction.reportActionID]: {pendingAction: null},
},
});

// 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
if (!shouldPostTasksInAdminsRoom) {
successData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`,
value: {
[textCommentAction.reportActionID]: {pendingAction: null},
},
});
}

let failureReport: Partial<Report> = {
lastMessageTranslationKey: '',
Expand Down Expand Up @@ -3839,21 +3869,25 @@ function prepareOnboardingOptimisticData(
key: `${ONYXKEYS.COLLECTION.REPORT}${targetChatReportID}`,
value: failureReport,
},

{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.NVP_INTRO_SELECTED,
value: {choice: null},
},
);
// 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
if (!shouldPostTasksInAdminsRoom) {
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`,
value: {
[textCommentAction.reportActionID]: {
errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('report.genericAddCommentFailureMessage'),
} as ReportAction,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.NVP_INTRO_SELECTED,
value: {choice: null},
},
);
});
}

if (!wasInvited) {
failureData.push({
Expand Down Expand Up @@ -3895,9 +3929,10 @@ function prepareOnboardingOptimisticData(
});
}

const guidedSetupData: GuidedSetupData = [{type: 'message', ...textMessage}];
// 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
const guidedSetupData: GuidedSetupData = shouldPostTasksInAdminsRoom ? [] : [{type: 'message', ...textMessage}];

if ('video' in data && data.video && videoCommentAction && videoMessage) {
if (!shouldPostTasksInAdminsRoom && 'video' in data && data.video && videoCommentAction && videoMessage) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`,
Expand Down
6 changes: 6 additions & 0 deletions src/types/onyx/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1842,6 +1842,12 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback<

/** Workspace account ID configured for Expensify Card */
workspaceAccountID?: number;

/** Setup specialist guide assigned for the policy */
assignedGuide?: {
/** The guide's email */
email: string;
};
} & Partial<PendingJoinRequestPolicy>,
'addWorkspaceRoom' | keyof ACHAccount | keyof Attributes
>;
Expand Down
Loading