diff --git a/src/hooks/useCreateEmptyReportConfirmation.tsx b/src/hooks/useCreateEmptyReportConfirmation.tsx index 5c71cf309c58c..af9590271bccf 100644 --- a/src/hooks/useCreateEmptyReportConfirmation.tsx +++ b/src/hooks/useCreateEmptyReportConfirmation.tsx @@ -21,6 +21,8 @@ type UseCreateEmptyReportConfirmationParams = { onConfirm: (shouldDismissEmptyReportsConfirmation: boolean) => void; /** Optional callback function to execute when user cancels the confirmation */ onCancel?: () => void; + /** Whether the modal should push a history entry so browser-back dismisses it (default: true) */ + shouldHandleNavigationBack?: boolean; }; type UseCreateEmptyReportConfirmationResult = { @@ -54,7 +56,12 @@ function ConfirmationPrompt({workspaceName, checkboxRef, onLinkPress}: {workspac ); } -export default function useCreateEmptyReportConfirmation({policyName, onConfirm, onCancel}: UseCreateEmptyReportConfirmationParams): UseCreateEmptyReportConfirmationResult { +export default function useCreateEmptyReportConfirmation({ + policyName, + onConfirm, + onCancel, + shouldHandleNavigationBack = true, +}: UseCreateEmptyReportConfirmationParams): UseCreateEmptyReportConfirmationResult { const {translate} = useLocalize(); const {showConfirmModal, closeModal} = useConfirmModal(); const workspaceDisplayName = policyName?.trim().length ? policyName : translate('report.newReport.genericWorkspaceName'); @@ -79,6 +86,7 @@ export default function useCreateEmptyReportConfirmation({policyName, onConfirm, title: `${translate('report.newReport.emptyReportConfirmationTitle')} `, confirmText: translate('report.newReport.createReport'), cancelText: translate('common.cancel'), + shouldHandleNavigationBack, prompt: ( { - const shouldNavigateToDemo = - hasUserBeenAddedToNudgeMigration || - isUserPaidPolicyMember || - introSelected?.choice === CONST.ONBOARDING_CHOICES.MANAGE_TEAM || - introSelected?.choice === CONST.ONBOARDING_CHOICES.TEST_DRIVE_RECEIVER || - introSelected?.choice === CONST.ONBOARDING_CHOICES.TRACK_WORKSPACE || - (introSelected?.choice === CONST.ONBOARDING_CHOICES.SUBMIT && introSelected.inviteType === CONST.ONBOARDING_INVITE_TYPES.WORKSPACE); - - if (shouldNavigateToDemo) { - Navigation.navigate(ROUTES.TEST_DRIVE_DEMO_ROOT); - return; - } - Navigation.navigate(ROUTES.TEST_DRIVE_DEMO_ROOT); - }); +function startTestDrive() { + Navigation.navigate(ROUTES.TEST_DRIVE_DEMO_ROOT); } // eslint-disable-next-line import/prefer-default-export diff --git a/src/pages/Search/EmptySearchView.tsx b/src/pages/Search/EmptySearchView.tsx index 05eba3789520b..4ea48132f66c1 100644 --- a/src/pages/Search/EmptySearchView.tsx +++ b/src/pages/Search/EmptySearchView.tsx @@ -1,4 +1,4 @@ -import {hasSeenTourSelector, tryNewDotOnyxSelector} from '@selectors/Onboarding'; +import {hasSeenTourSelector} from '@selectors/Onboarding'; import {accountIDSelector} from '@selectors/Session'; import {validTransactionDraftIDsSelector} from '@selectors/TransactionDraft'; import React from 'react'; @@ -19,7 +19,6 @@ import useConfirmModal from '@hooks/useConfirmModal'; import useCreateEmptyReportConfirmation from '@hooks/useCreateEmptyReportConfirmation'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useHasEmptyReportsForPolicy from '@hooks/useHasEmptyReportsForPolicy'; -import useIsPaidPolicyAdmin from '@hooks/useIsPaidPolicyAdmin'; import {useMemoizedLazyIllustrations} from '@hooks/useLazyAsset'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; @@ -40,7 +39,7 @@ import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import type {IntroSelected, PersonalDetails, Policy, Report, Transaction} from '@src/types/onyx'; +import type {PersonalDetails, Policy, Report, Transaction} from '@src/types/onyx'; import type {SearchDataTypes} from '@src/types/onyx/SearchResults'; import useSearchEmptyStateIllustration from './useSearchEmptyStateIllustration'; @@ -55,10 +54,8 @@ type EmptySearchViewContentProps = EmptySearchViewProps & { currentUserPersonalDetails: PersonalDetails; typeMenuSections: SearchTypeMenuSection[]; allPolicies: OnyxCollection; - isUserPaidPolicyMember: boolean; activePolicy: OnyxEntry; groupPoliciesWithChatEnabled: readonly never[] | Array>; - introSelected: OnyxEntry; hasSeenTour: boolean; }; @@ -84,13 +81,10 @@ function EmptySearchView({similarSearchHash, type, hasResults, queryJSON}: Empty const groupPoliciesWithChatEnabled = getGroupPaidPoliciesWithExpenseChatEnabled(allPolicies); - const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED); const [hasSeenTour = false] = useOnyx(ONYXKEYS.NVP_ONBOARDING, { selector: hasSeenTourSelector, }); - const isUserPaidPolicyMember = useIsPaidPolicyAdmin(); - return ( @@ -124,10 +116,8 @@ function EmptySearchViewContent({ currentUserPersonalDetails, typeMenuSections, allPolicies, - isUserPaidPolicyMember, activePolicy, groupPoliciesWithChatEnabled, - introSelected, hasSeenTour, queryJSON, }: EmptySearchViewContentProps) { @@ -154,10 +144,6 @@ function EmptySearchViewContent({ selector: hasExpenseReportsSelector, }); - const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRY_NEW_DOT, { - selector: tryNewDotOnyxSelector, - }); - const shouldRedirectToExpensifyClassic = areAllGroupPoliciesExpenseChatDisabled(allPolicies ?? {}); const defaultChatEnabledPolicy = getDefaultChatEnabledPolicy(groupPoliciesWithChatEnabled as Array>, activePolicy); @@ -245,7 +231,7 @@ function EmptySearchViewContent({ const defaultViewItemHeader = useSearchEmptyStateIllustration(); const startTestDriveAction = () => { - startTestDrive(introSelected, tryNewDot?.hasBeenAddedToNudgeMigration ?? false, isUserPaidPolicyMember); + startTestDrive(); }; let content: EmptySearchViewItem | undefined; diff --git a/src/pages/inbox/sidebar/FABPopoverContent/FABPopoverMenu.tsx b/src/pages/inbox/sidebar/FABPopoverContent/FABPopoverMenu.tsx index d60334b041d8a..8310371221802 100644 --- a/src/pages/inbox/sidebar/FABPopoverContent/FABPopoverMenu.tsx +++ b/src/pages/inbox/sidebar/FABPopoverContent/FABPopoverMenu.tsx @@ -74,6 +74,11 @@ function FABPopoverMenu({isVisible, onClose, onItemSelected, anchorRef, animatio isActive: isVisible, }); + const handleClose = () => { + setFocusedIndex(-1); + onClose(); + }; + const onItemPress = (onSelected: () => void, options?: {shouldCallAfterModalHide?: boolean}) => { onItemSelected(); if (options?.shouldCallAfterModalHide && !isSafari()) { @@ -105,7 +110,7 @@ function FABPopoverMenu({isVisible, onClose, onItemSelected, anchorRef, animatio horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT, vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM, }} - onClose={onClose} + onClose={handleClose} isVisible={isVisible} fromSidebarMediumScreen={!shouldUseNarrowLayout} animationIn="fadeIn" diff --git a/src/pages/inbox/sidebar/FABPopoverContent/menuItems/CreateReportMenuItem.tsx b/src/pages/inbox/sidebar/FABPopoverContent/menuItems/CreateReportMenuItem.tsx index d4a2c55a443fe..5b951ccbdb934 100644 --- a/src/pages/inbox/sidebar/FABPopoverContent/menuItems/CreateReportMenuItem.tsx +++ b/src/pages/inbox/sidebar/FABPopoverContent/menuItems/CreateReportMenuItem.tsx @@ -112,6 +112,7 @@ function CreateReportMenuItem() { policyID: defaultChatEnabledPolicyID, policyName: defaultChatEnabledPolicy?.name ?? '', onConfirm: handleCreateWorkspaceReport, + shouldHandleNavigationBack: false, }); return ( diff --git a/src/pages/inbox/sidebar/FABPopoverContent/menuItems/TestDriveMenuItem.tsx b/src/pages/inbox/sidebar/FABPopoverContent/menuItems/TestDriveMenuItem.tsx index bfaa7514f9967..ca7eb4fa3a389 100644 --- a/src/pages/inbox/sidebar/FABPopoverContent/menuItems/TestDriveMenuItem.tsx +++ b/src/pages/inbox/sidebar/FABPopoverContent/menuItems/TestDriveMenuItem.tsx @@ -1,6 +1,5 @@ -import {hasSeenTourSelector, tryNewDotOnyxSelector} from '@selectors/Onboarding'; +import {hasSeenTourSelector} from '@selectors/Onboarding'; import React from 'react'; -import useIsPaidPolicyAdmin from '@hooks/useIsPaidPolicyAdmin'; import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; @@ -20,9 +19,6 @@ function TestDriveMenuItem() { const theme = useTheme(); const icons = useMemoizedLazyExpensifyIcons(['Binoculars'] as const); const [hasSeenTour = false] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector}); - const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED); - const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRY_NEW_DOT, {selector: tryNewDotOnyxSelector}); - const isUserPaidPolicyMember = useIsPaidPolicyAdmin(); const isVisible = !hasSeenTour; return ( @@ -34,7 +30,7 @@ function TestDriveMenuItem() { iconStyles={styles.popoverIconCircle} iconFill={theme.icon} title={translate('testDrive.quickAction.takeATwoMinuteTestDrive')} - onPress={() => interceptAnonymousUser(() => startTestDrive(introSelected, tryNewDot?.hasBeenAddedToNudgeMigration ?? false, isUserPaidPolicyMember))} + onPress={() => interceptAnonymousUser(() => startTestDrive())} /> ); } diff --git a/tests/actions/TourTest.ts b/tests/actions/TourTest.ts index 63355e80b3a22..cb7c45aa461a1 100644 --- a/tests/actions/TourTest.ts +++ b/tests/actions/TourTest.ts @@ -2,15 +2,10 @@ import Onyx from 'react-native-onyx'; import OnyxUpdateManager from '@libs/actions/OnyxUpdateManager'; import {startTestDrive} from '@libs/actions/Tour'; import Navigation from '@libs/Navigation/Navigation'; -import Parser from '@libs/Parser'; import initOnyxDerivedValues from '@userActions/OnyxDerived'; -import CONST from '@src/CONST'; import * as SequentialQueue from '@src/libs/Network/SequentialQueue'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import type {OnboardingPurpose, Report, ReportAction} from '@src/types/onyx'; -import type {ReportActionsCollectionDataSet} from '@src/types/onyx/ReportAction'; -import * as LHNTestUtils from '../utils/LHNTestUtils'; import * as TestHelper from '../utils/TestHelper'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; @@ -36,89 +31,11 @@ describe('actions/Tour', () => { }); describe('startTestDrive', () => { - describe('migrated users', () => { - it('should show the Test Drive demo if user has been nudged to migrate', async () => { - startTestDrive(undefined, true, false); - await waitForBatchedUpdates(); + it('should navigate to the Test Drive demo screen', async () => { + startTestDrive(); + await waitForBatchedUpdates(); - expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.TEST_DRIVE_DEMO_ROOT); - }); - - it("should show the Test Drive demo if user doesn't have the nudge flag but is member of a paid policy", async () => { - startTestDrive(undefined, false, true); - await waitForBatchedUpdates(); - - expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.TEST_DRIVE_DEMO_ROOT); - }); - }); - - describe('NewDot users', () => { - const onboardingChoices = Object.values(CONST.ONBOARDING_CHOICES); - const onboardingDemoChoices = new Set([ - CONST.ONBOARDING_CHOICES.MANAGE_TEAM, - CONST.ONBOARDING_CHOICES.TEST_DRIVE_RECEIVER, - CONST.ONBOARDING_CHOICES.TRACK_WORKSPACE, - ]); - const accountID = 2; - const conciergeChatReport: Report = LHNTestUtils.getFakeReport([accountID, CONST.ACCOUNT_ID.CONCIERGE]); - const testDriveTaskReport: Report = {...LHNTestUtils.getFakeReport(), ownerAccountID: accountID}; - - let testDriveTaskAction: ReportAction; - const setTestDriveTaskData = async () => { - testDriveTaskAction = { - ...LHNTestUtils.getFakeReportAction(), - childType: CONST.REPORT.TYPE.TASK, - childReportName: Parser.replace( - TestHelper.translateLocal('onboarding.testDrive.name', {testDriveURL: `${CONST.STAGING_NEW_EXPENSIFY_URL}/${ROUTES.TEST_DRIVE_DEMO_ROOT}`}), - ), - childReportID: testDriveTaskReport.reportID, - }; - - const reportActionsCollectionDataSet: ReportActionsCollectionDataSet = { - [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${conciergeChatReport.reportID}`]: { - [testDriveTaskAction.reportActionID]: testDriveTaskAction, - }, - }; - - await Onyx.multiSet({ - ...reportActionsCollectionDataSet, - [ONYXKEYS.SESSION]: { - accountID, - }, - }); - }; - - it.each(onboardingChoices.filter((choice) => onboardingDemoChoices.has(choice)))('should show the Test Drive demo if user has "%s" onboarding choice', async (choice) => { - await setTestDriveTaskData(); - - startTestDrive({choice}, false, false); - await waitForBatchedUpdates(); - - expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.TEST_DRIVE_DEMO_ROOT); - }); - - it.each(onboardingChoices.filter((choice) => !onboardingDemoChoices.has(choice)))('should show the Test Drive demo if user has "%s" onboarding choice', async (choice) => { - startTestDrive({choice}, false, false); - await waitForBatchedUpdates(); - - expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.TEST_DRIVE_DEMO_ROOT); - }); - - it('should show the Test Drive demo if user is an invited employee', async () => { - await setTestDriveTaskData(); - - startTestDrive({choice: CONST.ONBOARDING_CHOICES.SUBMIT, inviteType: CONST.ONBOARDING_INVITE_TYPES.WORKSPACE}, false, false); - await waitForBatchedUpdates(); - - expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.TEST_DRIVE_DEMO_ROOT); - }); - - it('should show the Test Drive demo if user is member of a paid policy', async () => { - startTestDrive({choice: CONST.ONBOARDING_CHOICES.LOOKING_AROUND}, false, true); - await waitForBatchedUpdates(); - - expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.TEST_DRIVE_DEMO_ROOT); - }); + expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.TEST_DRIVE_DEMO_ROOT); }); }); });