From c8608be0fbe800a09974cf965b36f3a9a08bf5a9 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Tue, 14 Sep 2021 15:23:44 +0200 Subject: [PATCH 1/2] Don't show global create for new users if has workspace --- src/pages/home/sidebar/SidebarScreen.js | 40 ++++++++++++++++++++----- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/src/pages/home/sidebar/SidebarScreen.js b/src/pages/home/sidebar/SidebarScreen.js index 6201f049a1eb..9d36ad595997 100755 --- a/src/pages/home/sidebar/SidebarScreen.js +++ b/src/pages/home/sidebar/SidebarScreen.js @@ -2,6 +2,7 @@ import React, {Component} from 'react'; import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import PropTypes from 'prop-types'; +import _ from 'underscore'; import styles from '../../../styles/styles'; import SidebarLinks from './SidebarLinks'; import PopoverMenu from '../../../components/PopoverMenu'; @@ -34,11 +35,24 @@ const propTypes = { /* Flag for new users used to open the Global Create menu on first load */ isFirstTimeNewExpensifyUser: PropTypes.bool.isRequired, + /** The list of this user's policies */ + policies: PropTypes.objectOf(PropTypes.shape({ + /** The type of the policy */ + type: PropTypes.string, + + /** The user's role in the policy */ + role: PropTypes.string, + })), + ...windowDimensionsPropTypes, ...withLocalizePropTypes, }; +const defaultProps = { + policies: {}, +}; + class SidebarScreen extends Component { constructor(props) { super(props); @@ -58,13 +72,21 @@ class SidebarScreen extends Component { Timing.start(CONST.TIMING.SIDEBAR_LOADED, true); if (this.props.isFirstTimeNewExpensifyUser) { - // For some reason, the menu doesn't open without the timeout - setTimeout(() => { - this.toggleCreateMenu(); - - // Set the NVP back to false (this may need to be moved if this NVP is used for anything else later) - NameValuePair.set(CONST.NVP.IS_FIRST_TIME_NEW_EXPENSIFY_USER, false, ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER); - }, 200); + const hasFreePolicy = _.chain(this.props.policies) + .some(policy => policy && policy.type === CONST.POLICY.TYPE.FREE && policy.role === CONST.POLICY.ROLE.ADMIN) + .value(); + + // If user doesn't have any free policies (workspaces) set up, automatically open create menu + if (!hasFreePolicy) { + // For some reason, the menu doesn't open without the timeout + setTimeout(() => { + this.toggleCreateMenu(); + }, 200); + } + + // Set the NVP 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 + NameValuePair.set(CONST.NVP.IS_FIRST_TIME_NEW_EXPENSIFY_USER, false, ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER); } } @@ -177,6 +199,7 @@ class SidebarScreen extends Component { } SidebarScreen.propTypes = propTypes; +SidebarScreen.defaultProps = defaultProps; export default compose( withLocalize, withWindowDimensions, @@ -187,5 +210,8 @@ export default compose( isFirstTimeNewExpensifyUser: { key: ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER, }, + policies: { + key: ONYXKEYS.COLLECTION.POLICY, + }, }), )(SidebarScreen); From 0aa2cf2a6708898006385d05eaf6e90cda64c0fc Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Tue, 14 Sep 2021 15:24:00 +0200 Subject: [PATCH 2/2] Fix some comment formatting --- src/pages/home/sidebar/SidebarScreen.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pages/home/sidebar/SidebarScreen.js b/src/pages/home/sidebar/SidebarScreen.js index 9d36ad595997..d1d25b47ed4e 100755 --- a/src/pages/home/sidebar/SidebarScreen.js +++ b/src/pages/home/sidebar/SidebarScreen.js @@ -29,10 +29,12 @@ import Performance from '../../../libs/Performance'; import NameValuePair from '../../../libs/actions/NameValuePair'; const propTypes = { - /* Beta features list */ + /* Onyx Props */ + + /** Beta features list */ betas: PropTypes.arrayOf(PropTypes.string).isRequired, - /* Flag for new users used to open the Global Create menu on first load */ + /** Flag for new users used to open the Global Create menu on first load */ isFirstTimeNewExpensifyUser: PropTypes.bool.isRequired, /** The list of this user's policies */