Skip to content

Commit 4b5b509

Browse files
authored
Merge pull request #87231 from dukenv0307/fix/66424-part-14
2 parents e4049b7 + 06d4a86 commit 4b5b509

8 files changed

Lines changed: 74 additions & 21 deletions

File tree

src/components/PromotedActionsBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const PromotedActions = {
8585
return;
8686
}
8787
if (accountID) {
88-
navigateToAndOpenReportWithAccountIDs([accountID], currentUserAccountID, introSelected, betas);
88+
navigateToAndOpenReportWithAccountIDs([accountID], currentUserAccountID, introSelected, isSelfTourViewed, betas);
8989
}
9090
},
9191
}),

src/components/ReportActionItem/TaskView.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {delegateEmailSelector} from '@selectors/Account';
2+
import {hasSeenTourSelector} from '@selectors/Onboarding';
23
import React, {useEffect, useMemo} from 'react';
34
import {View} from 'react-native';
45
import type {OnyxEntry} from 'react-native-onyx';
@@ -58,6 +59,7 @@ function TaskView({report, parentReport, action}: TaskViewProps) {
5859
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
5960
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
6061
const [betas] = useOnyx(ONYXKEYS.BETAS);
62+
const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
6163
const [delegateEmail] = useOnyx(ONYXKEYS.ACCOUNT, {selector: delegateEmailSelector});
6264

6365
useEffect(() => {
@@ -116,7 +118,7 @@ function TaskView({report, parentReport, action}: TaskViewProps) {
116118
<OfflineWithFeedback
117119
shouldShowErrorMessages
118120
errors={report?.errorFields?.editTask ?? report?.errorFields?.createTask}
119-
onClose={() => clearTaskErrors(report, conciergeReportID, accountID, introSelected, betas)}
121+
onClose={() => clearTaskErrors(report, conciergeReportID, accountID, introSelected, betas, isSelfTourViewed)}
120122
errorRowStyles={styles.ph5}
121123
>
122124
<Hoverable>

src/libs/actions/Report/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,7 +2031,13 @@ function navigateToAndCreateGroupChat(
20312031
*
20322032
* @param participantAccountIDs of user logins to start a chat report with.
20332033
*/
2034-
function navigateToAndOpenReportWithAccountIDs(participantAccountIDs: number[], currentUserAccountID: number, introSelected: OnyxEntry<IntroSelected>, betas: OnyxEntry<Beta[]>) {
2034+
function navigateToAndOpenReportWithAccountIDs(
2035+
participantAccountIDs: number[],
2036+
currentUserAccountID: number,
2037+
introSelected: OnyxEntry<IntroSelected>,
2038+
isSelfTourViewed: boolean | undefined,
2039+
betas: OnyxEntry<Beta[]>,
2040+
) {
20352041
let newChat: OptimisticChatReport | undefined;
20362042
const chat = getChatByParticipants([...participantAccountIDs, currentUserAccountID]);
20372043
if (!chat) {
@@ -2043,6 +2049,7 @@ function navigateToAndOpenReportWithAccountIDs(participantAccountIDs: number[],
20432049
openReport({
20442050
reportID: newChat?.reportID,
20452051
introSelected,
2052+
isSelfTourViewed,
20462053
newReportObject: newChat,
20472054
parentReportActionID: '0',
20482055
participantAccountIDList: participantAccountIDs,
@@ -3937,6 +3944,7 @@ function clearCreateChatError(
39373944
introSelected: OnyxEntry<IntroSelected>,
39383945
currentUserAccountID: number,
39393946
betas: OnyxEntry<Beta[]>,
3947+
isSelfTourViewed: boolean | undefined,
39403948
) {
39413949
const metaData = getReportMetadata(report?.reportID);
39423950
const isOptimisticReport = metaData?.isOptimisticReport;
@@ -3945,8 +3953,7 @@ function clearCreateChatError(
39453953
return;
39463954
}
39473955

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

39523959
/**

src/libs/actions/Task.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,7 @@ function clearTaskErrors(
14151415
currentUserAccountID: number,
14161416
introSelected: OnyxEntry<OnyxTypes.IntroSelected>,
14171417
betas: OnyxEntry<OnyxTypes.Beta[]>,
1418+
isSelfTourViewed: boolean | undefined,
14181419
) {
14191420
const reportID = report?.reportID;
14201421
if (!reportID) {
@@ -1425,8 +1426,7 @@ function clearTaskErrors(
14251426
if (report?.pendingFields?.createChat === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
14261427
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`, report.parentReportActionID ? {[report.parentReportActionID]: null} : {});
14271428

1428-
// TODO: We'll pass isSelfTourViewed in the next PR. Refactor issue: https://github.com/Expensify/App/issues/66424
1429-
navigateToConciergeChatAndDeleteReport(reportID, conciergeReportID, currentUserAccountID, introSelected, undefined, betas);
1429+
navigateToConciergeChatAndDeleteReport(reportID, conciergeReportID, currentUserAccountID, introSelected, isSelfTourViewed, betas);
14301430
return;
14311431
}
14321432

src/pages/inbox/report/ReportActionItemCreated.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {hasSeenTourSelector} from '@selectors/Onboarding';
12
import React, {memo} from 'react';
23
import {View} from 'react-native';
34
import OfflineWithFeedback from '@components/OfflineWithFeedback';
@@ -34,6 +35,7 @@ function ReportActionItemCreated({reportID, policyID}: ReportActionItemCreatedPr
3435
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
3536
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
3637
const [betas] = useOnyx(ONYXKEYS.BETAS);
38+
const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
3739
const {accountID: currentUserAccountID} = useCurrentUserPersonalDetails();
3840

3941
if (!isChatReport(report)) {
@@ -47,7 +49,7 @@ function ReportActionItemCreated({reportID, policyID}: ReportActionItemCreatedPr
4749
pendingAction={report?.pendingFields?.addWorkspaceRoom ?? report?.pendingFields?.createChat}
4850
errors={report?.errorFields?.addWorkspaceRoom ?? report?.errorFields?.createChat}
4951
errorRowStyles={[styles.ml10, styles.mr2]}
50-
onClose={() => clearCreateChatError(report, conciergeReportID, introSelected, currentUserAccountID, betas)}
52+
onClose={() => clearCreateChatError(report, conciergeReportID, introSelected, currentUserAccountID, betas, isSelfTourViewed)}
5153
>
5254
<View style={[styles.pRelative]}>
5355
<AnimatedEmptyStateBackground />

src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {hasSeenTourSelector} from '@selectors/Onboarding';
12
import React, {useState} from 'react';
23
import {View} from 'react-native';
34
import type {OnyxEntry} from 'react-native-onyx';
@@ -68,6 +69,7 @@ function WorkspaceWorkflowsPayerPage({route, policy, personalDetails, isLoadingR
6869
const bankAccountID = policyBankAccountID ?? bankAccountInfo?.accountData?.bankAccountID;
6970
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
7071
const [betas] = useOnyx(ONYXKEYS.BETAS);
72+
const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
7173
const {isOffline} = useNetwork();
7274
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
7375
const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE);
@@ -358,7 +360,7 @@ function WorkspaceWorkflowsPayerPage({route, policy, personalDetails, isLoadingR
358360
return;
359361
}
360362
setShowErrorModal(false);
361-
navigateToAndOpenReportWithAccountIDs([policy.ownerAccountID], currentUserPersonalDetails.accountID, introSelected, betas);
363+
navigateToAndOpenReportWithAccountIDs([policy.ownerAccountID], currentUserPersonalDetails.accountID, introSelected, isSelfTourViewed, betas);
362364
}}
363365
html={translate('workflowsPayerPage.shareBankAccount.errorDescription', {
364366
admin: selectedPayerDetails?.displayName ?? '',

tests/actions/ReportTest.ts

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ describe('actions/Report', () => {
323323

324324
return waitForBatchedUpdates()
325325
.then(() => {
326-
Report.clearCreateChatError(REPORT, CONCIERGE_REPORT_ID, {choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM}, TEST_USER_ACCOUNT_ID, undefined);
326+
Report.clearCreateChatError(REPORT, CONCIERGE_REPORT_ID, {choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM}, TEST_USER_ACCOUNT_ID, undefined, false);
327327
return waitForBatchedUpdates();
328328
})
329329
.then(
@@ -356,7 +356,7 @@ describe('actions/Report', () => {
356356

357357
return waitForBatchedUpdates()
358358
.then(() => {
359-
Report.clearCreateChatError(REPORT, CONCIERGE_REPORT_ID, INTRO_SELECTED, TEST_USER_ACCOUNT_ID, undefined);
359+
Report.clearCreateChatError(REPORT, CONCIERGE_REPORT_ID, INTRO_SELECTED, TEST_USER_ACCOUNT_ID, undefined, false);
360360
return waitForBatchedUpdates();
361361
})
362362
.then(
@@ -388,7 +388,7 @@ describe('actions/Report', () => {
388388

389389
return waitForBatchedUpdates()
390390
.then(() => {
391-
Report.clearCreateChatError(REPORT, CONCIERGE_REPORT_ID, INTRO_SELECTED, TEST_USER_ACCOUNT_ID, undefined);
391+
Report.clearCreateChatError(REPORT, CONCIERGE_REPORT_ID, INTRO_SELECTED, TEST_USER_ACCOUNT_ID, undefined, false);
392392
return waitForBatchedUpdates();
393393
})
394394
.then(
@@ -409,12 +409,14 @@ describe('actions/Report', () => {
409409
);
410410
});
411411

412-
it('clearCreateChatError should forward betas through navigateToConciergeChatAndDeleteReport when deleting optimistic report', async () => {
412+
it.each<[string, OnyxTypes.Beta[] | undefined]>([
413+
['with betas', [CONST.BETAS.ALL]],
414+
['without betas', undefined],
415+
])('clearCreateChatError should call openReport when deleting optimistic report %s', async (_label, betas) => {
413416
const TEST_USER_ACCOUNT_ID = 1;
414417
const TEST_USER_LOGIN = 'test@user.com';
415418
const REPORT: OnyxTypes.Report = {...createRandomReport(1, undefined), errorFields: {createChat: {error: 'error'}}};
416419
const INTRO_SELECTED: OnyxTypes.IntroSelected = {choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM};
417-
const testBetas = [CONST.BETAS.ALL];
418420

419421
await TestHelper.signInWithTestUser(TEST_USER_ACCOUNT_ID, TEST_USER_LOGIN);
420422
await TestHelper.setPersonalDetails(TEST_USER_LOGIN, TEST_USER_ACCOUNT_ID);
@@ -429,7 +431,7 @@ describe('actions/Report', () => {
429431
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${REPORT.reportID}`, {isOptimisticReport: true});
430432
await waitForBatchedUpdates();
431433

432-
Report.clearCreateChatError(REPORT, undefined, INTRO_SELECTED, TEST_USER_ACCOUNT_ID, testBetas);
434+
Report.clearCreateChatError(REPORT, undefined, INTRO_SELECTED, TEST_USER_ACCOUNT_ID, betas, false);
433435
await waitForBatchedUpdates();
434436

435437
TestHelper.expectAPICommandToHaveBeenCalled(WRITE_COMMANDS.OPEN_REPORT, 1);
@@ -6476,7 +6478,7 @@ describe('actions/Report', () => {
64766478
});
64776479

64786480
describe('navigateToAndOpenReportWithAccountIDs', () => {
6479-
it('should create new chat and pass betas to openReport when no existing chat', async () => {
6481+
it.each([true, false])('should create new chat and call openReport when no existing chat (isSelfTourViewed=%s)', async (isSelfTourViewed) => {
64806482
const TEST_USER_ACCOUNT_ID = 1;
64816483
const TEST_USER_LOGIN = 'test@user.com';
64826484
const PARTICIPANT_ACCOUNT_ID = 2;
@@ -6486,7 +6488,7 @@ describe('actions/Report', () => {
64866488

64876489
const testIntroSelected: OnyxTypes.IntroSelected = {choice: CONST.ONBOARDING_CHOICES.ADMIN};
64886490

6489-
Report.navigateToAndOpenReportWithAccountIDs([PARTICIPANT_ACCOUNT_ID], TEST_USER_ACCOUNT_ID, testIntroSelected, undefined);
6491+
Report.navigateToAndOpenReportWithAccountIDs([PARTICIPANT_ACCOUNT_ID], TEST_USER_ACCOUNT_ID, testIntroSelected, isSelfTourViewed, undefined);
64906492
await waitForBatchedUpdates();
64916493

64926494
TestHelper.expectAPICommandToHaveBeenCalled(WRITE_COMMANDS.OPEN_REPORT, 1);
@@ -6513,7 +6515,7 @@ describe('actions/Report', () => {
65136515

65146516
const testIntroSelected: OnyxTypes.IntroSelected = {choice: CONST.ONBOARDING_CHOICES.ADMIN};
65156517

6516-
Report.navigateToAndOpenReportWithAccountIDs([PARTICIPANT_ACCOUNT_ID], TEST_USER_ACCOUNT_ID, testIntroSelected, undefined);
6518+
Report.navigateToAndOpenReportWithAccountIDs([PARTICIPANT_ACCOUNT_ID], TEST_USER_ACCOUNT_ID, testIntroSelected, false, undefined);
65176519
await waitForBatchedUpdates();
65186520

65196521
TestHelper.expectAPICommandToHaveBeenCalled(WRITE_COMMANDS.OPEN_REPORT, 0);
@@ -6579,6 +6581,29 @@ describe('actions/Report', () => {
65796581
expect(result?.successData).toBeDefined();
65806582
expect(result?.failureData).toBeDefined();
65816583
});
6584+
6585+
it.each<[boolean, string]>([
6586+
[true, 'should be defined'],
6587+
[false, 'should be undefined'],
6588+
])('viewTour completedTaskReportActionID when isSelfTourViewed=%s %s', async (isSelfTourViewed) => {
6589+
await setupUserWithConciergeChat();
6590+
await Onyx.merge(ONYXKEYS.NVP_ONBOARDING, {hasCompletedGuidedSetupFlow: false});
6591+
await waitForBatchedUpdates();
6592+
6593+
const introSelected: OnyxTypes.IntroSelected = {choice: CONST.ONBOARDING_CHOICES.SUBMIT, isInviteOnboardingComplete: false};
6594+
const result = Report.getGuidedSetupDataForOpenReport(introSelected, undefined, isSelfTourViewed);
6595+
6596+
expect(result).toBeDefined();
6597+
const guidedSetupData = JSON.parse(result?.guidedSetupData ?? '[]') as Array<{type: string; task?: string; completedTaskReportActionID?: string}>;
6598+
const viewTourTask = guidedSetupData.find((item) => item.type === 'task' && item.task === CONST.ONBOARDING_TASK_TYPE.VIEW_TOUR);
6599+
expect(viewTourTask).toBeDefined();
6600+
6601+
if (isSelfTourViewed) {
6602+
expect(viewTourTask?.completedTaskReportActionID).toBeDefined();
6603+
} else {
6604+
expect(viewTourTask?.completedTaskReportActionID).toBeUndefined();
6605+
}
6606+
});
65826607
});
65836608

65846609
describe('createTransactionThreadReport', () => {

tests/unit/PromotedActionsBarTest.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('PromotedActions.message', () => {
5252

5353
action.onSelected();
5454

55-
expect(mockNavigateToAndOpenReportWithAccountIDs).toHaveBeenCalledWith([42], 1, introSelected, undefined);
55+
expect(mockNavigateToAndOpenReportWithAccountIDs).toHaveBeenCalledWith([42], 1, introSelected, false, undefined);
5656
});
5757

5858
it('should pass undefined introSelected when not provided', () => {
@@ -66,7 +66,7 @@ describe('PromotedActions.message', () => {
6666

6767
action.onSelected();
6868

69-
expect(mockNavigateToAndOpenReportWithAccountIDs).toHaveBeenCalledWith([42], 1, undefined, undefined);
69+
expect(mockNavigateToAndOpenReportWithAccountIDs).toHaveBeenCalledWith([42], 1, undefined, undefined, undefined);
7070
});
7171

7272
it('should navigate to report directly when reportID is provided', () => {
@@ -114,7 +114,22 @@ describe('PromotedActions.message', () => {
114114

115115
action.onSelected();
116116

117-
expect(mockNavigateToAndOpenReportWithAccountIDs).toHaveBeenCalledWith([42], 1, introSelected, betas);
117+
expect(mockNavigateToAndOpenReportWithAccountIDs).toHaveBeenCalledWith([42], 1, introSelected, false, betas);
118+
});
119+
120+
it('should call navigateToAndOpenReportWithAccountIDs with isSelfTourViewed=true when self tour has been viewed and accountID is provided', () => {
121+
const introSelected = {choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM};
122+
const action = PromotedActions.message({
123+
accountID: 42,
124+
currentUserAccountID: 1,
125+
introSelected,
126+
isSelfTourViewed: true,
127+
betas: undefined,
128+
});
129+
130+
action.onSelected();
131+
132+
expect(mockNavigateToAndOpenReportWithAccountIDs).toHaveBeenCalledWith([42], 1, introSelected, true, undefined);
118133
});
119134

120135
it('should pass betas to navigateToAndOpenReport when login is provided', () => {

0 commit comments

Comments
 (0)