Skip to content

Commit

Permalink
Merge pull request #5244 from Expensify/beaman-skipShowingCreateForNe…
Browse files Browse the repository at this point in the history
…wUsersIfHasWorkspace

Skip showing create for new users if user already has a workspace
  • Loading branch information
robertjchen authored Sep 15, 2021
2 parents 1f0436c + 0aa2cf2 commit 09e2d94
Showing 1 changed file with 37 additions and 9 deletions.
46 changes: 37 additions & 9 deletions src/pages/home/sidebar/SidebarScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -28,17 +29,32 @@ 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 */
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);
Expand All @@ -58,13 +74,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);
}
}

Expand Down Expand Up @@ -177,6 +201,7 @@ class SidebarScreen extends Component {
}

SidebarScreen.propTypes = propTypes;
SidebarScreen.defaultProps = defaultProps;
export default compose(
withLocalize,
withWindowDimensions,
Expand All @@ -187,5 +212,8 @@ export default compose(
isFirstTimeNewExpensifyUser: {
key: ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER,
},
policies: {
key: ONYXKEYS.COLLECTION.POLICY,
},
}),
)(SidebarScreen);

0 comments on commit 09e2d94

Please sign in to comment.