diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js
index e25a0d76b53..10f22a0ca3c 100644
--- a/src/libs/Navigation/AppNavigator/AuthScreens.js
+++ b/src/libs/Navigation/AppNavigator/AuthScreens.js
@@ -1,6 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
+import {Linking} from 'react-native';
import Onyx, {withOnyx} from 'react-native-onyx';
+import Str from 'expensify-common/lib/str';
import moment from 'moment';
import _ from 'underscore';
import lodashGet from 'lodash/get';
@@ -27,10 +29,9 @@ import Navigation from '../Navigation';
import * as User from '../../actions/User';
import {setModalVisibility} from '../../actions/Modal';
import NameValuePair from '../../actions/NameValuePair';
-import {getPolicySummaries, getPolicyList} from '../../actions/Policy';
+import {getPolicyList} from '../../actions/Policy';
import modalCardStyleInterpolator from './modalCardStyleInterpolator';
import createCustomModalStackNavigator from './createCustomModalStackNavigator';
-import Permissions from '../../Permissions';
import getOperatingSystem from '../../getOperatingSystem';
import {fetchFreePlanVerifiedBankAccount} from '../../actions/BankAccounts';
@@ -65,7 +66,6 @@ import defaultScreenOptions from './defaultScreenOptions';
import * as API from '../../API';
import {setLocale} from '../../actions/App';
import {cleanupSession} from '../../actions/Session';
-import WorkspaceNew from '../../../pages/workspace/WorkspaceNew';
Onyx.connect({
key: ONYXKEYS.MY_PERSONAL_DETAILS,
@@ -107,22 +107,6 @@ const modalScreenListeners = {
},
};
-let hasLoadedPolicies = false;
-
-/**
- * We want to only load policy info if you are in the freePlan beta.
- * @param {Array} betas
- */
-function loadPoliciesBehindBeta(betas) {
- // When removing the freePlan beta, simply load the policyList and the policySummaries in componentDidMount().
- // Policy info loading should not be blocked behind the defaultRooms beta alone.
- if (!hasLoadedPolicies && (Permissions.canUseFreePlan(betas) || Permissions.canUseDefaultRooms(betas))) {
- getPolicyList();
- getPolicySummaries();
- hasLoadedPolicies = true;
- }
-}
-
const propTypes = {
/** Information about the network */
network: PropTypes.shape({
@@ -130,15 +114,11 @@ const propTypes = {
isOffline: PropTypes.bool,
}),
- /** List of betas available to current user */
- betas: PropTypes.arrayOf(PropTypes.string),
-
...windowDimensionsPropTypes,
};
const defaultProps = {
network: {isOffline: true},
- betas: [],
};
class AuthScreens extends React.Component {
@@ -187,7 +167,14 @@ class AuthScreens extends React.Component {
UnreadIndicatorUpdater.listenForReportChanges();
fetchFreePlanVerifiedBankAccount();
- loadPoliciesBehindBeta(this.props.betas);
+ // Load policies, maybe creating a new policy first.
+ Linking.getInitialURL()
+ .then((url) => {
+ const path = new URL(url).pathname;
+ const exitTo = new URLSearchParams(url).get('exitTo');
+ const shouldCreateFreePolicy = Str.startsWith(path, Str.normalizeUrl(ROUTES.LOGIN_WITH_SHORT_LIVED_TOKEN)) && exitTo === ROUTES.WORKSPACE_NEW;
+ getPolicyList(shouldCreateFreePolicy);
+ });
// Refresh the personal details, timezone and betas every 30 minutes
// There is no pusher event that sends updated personal details data yet
@@ -223,19 +210,7 @@ class AuthScreens extends React.Component {
}
shouldComponentUpdate(nextProps) {
- if (nextProps.isSmallScreenWidth !== this.props.isSmallScreenWidth) {
- return true;
- }
-
- if (nextProps.betas !== this.props.betas) {
- return true;
- }
-
- return false;
- }
-
- componentDidUpdate() {
- loadPoliciesBehindBeta(this.props.betas);
+ return nextProps.isSmallScreenWidth !== this.props.isSmallScreenWidth;
}
componentWillUnmount() {
@@ -248,7 +223,6 @@ class AuthScreens extends React.Component {
cleanupSession();
clearInterval(this.interval);
this.interval = null;
- hasLoadedPolicies = false;
}
render() {
@@ -310,11 +284,6 @@ class AuthScreens extends React.Component {
options={defaultScreenOptions}
component={LogInWithShortLivedTokenPage}
/>
-
{/* These are the various modal routes */}
{/* Note: Each modal must have it's own stack navigator since we want to be able to navigate to any
@@ -422,8 +391,5 @@ export default compose(
network: {
key: ONYXKEYS.NETWORK,
},
- betas: {
- key: ONYXKEYS.BETAS,
- },
}),
)(AuthScreens);
diff --git a/src/libs/Navigation/getPathName/index.js b/src/libs/Navigation/getPathName/index.js
deleted file mode 100644
index 161cece2a2e..00000000000
--- a/src/libs/Navigation/getPathName/index.js
+++ /dev/null
@@ -1,4 +0,0 @@
-export default (initialUrl) => {
- const initialURLObject = new URL(initialUrl);
- return initialURLObject.pathname;
-};
diff --git a/src/libs/Navigation/getPathName/index.native.js b/src/libs/Navigation/getPathName/index.native.js
deleted file mode 100644
index 94bc2b70e39..00000000000
--- a/src/libs/Navigation/getPathName/index.native.js
+++ /dev/null
@@ -1 +0,0 @@
-export default () => '';
diff --git a/src/libs/Navigation/linkingConfig.js b/src/libs/Navigation/linkingConfig.js
index 1094048f0b9..a9a4fd1ceb9 100644
--- a/src/libs/Navigation/linkingConfig.js
+++ b/src/libs/Navigation/linkingConfig.js
@@ -33,7 +33,6 @@ export default {
[SCREENS.LOGIN_WITH_VALIDATE_CODE_WORKSPACE_CARD]: ROUTES.LOGIN_WITH_VALIDATE_CODE_WORKSPACE_CARD,
[SCREENS.LOGIN_WITH_VALIDATE_CODE_2FA_WORKSPACE_CARD]: ROUTES.LOGIN_WITH_VALIDATE_CODE_2FA_WORKSPACE_CARD,
[SCREENS.LOG_IN_WITH_SHORT_LIVED_TOKEN]: ROUTES.LOGIN_WITH_SHORT_LIVED_TOKEN,
- WorkspaceNew: ROUTES.WORKSPACE_NEW,
// Modal Screens
Settings: {
diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js
index 2dac2974a4c..23415f68b38 100644
--- a/src/libs/actions/Policy.js
+++ b/src/libs/actions/Policy.js
@@ -22,7 +22,23 @@ Onyx.connect({
});
/**
- * Takes a full policy summary that is returned from the policySummaryList and simplifies it so we are only storing
+ * Simplifies the employeeList response into an object containing an array of emails
+ *
+ * @param {Object} employeeList
+ * @returns {Array}
+ */
+function getSimplifiedEmployeeList(employeeList) {
+ const employeeListEmails = _.chain(employeeList)
+ .pluck('email')
+ .flatten()
+ .unique()
+ .value();
+
+ return employeeListEmails;
+}
+
+/**
+ * Takes a full policy that is returned from the policyList and simplifies it so we are only storing
* the pieces of data that we need to in Onyx
*
* @param {Object} fullPolicy
@@ -30,7 +46,10 @@ Onyx.connect({
* @param {String} fullPolicy.name
* @param {String} fullPolicy.role
* @param {String} fullPolicy.type
+<<<<<<< HEAD
* @param {String} fullPolicy.outputCurrency
+=======
+>>>>>>> 30ce47c12 (Merge pull request #5706 from Expensify/Rory-FixLoadingSpinnerRaceCondition)
* @param {Object} fullPolicy.value.employeeList
* @param {String} [fullPolicy.value.avatarURL]
* @returns {Object}
@@ -41,26 +60,24 @@ function getSimplifiedPolicyObject(fullPolicy) {
name: fullPolicy.name,
role: fullPolicy.role,
type: fullPolicy.type,
+<<<<<<< HEAD
outputCurrency: fullPolicy.outputCurrency,
+=======
+>>>>>>> 30ce47c12 (Merge pull request #5706 from Expensify/Rory-FixLoadingSpinnerRaceCondition)
employeeList: getSimplifiedEmployeeList(lodashGet(fullPolicy, 'value.employeeList')),
avatarURL: lodashGet(fullPolicy, 'value.avatarURL', ''),
};
}
/**
- * Simplifies the employeeList response into an object containing an array of emails
- *
- * @param {Object} employeeList
- * @returns {Array}
+ * @param {Array