Skip to content

Commit 229b1c2

Browse files
authored
Merge pull request Expensify#86432 from dukenv0307/fix/66424-part-13
2 parents 2b517db + cf3f60d commit 229b1c2

7 files changed

Lines changed: 127 additions & 17 deletions

File tree

src/components/ReportActionItem/MoneyRequestReceiptView.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {hasSeenTourSelector} from '@selectors/Onboarding';
12
import mapValues from 'lodash/mapValues';
23
import React, {useEffect, useMemo, useRef, useState} from 'react';
34
import {View} from 'react-native';
@@ -130,6 +131,7 @@ function MoneyRequestReceiptView({
130131
});
131132
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
132133
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
134+
const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
133135
const [betas] = useOnyx(ONYXKEYS.BETAS);
134136

135137
const [isLoading, setIsLoading] = useState(true);
@@ -354,7 +356,7 @@ function MoneyRequestReceiptView({
354356
}
355357
if (transaction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
356358
if (chatReport?.reportID && getCreationReportErrors(chatReport)) {
357-
navigateToConciergeChatAndDeleteReport(chatReport.reportID, conciergeReportID, currentUserAccountID, introSelected, betas, true, true);
359+
navigateToConciergeChatAndDeleteReport(chatReport.reportID, conciergeReportID, currentUserAccountID, introSelected, isSelfTourViewed, betas, true, true);
358360
return;
359361
}
360362
if (parentReportAction) {
@@ -391,7 +393,7 @@ function MoneyRequestReceiptView({
391393
if (isInNarrowPaneModal) {
392394
Navigation.goBack();
393395
}
394-
navigateToConciergeChatAndDeleteReport(report.reportID, conciergeReportID, currentUserAccountID, introSelected, betas, true, true);
396+
navigateToConciergeChatAndDeleteReport(report.reportID, conciergeReportID, currentUserAccountID, introSelected, isSelfTourViewed, betas, true, true);
395397
}
396398
};
397399

src/libs/actions/Report/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3884,6 +3884,7 @@ function navigateToConciergeChatAndDeleteReport(
38843884
conciergeReportID: string | undefined,
38853885
currentUserAccountID: number,
38863886
introSelected: OnyxEntry<IntroSelected>,
3887+
isSelfTourViewed: boolean | undefined,
38873888
betas: OnyxEntry<Beta[]>,
38883889
shouldPopToTop = false,
38893890
shouldDeleteChildReports = false,
@@ -3894,8 +3895,7 @@ function navigateToConciergeChatAndDeleteReport(
38943895
} else {
38953896
Navigation.goBack();
38963897
}
3897-
// TODO: We'll pass isSelfTourViewed in the next PR. Refactor issue: https://github.com/Expensify/App/issues/66424
3898-
navigateToConciergeChat(conciergeReportID, introSelected, currentUserAccountID, undefined, betas, false);
3898+
navigateToConciergeChat(conciergeReportID, introSelected, currentUserAccountID, isSelfTourViewed, betas, false);
38993899
// eslint-disable-next-line @typescript-eslint/no-deprecated
39003900
InteractionManager.runAfterInteractions(() => {
39013901
deleteReport(reportID, shouldDeleteChildReports);
@@ -3916,7 +3916,8 @@ function clearCreateChatError(
39163916
return;
39173917
}
39183918

3919-
navigateToConciergeChatAndDeleteReport(report?.reportID, conciergeReportID, currentUserAccountID, introSelected, betas, undefined, true);
3919+
// TODO: We'll pass isSelfTourViewed in the next PR. Refactor issue: https://github.com/Expensify/App/issues/66424
3920+
navigateToConciergeChatAndDeleteReport(report?.reportID, conciergeReportID, currentUserAccountID, introSelected, undefined, betas, undefined, true);
39203921
}
39213922

39223923
/**

src/libs/actions/Task.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1390,7 +1390,8 @@ function clearTaskErrors(
13901390
if (report?.pendingFields?.createChat === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
13911391
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`, report.parentReportActionID ? {[report.parentReportActionID]: null} : {});
13921392

1393-
navigateToConciergeChatAndDeleteReport(reportID, conciergeReportID, currentUserAccountID, introSelected, betas);
1393+
// TODO: We'll pass isSelfTourViewed in the next PR. Refactor issue: https://github.com/Expensify/App/issues/66424
1394+
navigateToConciergeChatAndDeleteReport(reportID, conciergeReportID, currentUserAccountID, introSelected, undefined, betas);
13941395
return;
13951396
}
13961397

src/pages/Debug/Report/DebugReportPage.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {hasSeenTourSelector} from '@selectors/Onboarding';
12
import React, {useCallback, useMemo} from 'react';
23
import {View} from 'react-native';
34
import type {OnyxEntry} from 'react-native-onyx';
@@ -72,6 +73,7 @@ function DebugReportPage({
7273
const [betas] = useOnyx(ONYXKEYS.BETAS);
7374
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
7475
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
76+
const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
7577
const {accountID: currentUserAccountID} = useCurrentUserPersonalDetails();
7678
const transactionID = DebugUtils.getTransactionID(report, reportActions);
7779
const isReportArchived = useReportIsArchived(reportID);
@@ -164,7 +166,7 @@ function DebugReportPage({
164166
Debug.setDebugData(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, data);
165167
}}
166168
onDelete={() => {
167-
navigateToConciergeChatAndDeleteReport(reportID, conciergeReportID, currentUserAccountID, introSelected, betas, true, true);
169+
navigateToConciergeChatAndDeleteReport(reportID, conciergeReportID, currentUserAccountID, introSelected, isSelfTourViewed, betas, true, true);
168170
}}
169171
validate={DebugUtils.validateReportDraftProperty}
170172
>
@@ -228,6 +230,7 @@ function DebugReportPage({
228230
currentUserAccountID,
229231
conciergeReportID,
230232
introSelected,
233+
isSelfTourViewed,
231234
betas,
232235
],
233236
);

src/pages/inbox/report/ReportActionItemParentAction.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {hasSeenTourSelector} from '@selectors/Onboarding';
12
import {getReportActionsForReportIDs} from '@selectors/ReportAction';
23
import React, {useCallback} from 'react';
34
import {View} from 'react-native';
@@ -189,6 +190,7 @@ function ReportActionItemParentAction({
189190

190191
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
191192
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
193+
const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
192194

193195
return (
194196
<View style={[styles.pRelative]}>
@@ -199,7 +201,7 @@ function ReportActionItemParentAction({
199201
report?.errorFields?.createChatThread ?? (report?.errorFields?.createChat ? getMicroSecondOnyxErrorWithTranslationKey('report.genericCreateReportFailureMessage') : null)
200202
}
201203
errorRowStyles={[styles.ml10, styles.mr2]}
202-
onClose={() => navigateToConciergeChatAndDeleteReport(report?.reportID, conciergeReportID, currentUserAccountID, introSelected, allBetas, undefined, true)}
204+
onClose={() => navigateToConciergeChatAndDeleteReport(report?.reportID, conciergeReportID, currentUserAccountID, introSelected, isSelfTourViewed, allBetas, undefined, true)}
203205
>
204206
{ancestors.map((ancestor) => {
205207
const {report: ancestorReport, reportAction: ancestorReportAction} = ancestor;
@@ -224,7 +226,9 @@ function ReportActionItemParentAction({
224226
pendingAction={ancestorReport?.pendingFields?.addWorkspaceRoom ?? ancestorReport?.pendingFields?.createChat}
225227
errors={ancestorReport?.errorFields?.addWorkspaceRoom ?? ancestorReport?.errorFields?.createChat}
226228
errorRowStyles={[styles.ml10, styles.mr2]}
227-
onClose={() => navigateToConciergeChatAndDeleteReport(ancestorReport.reportID, conciergeReportID, currentUserAccountID, introSelected, allBetas)}
229+
onClose={() =>
230+
navigateToConciergeChatAndDeleteReport(ancestorReport.reportID, conciergeReportID, currentUserAccountID, introSelected, isSelfTourViewed, allBetas)
231+
}
228232
>
229233
{shouldDisplayThreadDivider && (
230234
<ThreadDivider

tests/actions/ReportTest.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4218,7 +4218,7 @@ describe('actions/Report', () => {
42184218
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, testReport);
42194219
await waitForBatchedUpdates();
42204220

4221-
Report.navigateToConciergeChatAndDeleteReport(REPORT_ID, CONCIERGE_REPORT_ID, TEST_USER_ACCOUNT_ID, INTRO_SELECTED, undefined);
4221+
Report.navigateToConciergeChatAndDeleteReport(REPORT_ID, CONCIERGE_REPORT_ID, TEST_USER_ACCOUNT_ID, INTRO_SELECTED, undefined, undefined);
42224222

42234223
await waitForBatchedUpdates();
42244224

@@ -4232,7 +4232,7 @@ describe('actions/Report', () => {
42324232
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, testReport);
42334233
await waitForBatchedUpdates();
42344234

4235-
Report.navigateToConciergeChatAndDeleteReport(REPORT_ID, CONCIERGE_REPORT_ID, TEST_USER_ACCOUNT_ID, INTRO_SELECTED, undefined, true);
4235+
Report.navigateToConciergeChatAndDeleteReport(REPORT_ID, CONCIERGE_REPORT_ID, TEST_USER_ACCOUNT_ID, INTRO_SELECTED, undefined, undefined, true);
42364236

42374237
await waitForBatchedUpdates();
42384238

@@ -4245,7 +4245,7 @@ describe('actions/Report', () => {
42454245
await waitForBatchedUpdates();
42464246

42474247
expect(() => {
4248-
Report.navigateToConciergeChatAndDeleteReport(undefined, CONCIERGE_REPORT_ID, TEST_USER_ACCOUNT_ID, INTRO_SELECTED, undefined);
4248+
Report.navigateToConciergeChatAndDeleteReport(undefined, CONCIERGE_REPORT_ID, TEST_USER_ACCOUNT_ID, INTRO_SELECTED, undefined, undefined);
42494249
}).not.toThrow();
42504250
});
42514251

@@ -4254,7 +4254,7 @@ describe('actions/Report', () => {
42544254
await waitForBatchedUpdates();
42554255

42564256
expect(() => {
4257-
Report.navigateToConciergeChatAndDeleteReport(REPORT_ID, undefined, TEST_USER_ACCOUNT_ID, INTRO_SELECTED, undefined);
4257+
Report.navigateToConciergeChatAndDeleteReport(REPORT_ID, undefined, TEST_USER_ACCOUNT_ID, INTRO_SELECTED, undefined, undefined);
42584258
}).not.toThrow();
42594259

42604260
await waitForBatchedUpdates();
@@ -4268,7 +4268,7 @@ describe('actions/Report', () => {
42684268
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, testReport);
42694269
await waitForBatchedUpdates();
42704270

4271-
Report.navigateToConciergeChatAndDeleteReport(REPORT_ID, CONCIERGE_REPORT_ID, TEST_USER_ACCOUNT_ID, INTRO_SELECTED, undefined, false, true);
4271+
Report.navigateToConciergeChatAndDeleteReport(REPORT_ID, CONCIERGE_REPORT_ID, TEST_USER_ACCOUNT_ID, INTRO_SELECTED, undefined, undefined, false, true);
42724272

42734273
await waitForBatchedUpdates();
42744274

@@ -4281,7 +4281,7 @@ describe('actions/Report', () => {
42814281
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, testReport);
42824282
await waitForBatchedUpdates();
42834283

4284-
Report.navigateToConciergeChatAndDeleteReport(REPORT_ID, CONCIERGE_REPORT_ID, TEST_USER_ACCOUNT_ID, INTRO_SELECTED, undefined, true, true);
4284+
Report.navigateToConciergeChatAndDeleteReport(REPORT_ID, CONCIERGE_REPORT_ID, TEST_USER_ACCOUNT_ID, INTRO_SELECTED, undefined, undefined, true, true);
42854285

42864286
await waitForBatchedUpdates();
42874287

@@ -4295,7 +4295,7 @@ describe('actions/Report', () => {
42954295
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, testReport);
42964296
await waitForBatchedUpdates();
42974297

4298-
Report.navigateToConciergeChatAndDeleteReport(REPORT_ID, CONCIERGE_REPORT_ID, TEST_USER_ACCOUNT_ID, INTRO_SELECTED, undefined);
4298+
Report.navigateToConciergeChatAndDeleteReport(REPORT_ID, CONCIERGE_REPORT_ID, TEST_USER_ACCOUNT_ID, INTRO_SELECTED, undefined, undefined);
42994299

43004300
await waitForBatchedUpdates();
43014301

@@ -4310,13 +4310,27 @@ describe('actions/Report', () => {
43104310
await waitForBatchedUpdates();
43114311

43124312
expect(() => {
4313-
Report.navigateToConciergeChatAndDeleteReport(REPORT_ID, CONCIERGE_REPORT_ID, TEST_USER_ACCOUNT_ID, undefined, undefined);
4313+
Report.navigateToConciergeChatAndDeleteReport(REPORT_ID, CONCIERGE_REPORT_ID, TEST_USER_ACCOUNT_ID, undefined, undefined, undefined);
43144314
}).not.toThrow();
43154315

43164316
await waitForBatchedUpdates();
43174317

43184318
expect(mockNavigation.goBack).toHaveBeenCalled();
43194319
});
4320+
4321+
it('should pass isSelfTourViewed to navigateToConciergeChat', async () => {
4322+
await Onyx.set(ONYXKEYS.CONCIERGE_REPORT_ID, CONCIERGE_REPORT_ID);
4323+
const testReport = createRandomReport(Number(REPORT_ID), undefined);
4324+
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, testReport);
4325+
await waitForBatchedUpdates();
4326+
4327+
Report.navigateToConciergeChatAndDeleteReport(REPORT_ID, CONCIERGE_REPORT_ID, TEST_USER_ACCOUNT_ID, INTRO_SELECTED, true, undefined);
4328+
4329+
await waitForBatchedUpdates();
4330+
4331+
expect(mockNavigation.goBack).toHaveBeenCalled();
4332+
expect(mockNavigation.navigate).toHaveBeenCalled();
4333+
});
43204334
});
43214335

43224336
describe('navigateToAndOpenChildReport', () => {

tests/unit/ReportUtilsTest.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import useReportIsArchived from '@hooks/useReportIsArchived';
1212
import * as HoldUtils from '@libs/actions/IOU/Hold';
1313
import {putOnHold} from '@libs/actions/IOU/Hold';
1414
import initOnyxDerivedValues from '@libs/actions/OnyxDerived';
15+
import type {TaskForParameters} from '@libs/actions/Report';
1516
import type {OnboardingTaskLinks} from '@libs/actions/Welcome/OnboardingFlow';
1617
import {convertToDisplayString} from '@libs/CurrencyUtils';
1718
import DateUtils from '@libs/DateUtils';
@@ -935,6 +936,90 @@ describe('ReportUtils', () => {
935936
const messageEntries = result?.guidedSetupData.filter((data) => data.type === 'message');
936937
expect(messageEntries?.length).toBeGreaterThanOrEqual(1);
937938
});
939+
940+
it('should auto-complete VIEW_TOUR task when isSelfTourViewed is true', () => {
941+
const result = prepareOnboardingOnyxData({
942+
introSelected: undefined,
943+
engagementChoice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM,
944+
onboardingMessage: {
945+
message: 'This is a test',
946+
tasks: [
947+
{
948+
type: CONST.ONBOARDING_TASK_TYPE.VIEW_TOUR,
949+
title: () => 'View Tour',
950+
description: () => 'Take a tour',
951+
autoCompleted: false,
952+
},
953+
],
954+
},
955+
adminsChatReportID: '1',
956+
companySize: CONST.ONBOARDING_COMPANY_SIZE.MICRO,
957+
isSelfTourViewed: true,
958+
});
959+
960+
const viewTourTask = result?.guidedSetupData.find(
961+
(item): item is Extract<TaskForParameters, {type: 'task'}> => item.type === 'task' && 'task' in item && item.task === CONST.ONBOARDING_TASK_TYPE.VIEW_TOUR,
962+
);
963+
expect(viewTourTask).toBeDefined();
964+
expect(viewTourTask?.completedTaskReportActionID).toBeDefined();
965+
});
966+
967+
it('should not auto-complete VIEW_TOUR task when isSelfTourViewed is false', () => {
968+
const result = prepareOnboardingOnyxData({
969+
introSelected: undefined,
970+
engagementChoice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM,
971+
onboardingMessage: {
972+
message: 'This is a test',
973+
tasks: [
974+
{
975+
type: CONST.ONBOARDING_TASK_TYPE.VIEW_TOUR,
976+
title: () => 'View Tour',
977+
description: () => 'Take a tour',
978+
autoCompleted: false,
979+
},
980+
],
981+
},
982+
adminsChatReportID: '1',
983+
companySize: CONST.ONBOARDING_COMPANY_SIZE.MICRO,
984+
isSelfTourViewed: false,
985+
});
986+
987+
const viewTourTask = result?.guidedSetupData.find(
988+
(item): item is Extract<TaskForParameters, {type: 'task'}> => item.type === 'task' && 'task' in item && item.task === CONST.ONBOARDING_TASK_TYPE.VIEW_TOUR,
989+
);
990+
expect(viewTourTask).toBeDefined();
991+
expect(viewTourTask?.completedTaskReportActionID).toBeUndefined();
992+
});
993+
994+
it('should auto-complete VIEW_TOUR task when isSelfTourViewed is undefined but onboarding.selfTourViewed is true via Onyx', async () => {
995+
await Onyx.merge(ONYXKEYS.NVP_ONBOARDING, {selfTourViewed: true, hasCompletedGuidedSetupFlow: false});
996+
await waitForBatchedUpdates();
997+
998+
const result = prepareOnboardingOnyxData({
999+
introSelected: undefined,
1000+
engagementChoice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM,
1001+
onboardingMessage: {
1002+
message: 'This is a test',
1003+
tasks: [
1004+
{
1005+
type: CONST.ONBOARDING_TASK_TYPE.VIEW_TOUR,
1006+
title: () => 'View Tour',
1007+
description: () => 'Take a tour',
1008+
autoCompleted: false,
1009+
},
1010+
],
1011+
},
1012+
adminsChatReportID: '1',
1013+
companySize: CONST.ONBOARDING_COMPANY_SIZE.MICRO,
1014+
isSelfTourViewed: undefined,
1015+
});
1016+
1017+
const viewTourTask = result?.guidedSetupData.find(
1018+
(item): item is Extract<TaskForParameters, {type: 'task'}> => item.type === 'task' && 'task' in item && item.task === CONST.ONBOARDING_TASK_TYPE.VIEW_TOUR,
1019+
);
1020+
expect(viewTourTask).toBeDefined();
1021+
expect(viewTourTask?.completedTaskReportActionID).toBeDefined();
1022+
});
9381023
});
9391024

9401025
describe('getIconsForParticipants', () => {

0 commit comments

Comments
 (0)