Skip to content

Commit

Permalink
Merge pull request #52314 from c3024/wip-move-tasks-to-admin-2
Browse files Browse the repository at this point in the history
Optimistic update for moving tasks for "Manage Team's Expenses" to #admins room
  • Loading branch information
yuwenmemon authored Dec 2, 2024
2 parents 0a6803d + 5c1618e commit 473822d
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 29 deletions.
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);
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 @@ -3489,10 +3490,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 @@ -3554,7 +3572,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 @@ -3734,13 +3754,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 @@ -3749,6 +3763,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 @@ -3758,13 +3784,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 @@ -3794,21 +3824,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 @@ -3850,9 +3884,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

0 comments on commit 473822d

Please sign in to comment.