Skip to content

Commit

Permalink
Stay on the workspace route during welcome action
Browse files Browse the repository at this point in the history
  • Loading branch information
neil-marcellini committed Apr 26, 2022
1 parent 28ac0a8 commit 80e0143
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/libs/actions/WelcomeActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as Policy from './Policy';
import ONYXKEYS from '../../ONYXKEYS';
import NameValuePair from './NameValuePair';
import CONST from '../../CONST';
import Log from '../Log';

/* Flag for new users used to show welcome actions on first load */
let isFirstTimeNewExpensifyUser = false;
Expand Down Expand Up @@ -58,20 +59,22 @@ function show({routes, toggleCreateMenu}) {
// Set the NVP back to false so we don't automatically run welcome actions again
NameValuePair.set(CONST.NVP.IS_FIRST_TIME_NEW_EXPENSIFY_USER, false, ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER);

// We want to display the Workspace chat first since that means a user is already in a Workspace and doesn't need to create another one
const workspaceChatReport = _.find(allReports, report => ReportUtils.isPolicyExpenseChat(report));
if (workspaceChatReport) {
Navigation.navigate(ROUTES.getReportRoute(workspaceChatReport.reportID));
return;
}

// If we are rendering the SidebarScreen at the same time as a workspace route that means we've already created a workspace via workspace/new and should not open the global
// create menu right now.
const topRouteName = lodashGet(_.last(routes), 'name', '');
const loginWithShortLivedTokenRoute = _.find(routes, route => route.name === 'LogInWithShortLivedToken');
const exitingToWorkspaceRoute = lodashGet(loginWithShortLivedTokenRoute, 'params.exitTo', '') === 'workspace/new';
const isDisplayingWorkspaceRoute = topRouteName.toLowerCase().includes('workspace') || exitingToWorkspaceRoute;

// We want to display the Workspace chat first since that means a user is already in a Workspace and doesn't need to create another one
// Only navigate to the workspace chat if we are not displaying a workspace route
const workspaceChatReport = _.find(allReports, report => ReportUtils.isPolicyExpenseChat(report));
if (workspaceChatReport && !isDisplayingWorkspaceRoute) {
Log.info('[WelcomeActions] Navigating to the workspace chat report');
Navigation.navigate(ROUTES.getReportRoute(workspaceChatReport.reportID));
return;
}

// It's also possible that we already have a workspace policy. In either case we will not toggle the menu but do still want to set the NVP in this case
// since the user does not need to create a workspace.
if (!Policy.isAdminOfFreePolicy(allPolicies) && !isDisplayingWorkspaceRoute) {
Expand Down

0 comments on commit 80e0143

Please sign in to comment.