Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/libs/navigateAfterOnboarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ROUTES from '@src/ROUTES';
import {setDisableDismissOnEscape} from './actions/Modal';
import shouldOpenOnAdminRoom from './Navigation/helpers/shouldOpenOnAdminRoom';
import Navigation from './Navigation/Navigation';
import {findLastAccessedReport, isConciergeChatReport} from './ReportUtils';
import {findLastAccessedReport, isConciergeChatReport, isSelfDM} from './ReportUtils';

const navigateAfterOnboarding = (
isSmallScreenWidth: boolean,
Expand All @@ -26,8 +26,9 @@ const navigateAfterOnboarding = (
} else {
const lastAccessedReport = findLastAccessedReport(!canUseDefaultRooms, shouldOpenOnAdminRoom() && !shouldPreventOpenAdminRoom);
const lastAccessedReportID = lastAccessedReport?.reportID;
// we don't want to navigate to newly created workspaces after onboarding is completed.
if (lastAccessedReportID && lastAccessedReport.policyID !== onboardingPolicyID && !isConciergeChatReport(lastAccessedReport)) {
// We need to send the user to the #admins room from the policy that was created while onboarding, not newly created workspaces nor selfDM chats
// See https://github.com/Expensify/App/issues/61417 and https://github.com/Expensify/App/issues/73559 for more details.
Comment on lines +29 to +30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is a better version of the comment that doesn't require someone to go research those GH issues:

When the user goes through the onboarding flow, a workspace can be created if the user selects specific options. The user should be taken to the #admins room for that workspace because it is the most natural place for them to start their experience in the app. The user should never go to the self DM or the Concierge chat if a workspace was created during the onboarding flow.

While I was writing that, a couple of things occurred to me:

  • This logic is not very readable, I think it would be mroe clear if the logic did an early return for the workspace case:
if (lastAccessedReportID && lastAccessedReport.policyID === onboardingPolicyID) {
    Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(lastAccessedReportID));
    return;
}
  • I think there should always be a return after calling Navigation.navigate(), right? Otherwise, there is a possibility of also running the Navigation.navigate(ROUTES.TEST_DRIVE_MODAL_ROOT.route); trigger too?

if (lastAccessedReportID && lastAccessedReport.policyID !== onboardingPolicyID && !isConciergeChatReport(lastAccessedReport) && !isSelfDM(lastAccessedReport)) {
reportID = lastAccessedReportID;
}
}
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/navigateAfterOnboardingTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jest.mock('@libs/ReportUtils', () => ({
shouldDisplayViolationsRBRInLHN: jest.requireActual<typeof ReportUtils>('@libs/ReportUtils').shouldDisplayViolationsRBRInLHN,
generateIsEmptyReport: jest.requireActual<typeof ReportUtils>('@libs/ReportUtils').generateIsEmptyReport,
isExpenseReport: jest.requireActual<typeof ReportUtils>('@libs/ReportUtils').isExpenseReport,
isSelfDM: jest.requireActual<typeof ReportUtils>('@libs/ReportUtils').isSelfDM,
}));

jest.mock('@libs/Navigation/helpers/shouldOpenOnAdminRoom', () => ({
Expand Down Expand Up @@ -104,6 +105,15 @@ describe('navigateAfterOnboarding', () => {
expect(Navigation.navigate).not.toHaveBeenCalledWith(ROUTES.REPORT_WITH_ID.getRoute(REPORT_ID));
});

it('should not navigate to last accessed report if it is selfDM chat on small screens', () => {
const lastAccessedReport = {reportID: REPORT_ID, chatType: CONST.REPORT.CHAT_TYPE.SELF_DM};
mockFindLastAccessedReport.mockReturnValue(lastAccessedReport);
mockShouldOpenOnAdminRoom.mockReturnValue(false);

navigateAfterOnboarding(true, true, ONBOARDING_POLICY_ID, ONBOARDING_ADMINS_CHAT_REPORT_ID);
expect(Navigation.navigate).not.toHaveBeenCalledWith(ROUTES.REPORT_WITH_ID.getRoute(REPORT_ID));
});

it('should navigate to last accessed report if shouldOpenOnAdminRoom is true on small screens', () => {
const navigate = jest.spyOn(Navigation, 'navigate');
const lastAccessedReport = {reportID: REPORT_ID};
Expand Down
Loading