Skip to content
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
3 changes: 3 additions & 0 deletions src/ONYXKEYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ export default {
// Is report data loading?
IS_LOADING_REPORT_DATA: 'isLoadingReportData',

// Is policy data loading?
IS_LOADING_POLICY_DATA: 'isLoadingPolicyData',

// Are we loading the create policy room command
IS_LOADING_CREATE_POLICY_ROOM: 'isLoadingCratePolicyRoom',

Expand Down
4 changes: 4 additions & 0 deletions src/libs/actions/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,11 @@ function deletePolicy(policyID) {
* and we also don't have to wait for full policies to load before navigating to the new policy.
*/
function getPolicyList() {
Onyx.set(ONYXKEYS.IS_LOADING_POLICY_DATA, true);
API.GetPolicySummaryList()
.then((data) => {
if (data.jsonCode !== 200) {
Onyx.set(ONYXKEYS.IS_LOADING_POLICY_DATA, false);
return;
}

Expand All @@ -224,6 +226,8 @@ function getPolicyList() {
if (!_.isEmpty(policyCollection)) {
updateAllPolicies(policyCollection);
}

Onyx.set(ONYXKEYS.IS_LOADING_POLICY_DATA, false);
});
}

Expand Down
2 changes: 2 additions & 0 deletions src/libs/actions/Session/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import NetworkConnection from '../../NetworkConnection';
import * as User from '../User';
import * as ValidationUtils from '../../ValidationUtils';
import * as Authentication from '../../Authentication';
import * as Welcome from '../Welcome';

let credentials = {};
Onyx.connect({
Expand Down Expand Up @@ -347,6 +348,7 @@ function cleanupSession() {
PushNotification.clearNotifications();
Pusher.disconnect();
Timers.clearAll();
Welcome.resetReadyCheck();
}

function clearAccountMessages() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,60 @@ import * as Policy from './Policy';
import ONYXKEYS from '../../ONYXKEYS';
import NameValuePair from './NameValuePair';
import CONST from '../../CONST';
import createOnReadyTask from '../createOnReadyTask';

const readyTask = createOnReadyTask();

let isFirstTimeNewExpensifyUser;
let isLoadingReportData = true;
let isLoadingPolicyData = true;

/**
* Check that a few requests have completed so that the welcome action can proceed:
*
* - Whether we are a first time new expensify user
* - Whether we have loaded all policies the server knows about
* - Whether we have loaded all reports the server knows about
*/
function checkOnReady() {
if (!_.isBoolean(isFirstTimeNewExpensifyUser) || isLoadingPolicyData || isLoadingReportData) {
return;
}

readyTask.setIsReady();
}

/* 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,
initWithStoredValues: false,
callback: (val) => {
isFirstTimeNewExpensifyUser = val;
checkOnReady();
},
});

Onyx.connect({
key: ONYXKEYS.IS_LOADING_REPORT_DATA,
initWithStoredValues: false,
callback: (val) => {
isLoadingReportData = val;
checkOnReady();
},
});

Onyx.connect({
key: ONYXKEYS.IS_LOADING_POLICY_DATA,
initWithStoredValues: false,
callback: (val) => {
isLoadingPolicyData = val;
checkOnReady();
},
Comment on lines 34 to +58

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not a big deal, but after setReady we no longer need to be connected to these Onyx keys

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actually we might need - for when you logout and login again

});

const allReports = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
initWithStoredValues: false,
callback: (val, key) => {
if (!val || !key) {
return;
Expand All @@ -45,12 +88,10 @@ Onyx.connect({
*
* @param {Object} params
* @param {Object} params.routes
* @param {Function} params.hideCreateMenu
* @param {Function} params.showCreateMenu
*/
Comment thread
marcaaron marked this conversation as resolved.
Outdated
function show({routes, hideCreateMenu}) {
// 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(() => {
function show({routes, showCreateMenu}) {
readyTask.isReady().then(() => {
if (!isFirstTimeNewExpensifyUser) {
return;
}
Expand All @@ -72,15 +113,19 @@ function show({routes, hideCreateMenu}) {
const exitingToWorkspaceRoute = lodashGet(loginWithShortLivedTokenRoute, 'params.exitTo', '') === 'workspace/new';
const isDisplayingWorkspaceRoute = topRouteName.toLowerCase().includes('workspace') || exitingToWorkspaceRoute;

// It's also possible that we already have a workspace policy. In either case we will not hide the menu but do still want to set the NVP in this case
// since the user does not need to create a workspace.
// If user is not already an admin of a free policy and we are not navigating them to their workspace or creating a new workspace via workspace/new then
// we will show the create menu.
if (!Policy.isAdminOfFreePolicy(allPolicies) && !isDisplayingWorkspaceRoute) {
hideCreateMenu();
showCreateMenu();
}
}, 1500);
});
}

function resetReadyCheck() {
readyTask.reset();
}

export {
// eslint-disable-next-line import/prefer-default-export
show,
resetReadyCheck,
};
4 changes: 2 additions & 2 deletions src/pages/home/sidebar/SidebarScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Permissions from '../../../libs/Permissions';
import ONYXKEYS from '../../../ONYXKEYS';
import * as Policy from '../../../libs/actions/Policy';
import Performance from '../../../libs/Performance';
import * as WelcomeAction from '../../../libs/actions/WelcomeActions';
import * as Welcome from '../../../libs/actions/Welcome';

const propTypes = {
/* Beta features list */
Expand Down Expand Up @@ -58,7 +58,7 @@ class SidebarScreen extends Component {
Timing.start(CONST.TIMING.SIDEBAR_LOADED, true);

const routes = lodashGet(this.props.navigation.getState(), 'routes', []);
WelcomeAction.show({routes, hideCreateMenu: this.hideCreateMenu});
Welcome.show({routes, showCreateMenu: this.showCreateMenu});
}

/**
Expand Down