Skip to content

Commit 1ebe416

Browse files
authored
Merge pull request Expensify#87809 from Krishna2323/krishna2323/issue/66425-part-6
Part 6 - Thread delegateEmail through getFinishOnboardingTaskOnyxData and completeTestDriveTask
2 parents b7b4b85 + cddde9c commit 1ebe416

10 files changed

Lines changed: 55 additions & 10 deletions

File tree

src/components/TestDrive/TestDriveDemo.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {delegateEmailSelector} from '@selectors/Account';
12
import {hasSeenTourSelector} from '@selectors/Onboarding';
23
import React, {useCallback, useEffect, useRef, useState} from 'react';
34
import {InteractionManager} from 'react-native';
@@ -34,6 +35,7 @@ function TestDriveDemo() {
3435
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
3536
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
3637
const [betas] = useOnyx(ONYXKEYS.BETAS);
38+
const [delegateEmail] = useOnyx(ONYXKEYS.ACCOUNT, {selector: delegateEmailSelector});
3739
const {
3840
taskReport: viewTourTaskReport,
3941
taskParentReport: viewTourTaskParentReport,
@@ -72,6 +74,7 @@ function TestDriveDemo() {
7274
currentUserPersonalDetails.accountID,
7375
hasOutstandingChildTask,
7476
parentReportAction,
77+
delegateEmail,
7578
false,
7679
);
7780
}, [
@@ -82,6 +85,7 @@ function TestDriveDemo() {
8285
currentUserPersonalDetails.accountID,
8386
hasOutstandingChildTask,
8487
parentReportAction,
88+
delegateEmail,
8589
conciergeReportID,
8690
introSelected,
8791
betas,

src/libs/ReportUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11933,7 +11933,7 @@ function prepareOnboardingOnyxData({
1193311933
}
1193411934

1193511935
const completedTaskReportAction = isTaskAutoCompleted
11936-
? // Will be refactored in next PR; full restructure tracked in https://github.com/Expensify/App/issues/66417
11936+
? // Will be refactored in next PR; buildOptimisticTaskReportAction falls back to module-level Onyx.connect value; tracked in https://github.com/Expensify/App/issues/66417
1193711937
buildOptimisticTaskReportAction(currentTask.reportID, CONST.REPORT.ACTIONS.TYPE.TASK_COMPLETED, undefined, 'marked as complete', actorAccountID, 2)
1193811938
: null;
1193911939
if (task.type === CONST.ONBOARDING_TASK_TYPE.CREATE_WORKSPACE) {

src/libs/actions/Policy/Category.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ function appendSetupCategoriesOnboardingData(
9494
currentUserAccountID,
9595
hasOutstandingChildTask,
9696
parentReportAction,
97+
// Will be refactored in next PR; buildOptimisticTaskReportAction falls back to module-level Onyx.connect value; tracked in https://github.com/Expensify/App/issues/66417
98+
undefined,
9799
);
98100
onyxData.optimisticData?.push(...(finishOnboardingTaskData.optimisticData ?? []));
99101
onyxData.successData?.push(...(finishOnboardingTaskData.successData ?? []));

src/libs/actions/Policy/Policy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2923,7 +2923,7 @@ function buildPolicyData(options: BuildPolicyDataOptions): OnyxData<BuildPolicyD
29232923
optimisticData: optimisticCreateWorkspaceTaskData,
29242924
successData: successCreateWorkspaceTaskData,
29252925
failureData: failureCreateWorkspaceTaskData,
2926-
// Will be refactored in next PR; full restructure tracked in https://github.com/Expensify/App/issues/66417
2926+
// Will be refactored in next PR; buildOptimisticTaskReportAction falls back to module-level Onyx.connect value; tracked in https://github.com/Expensify/App/issues/66417
29272927
} = buildTaskData(createWorkspaceTaskReport, introSelected.createWorkspace, false, false, undefined, undefined);
29282928
optimisticData.push(...optimisticCreateWorkspaceTaskData);
29292929
successData.push(...successCreateWorkspaceTaskData);

src/libs/actions/Policy/Tag.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ function createPolicyTag({
224224
currentUserAccountID,
225225
setupTagsHasOutstandingChildTask ?? false,
226226
setupTagsParentReportAction,
227+
// Will be refactored in next PR; buildOptimisticTaskReportAction falls back to module-level Onyx.connect value; tracked in https://github.com/Expensify/App/issues/66417
228+
undefined,
227229
);
228230
}
229231

@@ -236,6 +238,8 @@ function createPolicyTag({
236238
currentUserAccountID,
237239
setupCategoriesAndTagsHasOutstandingChildTask ?? false,
238240
setupCategoriesAndTagsParentReportAction,
241+
// Will be refactored in next PR; buildOptimisticTaskReportAction falls back to module-level Onyx.connect value; tracked in https://github.com/Expensify/App/issues/66417
242+
undefined,
239243
);
240244
}
241245
}

src/libs/actions/Task.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,12 +1443,12 @@ function getFinishOnboardingTaskOnyxData(
14431443
currentUserAccountID: number,
14441444
hasOutstandingChildTask: boolean,
14451445
parentReportAction: OnyxEntry<ReportAction> | undefined,
1446+
delegateEmail: string | undefined,
14461447
): OnyxData<typeof ONYXKEYS.COLLECTION.REPORT | typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS> {
14471448
if (taskReport && canActionTask(taskReport, parentReportAction, currentUserAccountID, taskParentReport, isParentReportArchived)) {
14481449
if (taskReport) {
14491450
if (taskReport.stateNum !== CONST.REPORT.STATE_NUM.APPROVED || taskReport.statusNum !== CONST.REPORT.STATUS_NUM.APPROVED) {
1450-
// Will be refactored in next PR; full restructure tracked in https://github.com/Expensify/App/issues/66417
1451-
return completeTask(taskReport, taskParentReport?.hasOutstandingChildTask ?? false, hasOutstandingChildTask, parentReportAction, undefined);
1451+
return completeTask(taskReport, taskParentReport?.hasOutstandingChildTask ?? false, hasOutstandingChildTask, parentReportAction, delegateEmail);
14521452
}
14531453
}
14541454
}
@@ -1462,10 +1462,19 @@ function completeTestDriveTask(
14621462
currentUserAccountID: number,
14631463
hasOutstandingChildTask: boolean,
14641464
parentReportAction: OnyxEntry<ReportAction> | undefined,
1465+
delegateEmail: string | undefined,
14651466
shouldUpdateSelfTourViewedOnlyLocally = false,
14661467
) {
14671468
setSelfTourViewed(shouldUpdateSelfTourViewedOnlyLocally);
1468-
getFinishOnboardingTaskOnyxData(viewTourTaskReport, viewTourTaskParentReport, isViewTourTaskParentReportArchived, currentUserAccountID, hasOutstandingChildTask, parentReportAction);
1469+
getFinishOnboardingTaskOnyxData(
1470+
viewTourTaskReport,
1471+
viewTourTaskParentReport,
1472+
isViewTourTaskParentReportArchived,
1473+
currentUserAccountID,
1474+
hasOutstandingChildTask,
1475+
parentReportAction,
1476+
delegateEmail,
1477+
);
14691478
}
14701479

14711480
export {

src/libs/actions/Workflow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function createApprovalWorkflow({approvalWorkflow, policy, addExpenseApprovalsTa
9292
addExpenseApprovalsTaskReport &&
9393
(addExpenseApprovalsTaskReport.stateNum !== CONST.REPORT.STATE_NUM.APPROVED || addExpenseApprovalsTaskReport.statusNum !== CONST.REPORT.STATUS_NUM.APPROVED)
9494
) {
95-
// Will be refactored in next PR; full restructure tracked in https://github.com/Expensify/App/issues/66417
95+
// Will be refactored in next PR; buildOptimisticTaskReportAction falls back to module-level Onyx.connect value; tracked in https://github.com/Expensify/App/issues/66417
9696
completeTask(addExpenseApprovalsTaskReport, false, false, undefined, undefined);
9797
}
9898
}

src/pages/home/DiscoverSection.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {delegateEmailSelector} from '@selectors/Account';
12
import React from 'react';
23
import {Image, Linking, View} from 'react-native';
34
import HomeTestDriveImage from '@assets/images/home-testdrive-image.png';
@@ -35,6 +36,7 @@ function DiscoverSection() {
3536
} = useOnboardingTaskInformation(CONST.ONBOARDING_TASK_TYPE.VIEW_TOUR);
3637
const parentReportAction = useParentReportAction(viewTourTaskReport);
3738
const [onboarding] = useOnyx(ONYXKEYS.NVP_ONBOARDING);
39+
const [delegateEmail] = useOnyx(ONYXKEYS.ACCOUNT, {selector: delegateEmailSelector});
3840

3941
if (onboarding?.selfTourViewed || !onboarding) {
4042
return null;
@@ -51,6 +53,7 @@ function DiscoverSection() {
5153
currentUserPersonalDetails.accountID,
5254
hasOutstandingChildTask,
5355
parentReportAction,
56+
delegateEmail,
5457
false,
5558
);
5659
return;

src/pages/iou/request/step/IOURequestStepConfirmation.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {delegateEmailSelector} from '@selectors/Account';
12
import {hasSeenTourSelector} from '@selectors/Onboarding';
23
import {validTransactionDraftIDsSelector} from '@selectors/TransactionDraft';
34
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
@@ -204,6 +205,7 @@ function IOURequestStepConfirmation({
204205
const [gpsDraftDetails] = useOnyx(ONYXKEYS.GPS_DRAFT_DETAILS);
205206
const [betas] = useOnyx(ONYXKEYS.BETAS);
206207
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
208+
const [delegateEmail] = useOnyx(ONYXKEYS.ACCOUNT, {selector: delegateEmailSelector});
207209

208210
const expensifyIcons = useMemoizedLazyExpensifyIcons(['ReplaceReceipt', 'SmartScan']);
209211

@@ -528,6 +530,7 @@ function IOURequestStepConfirmation({
528530
currentUserPersonalDetails.accountID,
529531
hasOutstandingChildTask,
530532
parentReportAction,
533+
delegateEmail,
531534
false,
532535
);
533536
}
@@ -654,6 +657,7 @@ function IOURequestStepConfirmation({
654657
isViewTourTaskParentReportArchived,
655658
hasOutstandingChildTask,
656659
parentReportAction,
660+
delegateEmail,
657661
translate,
658662
toLocaleDigit,
659663
betas,

tests/actions/TaskTest.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,24 +271,43 @@ describe('actions/Task', () => {
271271
const conciergeChatReport: Report = getFakeReport([accountID, CONST.ACCOUNT_ID.CONCIERGE]);
272272
const testDriveTaskReport: Report = {...getFakeReport(), ownerAccountID: accountID};
273273
it('Completes test drive task', () => {
274-
completeTestDriveTask(testDriveTaskReport, conciergeChatReport, false, accountID, false, undefined);
275-
expect(Object.values(getFinishOnboardingTaskOnyxData(testDriveTaskReport, conciergeChatReport, false, 0, false, undefined)).length).toBe(0);
274+
completeTestDriveTask(testDriveTaskReport, conciergeChatReport, false, accountID, false, undefined, undefined);
275+
expect(Object.values(getFinishOnboardingTaskOnyxData(testDriveTaskReport, conciergeChatReport, false, 0, false, undefined, undefined)).length).toBe(0);
276276
});
277277
});
278278

279279
describe('getFinishOnboardingTaskOnyxData', () => {
280+
const DELEGATE_EMAIL = 'delegate@example.com';
281+
const DELEGATE_ACCOUNT_ID = 999;
280282
const parentReport: Report = getFakeReport();
281283
const taskReport: Report = {...getFakeReport(), type: CONST.REPORT.TYPE.TASK, ownerAccountID: 1, managerID: 2, parentReportID: parentReport.reportID};
282284
beforeEach(async () => {
283285
await Onyx.clear();
284286
await Onyx.set(ONYXKEYS.SESSION, {email: 'user1@gmail.com', accountID: 2});
287+
await Onyx.set(ONYXKEYS.PERSONAL_DETAILS_LIST, {
288+
[DELEGATE_ACCOUNT_ID]: {accountID: DELEGATE_ACCOUNT_ID, login: DELEGATE_EMAIL},
289+
});
285290
await waitForBatchedUpdates();
286291
});
287292
it('Return not empty object', () => {
288-
expect(Object.values(getFinishOnboardingTaskOnyxData(taskReport, parentReport, false, 2, false, undefined)).length).toBeGreaterThan(0);
293+
expect(Object.values(getFinishOnboardingTaskOnyxData(taskReport, parentReport, false, 2, false, undefined, undefined)).length).toBeGreaterThan(0);
289294
});
290295
it('Return empty object', () => {
291-
expect(Object.values(getFinishOnboardingTaskOnyxData(taskReport, parentReport, true, 2, false, undefined)).length).toBe(0);
296+
expect(Object.values(getFinishOnboardingTaskOnyxData(taskReport, parentReport, true, 2, false, undefined, undefined)).length).toBe(0);
297+
});
298+
it('forwards delegateAccountID when delegateEmail is provided', () => {
299+
const onyxData = getFinishOnboardingTaskOnyxData(taskReport, parentReport, false, 2, false, undefined, DELEGATE_EMAIL);
300+
const reportActionsData = onyxData.optimisticData?.find((entry) => (entry.key as string).startsWith(ONYXKEYS.COLLECTION.REPORT_ACTIONS));
301+
const reportActions = reportActionsData?.value as Record<string, ReportAction> | undefined;
302+
const completedAction = reportActions ? Object.values(reportActions).find((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.TASK_COMPLETED) : undefined;
303+
expect(completedAction?.delegateAccountID).toBe(DELEGATE_ACCOUNT_ID);
304+
});
305+
it('does not set delegateAccountID when delegateEmail is undefined', () => {
306+
const onyxData = getFinishOnboardingTaskOnyxData(taskReport, parentReport, false, 2, false, undefined, undefined);
307+
const reportActionsData = onyxData.optimisticData?.find((entry) => (entry.key as string).startsWith(ONYXKEYS.COLLECTION.REPORT_ACTIONS));
308+
const reportActions = reportActionsData?.value as Record<string, ReportAction> | undefined;
309+
const completedAction = reportActions ? Object.values(reportActions).find((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.TASK_COMPLETED) : undefined;
310+
expect(completedAction?.delegateAccountID).toBeUndefined();
292311
});
293312
});
294313

0 commit comments

Comments
 (0)