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

[No QA] Show Workspace Chat first instead of opening Global Create #7865

Merged
merged 8 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
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
84 changes: 84 additions & 0 deletions src/libs/actions/WelcomeActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import Onyx from 'react-native-onyx';
import _ from 'underscore';
import lodashGet from 'lodash/get';
import Navigation from '../Navigation/Navigation';
import * as ReportUtils from '../reportUtils';
import ROUTES from '../../ROUTES';
import * as Policy from './Policy';
import ONYXKEYS from '../../ONYXKEYS';
import NameValuePair from './NameValuePair';
import CONST from '../../CONST';

/* Flag for new users used to show welcome actions on first load */
let isFirstTimeNewExpensifyUser = false;
Onyx.connect({
key: ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER,
callback: val => isFirstTimeNewExpensifyUser = val,
});

const allReports = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
callback: (val, key) => {
if (!val || !key) {
return;
}

allReports[key] = {...allReports[key], ...val};
},
});

const allPolicies = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
callback: (val, key) => {
if (!val || !key) {
return;
}

allPolicies[key] = {...allPolicies[key], ...val};
},
});

/**
* Shows a welcome action on first login
*
* @param {Object} params
* @param {Object} params.routes
* @param {Function} params.toggleCreateMenu
*/
function show({routes, toggleCreateMenu}) {
// NOTE: This setTimeout is required due to a bug in react-navigation where modals do not display properly in a drawerContent
// 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 (!isFirstTimeNewExpensifyUser) {
return;
}

// Set the NVP back to false so we don't automatically run welcome actions again
NameValuePair.set(CONST.NVP.IS_FIRST_TIME_NEW_EXPENSIFY_USER, false, ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER);

// We want to display the Workspace chat first since that means a user is already in a Workspace and doesn't need to create another one
const workspaceChatReport = _.find(allReports, report => ReportUtils.isPolicyExpenseChat(report));
if (workspaceChatReport) {
Navigation.navigate(ROUTES.getReportRoute(workspaceChatReport.reportID));
return;
}

// 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 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 (!Policy.isAdminOfFreePolicy(allPolicies) && !isDisplayingWorkspaceRoute) {
toggleCreateMenu();
}
}, 1500);
}

export {
// eslint-disable-next-line import/prefer-default-export
show,
};
2 changes: 1 addition & 1 deletion src/pages/home/HeaderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const HeaderView = (props) => {
</Pressable>
</Tooltip>
)}
{props.report && props.report.reportName && (
{Boolean(props.report && props.report.reportName) && (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this to fix a RN error that I was seeing where text is a child of View

Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't seen it done like this, good thinking.

<View
style={[
styles.flex1,
Expand Down
35 changes: 3 additions & 32 deletions src/pages/home/sidebar/SidebarScreen.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import _ from 'underscore';
import lodashGet from 'lodash/get';
import React, {Component} from 'react';
import {View} from 'react-native';
Expand All @@ -22,15 +21,12 @@ import Permissions from '../../../libs/Permissions';
import ONYXKEYS from '../../../ONYXKEYS';
import * as Policy from '../../../libs/actions/Policy';
import Performance from '../../../libs/Performance';
import NameValuePair from '../../../libs/actions/NameValuePair';
import * as WelcomeAction from '../../../libs/actions/WelcomeActions';

const propTypes = {
/* Beta features list */
betas: PropTypes.arrayOf(PropTypes.string).isRequired,

/* Flag for new users used to open the Global Create menu on first load */
isFirstTimeNewExpensifyUser: PropTypes.bool,

/* Is workspace is being created by the user? */
isCreatingWorkspace: PropTypes.bool,

Expand All @@ -39,7 +35,6 @@ const propTypes = {
...withLocalizePropTypes,
};
const defaultProps = {
isFirstTimeNewExpensifyUser: false,
isCreatingWorkspace: false,
};

Expand All @@ -61,29 +56,8 @@ class SidebarScreen extends Component {
Performance.markStart(CONST.TIMING.SIDEBAR_LOADED);
Timing.start(CONST.TIMING.SIDEBAR_LOADED, true);

// NOTE: This setTimeout is required due to a bug in react-navigation where modals do not display properly in a drawerContent
// 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) {
return;
}

// 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 (!Policy.isAdminOfFreePolicy(this.props.allPolicies) && !isDisplayingWorkspaceRoute) {
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
NameValuePair.set(CONST.NVP.IS_FIRST_TIME_NEW_EXPENSIFY_USER, false, ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER);
}, 1500);
const routes = lodashGet(this.props.navigation.getState(), 'routes', []);
WelcomeAction.show({routes, toggleCreateMenu: this.toggleCreateMenu});
}

/**
Expand Down Expand Up @@ -221,9 +195,6 @@ export default compose(
betas: {
key: ONYXKEYS.BETAS,
},
isFirstTimeNewExpensifyUser: {
key: ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER,
},
isCreatingWorkspace: {
key: ONYXKEYS.IS_CREATING_WORKSPACE,
},
Expand Down