Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip showing create for new users if user already has a workspace #5244

Merged
merged 2 commits into from
Sep 15, 2021
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: 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤮 we should figure out how to do this without a setTimeout these hacks end up biting us later down the road because anything else that depends on this code then will have to use a timeout/delay to push it's rendering to the end of the stack.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This setTimeout is currently our only solution for auto-opening the global create on load, I made this issue for people to look into solutions - read the discussions, it's not a straightforward solutions sadly :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We even increased from 200 ms to 1500 ms here: #5369

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't say one comment from a contributor is an "exhaustive" discussion on how best to fix this 😅 but I do agree with Rory's comment so did we ever follow up with react-navigation on this?

Copy link
Contributor Author

@Beamanator Beamanator Sep 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL I meant this issue: #5303 :D (many more comments haha)

}

// 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);