Skip to content

Commit 05f2b34

Browse files
authored
Merge pull request Expensify#73749 from paulnjs/paulnjs-fix/73056
FAB - “Test drive” task sound plays twice
2 parents aa66369 + 46e908d commit 05f2b34

5 files changed

Lines changed: 22 additions & 61 deletions

File tree

src/components/TestDrive/TestDriveDemo.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout';
1212
import useThemeStyles from '@hooks/useThemeStyles';
1313
import {completeTestDriveTask} from '@libs/actions/Task';
1414
import Navigation from '@libs/Navigation/Navigation';
15+
import {hasSeenTourSelector} from '@libs/onboardingSelectors';
1516
import {isPaidGroupPolicy, isPolicyAdmin} from '@libs/PolicyUtils';
1617
import {isAdminRoom} from '@libs/ReportUtils';
1718
import {getTestDriveURL} from '@libs/TourUtils';
@@ -39,11 +40,22 @@ function TestDriveDemo() {
3940
selector: (policies) => Object.values(policies ?? {}).some((policy) => isPaidGroupPolicy(policy) && isPolicyAdmin(policy, currentUserPersonalDetails.login)),
4041
});
4142

43+
const [hasSeenTour = false] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {
44+
selector: hasSeenTourSelector,
45+
canBeMissing: true,
46+
});
47+
48+
useEffect(() => {
49+
if (hasSeenTour) {
50+
return;
51+
}
52+
completeTestDriveTask(viewTourTaskReport, viewTourTaskParentReport, isViewTourTaskParentReportArchived, currentUserPersonalDetails.accountID);
53+
}, [hasSeenTour]);
54+
4255
useEffect(() => {
4356
// eslint-disable-next-line @typescript-eslint/no-deprecated
4457
InteractionManager.runAfterInteractions(() => {
4558
setIsVisible(true);
46-
completeTestDriveTask(viewTourTaskReport, viewTourTaskParentReport, isViewTourTaskParentReportArchived, currentUserPersonalDetails.accountID);
4759
});
4860

4961
// This should fire only during mount.

src/libs/actions/Tour.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
import {InteractionManager} from 'react-native';
2-
import type {OnyxEntry} from 'react-native-onyx';
32
import Navigation from '@libs/Navigation/Navigation';
43
import CONST from '@src/CONST';
54
import ROUTES from '@src/ROUTES';
6-
import type * as OnyxTypes from '@src/types/onyx';
75
import type {IntroSelected} from './Report';
8-
import {completeTestDriveTask} from './Task';
96

10-
function startTestDrive(
11-
introSelected: IntroSelected | undefined,
12-
shouldUpdateSelfTourViewedOnlyLocally: boolean,
13-
hasUserBeenAddedToNudgeMigration: boolean,
14-
isUserPaidPolicyMember: boolean,
15-
viewTourTaskReport: OnyxEntry<OnyxTypes.Report>,
16-
viewTourTaskParentReport: OnyxEntry<OnyxTypes.Report>,
17-
isViewTourTaskParentReportArchived: boolean,
18-
currentUserAccountID: number,
19-
) {
7+
function startTestDrive(introSelected: IntroSelected | undefined, hasUserBeenAddedToNudgeMigration: boolean, isUserPaidPolicyMember: boolean) {
208
// eslint-disable-next-line @typescript-eslint/no-deprecated
219
InteractionManager.runAfterInteractions(() => {
2210
if (
@@ -27,7 +15,6 @@ function startTestDrive(
2715
introSelected?.choice === CONST.ONBOARDING_CHOICES.TRACK_WORKSPACE ||
2816
(introSelected?.choice === CONST.ONBOARDING_CHOICES.SUBMIT && introSelected.inviteType === CONST.ONBOARDING_INVITE_TYPES.WORKSPACE)
2917
) {
30-
completeTestDriveTask(viewTourTaskReport, viewTourTaskParentReport, isViewTourTaskParentReportArchived, currentUserAccountID, shouldUpdateSelfTourViewedOnlyLocally);
3118
Navigation.navigate(ROUTES.TEST_DRIVE_DEMO_ROOT);
3219
} else {
3320
Navigation.navigate(ROUTES.TEST_DRIVE_MODAL_ROOT.route);

src/pages/Search/EmptySearchView.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -339,16 +339,7 @@ function EmptySearchViewContent({
339339
}
340340

341341
const startTestDriveAction = () => {
342-
startTestDrive(
343-
introSelected,
344-
false,
345-
tryNewDot?.hasBeenAddedToNudgeMigration ?? false,
346-
isUserPaidPolicyMember,
347-
viewTourTaskReport,
348-
viewTourTaskParentReport,
349-
isViewTourTaskParentReportArchived,
350-
currentUserPersonalDetails.accountID,
351-
);
342+
startTestDrive(introSelected, tryNewDot?.hasBeenAddedToNudgeMigration ?? false, isUserPaidPolicyMember);
352343
};
353344

354345
// If we didn't match a specific search hash, show a specific message based on the type of the data

src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import useCreateEmptyReportConfirmation from '@hooks/useCreateEmptyReportConfirm
1717
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
1818
import useLocalize from '@hooks/useLocalize';
1919
import useNetwork from '@hooks/useNetwork';
20-
import useOnboardingTaskInformation from '@hooks/useOnboardingTaskInformation';
2120
import useOnyx from '@hooks/useOnyx';
2221
import usePermissions from '@hooks/usePermissions';
2322
import usePreferredPolicy from '@hooks/usePreferredPolicy';
@@ -31,7 +30,6 @@ import {startDistanceRequest, startMoneyRequest} from '@libs/actions/IOU';
3130
import {openOldDotLink} from '@libs/actions/Link';
3231
import {navigateToQuickAction} from '@libs/actions/QuickActionNavigation';
3332
import {createNewReport, startNewChat} from '@libs/actions/Report';
34-
import {isAnonymousUser} from '@libs/actions/Session';
3533
import {startTestDrive} from '@libs/actions/Tour';
3634
import getIconForAction from '@libs/getIconForAction';
3735
import interceptAnonymousUser from '@libs/interceptAnonymousUser';
@@ -180,12 +178,6 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, ref
180178
});
181179
const reportID = useMemo(() => generateReportID(), []);
182180

183-
const {
184-
taskReport: viewTourTaskReport,
185-
taskParentReport: viewTourTaskParentReport,
186-
isOnboardingTaskParentReportArchived: isViewTourTaskParentReportArchived,
187-
} = useOnboardingTaskInformation(CONST.ONBOARDING_TASK_TYPE.VIEW_TOUR);
188-
189181
const isReportInSearch = isOnSearchMoneyRequestReportPage();
190182
const groupPoliciesWithChatEnabled = getGroupPaidPoliciesWithExpenseChatEnabled(allPolicies as OnyxCollection<OnyxTypes.Policy>);
191183

@@ -606,19 +598,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, ref
606598
iconStyles: styles.popoverIconCircle,
607599
iconFill: theme.icon,
608600
text: translate('testDrive.quickAction.takeATwoMinuteTestDrive'),
609-
onSelected: () =>
610-
interceptAnonymousUser(() =>
611-
startTestDrive(
612-
introSelected,
613-
isAnonymousUser(),
614-
tryNewDot?.hasBeenAddedToNudgeMigration ?? false,
615-
isUserPaidPolicyMember,
616-
viewTourTaskReport,
617-
viewTourTaskParentReport,
618-
isViewTourTaskParentReportArchived,
619-
currentUserPersonalDetails.accountID,
620-
),
621-
),
601+
onSelected: () => interceptAnonymousUser(() => startTestDrive(introSelected, tryNewDot?.hasBeenAddedToNudgeMigration ?? false, isUserPaidPolicyMember)),
622602
},
623603
]
624604
: []),

tests/actions/TourTest.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ describe('actions/Tour', () => {
3838
describe('startTestDrive', () => {
3939
describe('migrated users', () => {
4040
it('should show the Test Drive demo if user has been nudged to migrate', async () => {
41-
startTestDrive(undefined, false, true, false, undefined, undefined, false, 2);
41+
startTestDrive(undefined, true, false);
4242
await waitForBatchedUpdates();
4343

4444
expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.TEST_DRIVE_DEMO_ROOT);
4545
});
4646

4747
it("should show the Test Drive demo if user doesn't have the nudge flag but is member of a paid policy", async () => {
48-
startTestDrive(undefined, false, false, true, undefined, undefined, false, 2);
48+
startTestDrive(undefined, false, true);
4949
await waitForBatchedUpdates();
5050

5151
expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.TEST_DRIVE_DEMO_ROOT);
@@ -86,14 +86,14 @@ describe('actions/Tour', () => {
8686
it.each(onboardingChoices.filter((choice) => onboardingDemoChoices.includes(choice)))('should show the Test Drive demo if user has "%s" onboarding choice', async (choice) => {
8787
await setTestDriveTaskData();
8888

89-
startTestDrive({choice}, false, false, false, testDriveTaskReport, conciergeChatReport, false, accountID);
89+
startTestDrive({choice}, false, false);
9090
await waitForBatchedUpdates();
9191

9292
expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.TEST_DRIVE_DEMO_ROOT);
9393
});
9494

9595
it.each(onboardingChoices.filter((choice) => !onboardingDemoChoices.includes(choice)))('should show the Test Drive modal if user has "%s" onboarding choice', async (choice) => {
96-
startTestDrive({choice}, false, false, false, undefined, undefined, false, accountID);
96+
startTestDrive({choice}, false, false);
9797
await waitForBatchedUpdates();
9898

9999
expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.TEST_DRIVE_MODAL_ROOT.route);
@@ -102,23 +102,14 @@ describe('actions/Tour', () => {
102102
it('should show the Test Drive demo if user is an invited employee', async () => {
103103
await setTestDriveTaskData();
104104

105-
startTestDrive(
106-
{choice: CONST.ONBOARDING_CHOICES.SUBMIT, inviteType: CONST.ONBOARDING_INVITE_TYPES.WORKSPACE},
107-
false,
108-
false,
109-
false,
110-
testDriveTaskReport,
111-
conciergeChatReport,
112-
false,
113-
accountID,
114-
);
105+
startTestDrive({choice: CONST.ONBOARDING_CHOICES.SUBMIT, inviteType: CONST.ONBOARDING_INVITE_TYPES.WORKSPACE}, false, false);
115106
await waitForBatchedUpdates();
116107

117108
expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.TEST_DRIVE_DEMO_ROOT);
118109
});
119110

120111
it('should show the Test Drive demo if user is member of a paid policy', async () => {
121-
startTestDrive({choice: CONST.ONBOARDING_CHOICES.LOOKING_AROUND}, false, false, true, testDriveTaskReport, conciergeChatReport, false, accountID);
112+
startTestDrive({choice: CONST.ONBOARDING_CHOICES.LOOKING_AROUND}, false, true);
122113
await waitForBatchedUpdates();
123114

124115
expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.TEST_DRIVE_DEMO_ROOT);

0 commit comments

Comments
 (0)