Skip to content

Commit

Permalink
Merge pull request #4205 from Expensify/chirag-beta-race-fixes
Browse files Browse the repository at this point in the history
Beta race fixes
  • Loading branch information
Beamanator authored Jul 27, 2021
2 parents d35ab90 + ce7b7e7 commit 30242db
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 10 deletions.
19 changes: 16 additions & 3 deletions src/Expensify.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import React, {PureComponent} from 'react';
import {View, AppState} from 'react-native';
import Onyx, {withOnyx} from 'react-native-onyx';
import _ from 'underscore';

import BootSplash from './libs/BootSplash';
import listenToStorageEvents from './libs/listenToStorageEvents';
Expand All @@ -21,6 +22,7 @@ import {growlRef} from './libs/Growl';
import Navigation from './libs/Navigation/Navigation';
import ROUTES from './ROUTES';
import StartupTimer from './libs/StartupTimer';
import {setRedirectToWorkspaceNewAfterSignIn} from './libs/actions/Session';

// Initialize the store when the app loads for the first time
Onyx.init({
Expand Down Expand Up @@ -69,6 +71,9 @@ const propTypes = {

/** Whether the initial data needed to render the app is ready */
initialReportDataLoaded: PropTypes.bool,

/** List of betas */
betas: PropTypes.arrayOf(PropTypes.string),
};

const defaultProps = {
Expand All @@ -79,6 +84,7 @@ const defaultProps = {
},
updateAvailable: false,
initialReportDataLoaded: false,
betas: [],
};

class Expensify extends PureComponent {
Expand Down Expand Up @@ -129,9 +135,13 @@ class Expensify extends PureComponent {
const previousAuthToken = lodashGet(prevProps, 'session.authToken', null);
if (this.getAuthToken() && !previousAuthToken) {
BootSplash.show({fade: true});
if (lodashGet(this.props, 'session.redirectToWorkspaceNewAfterSignIn', false)) {
Navigation.navigate(ROUTES.WORKSPACE_NEW);
}
}

if (this.getAuthToken()
&& !_.isEmpty(this.props.betas)
&& lodashGet(this.props, 'session.redirectToWorkspaceNewAfterSignIn', false)) {
setRedirectToWorkspaceNewAfterSignIn(false);
Navigation.navigate(ROUTES.WORKSPACE_NEW);
}

if (this.getAuthToken() && this.props.initialReportDataLoaded) {
Expand Down Expand Up @@ -188,6 +198,9 @@ export default withOnyx({
session: {
key: ONYXKEYS.SESSION,
},
betas: {
key: ONYXKEYS.BETAS,
},
updateAvailable: {
key: ONYXKEYS.UPDATE_AVAILABLE,
initWithStoredValues: false,
Expand Down
10 changes: 10 additions & 0 deletions src/libs/actions/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,15 @@ function continueSessionFromECom(accountID, validateCode, twoFactorAuthCode) {
});
}

/**
* Sets the redirectToWorkspaceNewAfterSignIn flag in the session variable
*
* @param {Boolean} shouldRedirect
*/
function setRedirectToWorkspaceNewAfterSignIn(shouldRedirect) {
Onyx.merge(ONYXKEYS.SESSION, {redirectToWorkspaceNewAfterSignIn: shouldRedirect});
}

export {
continueSessionFromECom,
fetchAccountDetails,
Expand All @@ -309,4 +318,5 @@ export {
resendValidationLink,
resetPassword,
restartSignin,
setRedirectToWorkspaceNewAfterSignIn,
};
17 changes: 15 additions & 2 deletions src/pages/ValidateLogin2FANewWorkspacePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import {TextInput, View} from 'react-native';
import lodashGet from 'lodash/get';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import withLocalize, {withLocalizePropTypes} from '../components/withLocalize';
import validateLinkPropTypes from './validateLinkPropTypes';
import {continueSessionFromECom} from '../libs/actions/Session';
import {continueSessionFromECom, setRedirectToWorkspaceNewAfterSignIn} from '../libs/actions/Session';
import styles from '../styles/styles';
import ExpensifyCashLogo from '../components/ExpensifyCashLogo';
import variables from '../styles/variables';
Expand All @@ -30,6 +31,9 @@ const propTypes = {
/** The accountID and validateCode are passed via the URL */
route: validateLinkPropTypes,

/** List of betas */
betas: PropTypes.arrayOf(PropTypes.string),

...withLocalizePropTypes,
};

Expand All @@ -38,6 +42,7 @@ const defaultProps = {
params: {},
},
session: {},
betas: [],
};
class ValidateLogin2FANewWorkspacePage extends Component {
constructor(props) {
Expand All @@ -62,7 +67,12 @@ class ValidateLogin2FANewWorkspacePage extends Component {
// by calling dismissModal(), the /v/... route is removed from history so the user will get taken to `/`
// if they cancel out of the new workspace modal.
Navigation.dismissModal();
Navigation.navigate(ROUTES.WORKSPACE_NEW);

if (_.isEmpty(this.props.betas)) {
setRedirectToWorkspaceNewAfterSignIn(true);
} else {
Navigation.navigate(ROUTES.WORKSPACE_NEW);
}
}
}

Expand Down Expand Up @@ -144,5 +154,8 @@ export default compose(
session: {
key: ONYXKEYS.SESSION,
},
betas: {
key: ONYXKEYS.BETAS,
},
}),
)(ValidateLogin2FANewWorkspacePage);
17 changes: 15 additions & 2 deletions src/pages/ValidateLoginNewWorkspacePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import {Component} from 'react';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import lodashGet from 'lodash/get';
import _ from 'underscore';
import validateLinkPropTypes from './validateLinkPropTypes';
import compose from '../libs/compose';
import ONYXKEYS from '../ONYXKEYS';
import Navigation from '../libs/Navigation/Navigation';
import ROUTES from '../ROUTES';
import {continueSessionFromECom} from '../libs/actions/Session';
import {continueSessionFromECom, setRedirectToWorkspaceNewAfterSignIn} from '../libs/actions/Session';


const propTypes = {
/* Onyx Props */
Expand All @@ -20,13 +22,17 @@ const propTypes = {

/** The accountID and validateCode are passed via the URL */
route: validateLinkPropTypes,

/** List of betas */
betas: PropTypes.arrayOf(PropTypes.string),
};

const defaultProps = {
route: {
params: {},
},
session: {},
betas: [],
};
class ValidateLoginNewWorkspacePage extends Component {
componentDidMount() {
Expand All @@ -39,7 +45,11 @@ class ValidateLoginNewWorkspacePage extends Component {
// by calling dismissModal(), the /v/... route is removed from history so the user will get taken to `/`
// if they cancel out of the new workspace modal.
Navigation.dismissModal();
Navigation.navigate(ROUTES.WORKSPACE_NEW);
if (_.isEmpty(this.props.betas)) {
setRedirectToWorkspaceNewAfterSignIn(true);
} else {
Navigation.navigate(ROUTES.WORKSPACE_NEW);
}
return;
}

Expand All @@ -63,5 +73,8 @@ export default compose(
session: {
key: ONYXKEYS.SESSION,
},
betas: {
key: ONYXKEYS.BETAS,
},
}),
)(ValidateLoginNewWorkspacePage);
5 changes: 2 additions & 3 deletions src/pages/workspace/PublicWorkspaceNewView.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from 'react';
import Onyx from 'react-native-onyx';
import PropTypes from 'prop-types';
import ONYXKEYS from '../../ONYXKEYS';
import SCREENS from '../../SCREENS';
import {setRedirectToWorkspaceNewAfterSignIn} from '../../libs/actions/Session';

const propTypes = {
/** react-navigation navigation object available to screen components */
Expand All @@ -14,7 +13,7 @@ const propTypes = {

class PublicWorkspaceNewView extends React.PureComponent {
componentDidMount() {
Onyx.merge(ONYXKEYS.SESSION, {redirectToWorkspaceNewAfterSignIn: true});
setRedirectToWorkspaceNewAfterSignIn(true);
this.props.navigation.replace(SCREENS.HOME);
}

Expand Down

0 comments on commit 30242db

Please sign in to comment.