Skip to content

Commit 4fc17c7

Browse files
marcaaronOSBotify
authored and
OSBotify
committed
Merge pull request #5394 from Expensify/marcaaron-hideCreateMenuOnNewDotRedirect
Dont toggle create menu if we already have a free policy (cherry picked from commit 8987627)
1 parent 4a683da commit 4fc17c7

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/libs/actions/Policy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ function create(name = '') {
228228
}
229229
res = response;
230230

231+
// We are awaiting this merge so that we can guarantee our policy is available to any React components connected to the policies collection before we navigate to a new route.
231232
return Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${response.policyID}`, {
232233
employeeList: getSimplifiedEmployeeList(response.policy.employeeList),
233234
id: response.policyID,

src/pages/home/sidebar/SidebarScreen.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import _ from 'underscore';
2+
import lodashGet from 'lodash/get';
13
import React, {Component} from 'react';
24
import {View} from 'react-native';
35
import {withOnyx} from 'react-native-onyx';
46
import PropTypes from 'prop-types';
7+
import {withNavigation} from '@react-navigation/compat';
58
import styles from '../../../styles/styles';
69
import SidebarLinks from './SidebarLinks';
710
import PopoverMenu from '../../../components/PopoverMenu';
@@ -61,7 +64,17 @@ class SidebarScreen extends Component {
6164
// This is a short-term workaround, see this issue for updates on a long-term solution: https://github.com/Expensify/App/issues/5296
6265
setTimeout(() => {
6366
if (this.props.isFirstTimeNewExpensifyUser) {
64-
this.toggleCreateMenu();
67+
// 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
68+
// create menu right now.
69+
const routes = lodashGet(this.props.navigation.getState(), 'routes', []);
70+
const topRouteName = lodashGet(_.last(routes), 'name', '');
71+
const isDisplayingWorkspaceRoute = topRouteName.toLowerCase().includes('workspace');
72+
73+
// 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
74+
// not need to create a workspace.
75+
if (!isAdminOfFreePolicy(this.props.allPolicies) && !isDisplayingWorkspaceRoute) {
76+
this.toggleCreateMenu();
77+
}
6578

6679
// Set the NVP back to false so we don't automatically open the menu again
6780
// Note: this may need to be moved if this NVP is used for anything else later
@@ -180,6 +193,7 @@ class SidebarScreen extends Component {
180193

181194
SidebarScreen.propTypes = propTypes;
182195
export default compose(
196+
withNavigation,
183197
withLocalize,
184198
withWindowDimensions,
185199
withOnyx({

0 commit comments

Comments
 (0)