Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 9 additions & 37 deletions src/pages/home/sidebar/SidebarScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ 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 @@ -29,32 +28,17 @@ import Performance from '../../../libs/Performance';
import NameValuePair from '../../../libs/actions/NameValuePair';

const propTypes = {
/* Onyx Props */

/** Beta features list */
/* 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 @@ -74,21 +58,13 @@ class SidebarScreen extends Component {
Timing.start(CONST.TIMING.SIDEBAR_LOADED, true);

if (this.props.isFirstTimeNewExpensifyUser) {
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);
// 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);
}
}

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

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