From 61cf59552a4459ad92b52c3e245c566dc3aa171a Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Tue, 21 Sep 2021 08:16:12 -1000 Subject: [PATCH 1/3] Dont toggle create menu if we already have a free policy --- src/pages/home/sidebar/SidebarScreen.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pages/home/sidebar/SidebarScreen.js b/src/pages/home/sidebar/SidebarScreen.js index 437cec2766ca..7a296a4923d2 100755 --- a/src/pages/home/sidebar/SidebarScreen.js +++ b/src/pages/home/sidebar/SidebarScreen.js @@ -61,7 +61,11 @@ class SidebarScreen extends Component { // This is a short-term workaround, see this issue for updates on a long-term solution: https://github.com/Expensify/App/issues/5296 setTimeout(() => { if (this.props.isFirstTimeNewExpensifyUser) { - this.toggleCreateMenu(); + // If we are getting redirected here and already have a workspace policy then do not show the create menu. We will also want to set the NVP in this case since the user does + // not need to create a workspace. + if (!isAdminOfFreePolicy(this.props.allPolicies)) { + this.toggleCreateMenu(); + } // Set the NVP back to false so we don't automatically open the menu again // Note: this may need to be moved if this NVP is used for anything else later From 3ad46190a1c6df5f62c9ea732c981cea9e619761 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Tue, 21 Sep 2021 08:20:25 -1000 Subject: [PATCH 2/3] Add comment to explain why we are waiting for the merge to happen --- src/libs/actions/Policy.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index acb4d445492d..b2d7b12f1534 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -228,6 +228,7 @@ function create(name = '') { } res = response; + // 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. return Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${response.policyID}`, { employeeList: getSimplifiedEmployeeList(response.policy.employeeList), id: response.policyID, From 7d802e07427c3299a117c0636f51a24bfc3d1f37 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Wed, 22 Sep 2021 10:59:14 -1000 Subject: [PATCH 3/3] check route name and do not open global create menu --- src/pages/home/sidebar/SidebarScreen.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/pages/home/sidebar/SidebarScreen.js b/src/pages/home/sidebar/SidebarScreen.js index 7a296a4923d2..725d30e898c1 100755 --- a/src/pages/home/sidebar/SidebarScreen.js +++ b/src/pages/home/sidebar/SidebarScreen.js @@ -1,7 +1,10 @@ +import _ from 'underscore'; +import lodashGet from 'lodash/get'; import React, {Component} from 'react'; import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import PropTypes from 'prop-types'; +import {withNavigation} from '@react-navigation/compat'; import styles from '../../../styles/styles'; import SidebarLinks from './SidebarLinks'; import PopoverMenu from '../../../components/PopoverMenu'; @@ -61,9 +64,15 @@ class SidebarScreen extends Component { // This is a short-term workaround, see this issue for updates on a long-term solution: https://github.com/Expensify/App/issues/5296 setTimeout(() => { if (this.props.isFirstTimeNewExpensifyUser) { - // If we are getting redirected here and already have a workspace policy then do not show the create menu. We will also want to set the NVP in this case since the user does + // 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 routes = lodashGet(this.props.navigation.getState(), 'routes', []); + const topRouteName = lodashGet(_.last(routes), 'name', ''); + const isDisplayingWorkspaceRoute = topRouteName.toLowerCase().includes('workspace'); + + // 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 (!isAdminOfFreePolicy(this.props.allPolicies)) { + if (!isAdminOfFreePolicy(this.props.allPolicies) && !isDisplayingWorkspaceRoute) { this.toggleCreateMenu(); } @@ -184,6 +193,7 @@ class SidebarScreen extends Component { SidebarScreen.propTypes = propTypes; export default compose( + withNavigation, withLocalize, withWindowDimensions, withOnyx({