diff --git a/src/Expensify.js b/src/Expensify.js index eca2fb130a37..0d26f00c96ec 100644 --- a/src/Expensify.js +++ b/src/Expensify.js @@ -19,6 +19,8 @@ import UpdateAppModal from './components/UpdateAppModal'; import Visibility from './libs/Visibility'; import GrowlNotification from './components/GrowlNotification'; import {growlRef} from './libs/Growl'; +import Navigation from './libs/Navigation/Navigation'; +import ROUTES from './ROUTES'; // Initialize the store when the app loads for the first time Onyx.init({ @@ -55,6 +57,9 @@ const propTypes = { /** Currently logged in user accountID */ accountID: PropTypes.number, + + /** Should app immediately redirect to new workspace route once authenticated */ + redirectToWorkspaceNewAfterSignIn: PropTypes.bool, }), /** Whether a new update is available and ready to install. */ @@ -68,6 +73,7 @@ const defaultProps = { session: { authToken: null, accountID: null, + redirectToWorkspaceNewAfterSignIn: false, }, updateAvailable: false, initialReportDataLoaded: false, @@ -114,6 +120,9 @@ 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() && this.props.initialReportDataLoaded) { diff --git a/src/libs/Navigation/AppNavigator/PublicScreens.js b/src/libs/Navigation/AppNavigator/PublicScreens.js index 4241a7d42d33..62032beb27cc 100644 --- a/src/libs/Navigation/AppNavigator/PublicScreens.js +++ b/src/libs/Navigation/AppNavigator/PublicScreens.js @@ -2,6 +2,7 @@ import React from 'react'; import {createStackNavigator} from '@react-navigation/stack'; import SignInPage from '../../../pages/signin/SignInPage'; import SetPasswordPage from '../../../pages/SetPasswordPage'; +import PublicWorkspaceNewView from '../../../pages/workspace/PublicWorkspaceNewView'; import ValidateLoginPage from '../../../pages/ValidateLoginPage'; import SCREENS from '../../../SCREENS'; @@ -31,5 +32,9 @@ export default () => ( options={defaultScreenOptions} component={SetPasswordPage} /> + ); diff --git a/src/libs/actions/Session.js b/src/libs/actions/Session.js index efbb82abe602..07d545059fad 100644 --- a/src/libs/actions/Session.js +++ b/src/libs/actions/Session.js @@ -23,11 +23,9 @@ Onyx.connect({ */ function setSuccessfulSignInData(data) { PushNotification.register(data.accountID); - Onyx.multiSet({ - [ONYXKEYS.SESSION]: { - shouldShowComposeInput: true, - ..._.pick(data, 'authToken', 'accountID', 'email'), - }, + Onyx.merge(ONYXKEYS.SESSION, { + shouldShowComposeInput: true, + ..._.pick(data, 'authToken', 'accountID', 'email'), }); } diff --git a/src/pages/workspace/PublicWorkspaceNewView.js b/src/pages/workspace/PublicWorkspaceNewView.js new file mode 100644 index 000000000000..fa0ac88b4420 --- /dev/null +++ b/src/pages/workspace/PublicWorkspaceNewView.js @@ -0,0 +1,28 @@ +import React from 'react'; +import Onyx from 'react-native-onyx'; +import PropTypes from 'prop-types'; +import ONYXKEYS from '../../ONYXKEYS'; +import SCREENS from '../../SCREENS'; + +const propTypes = { + /** react-navigation navigation object available to screen components */ + navigation: PropTypes.shape({ + /** Method used to navigate to a new page and not keep the current route in the history */ + replace: PropTypes.func.isRequired, + }).isRequired, +}; + +class PublicWorkspaceNewView extends React.PureComponent { + componentDidMount() { + Onyx.merge(ONYXKEYS.SESSION, {redirectToWorkspaceNewAfterSignIn: true}); + this.props.navigation.replace(SCREENS.HOME); + } + + render() { + return null; + } +} + +PublicWorkspaceNewView.propTypes = propTypes; + +export default PublicWorkspaceNewView;