From 592b9b1e8a80ba2cf010cebe572f637a64f7393f Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Mon, 14 Jun 2021 18:49:36 +0200 Subject: [PATCH 1/5] Merge instead of set session data after signin --- src/libs/actions/Session.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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'), }); } From ebcdc7e4fbf61b91adc379f75fab90b05f0d5cab Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Mon, 14 Jun 2021 18:50:46 +0200 Subject: [PATCH 2/5] New public workspace/new route + redirect --- src/Expensify.js | 11 +++++++++ src/ROUTES.js | 1 + .../Navigation/AppNavigator/PublicScreens.js | 5 ++++ src/libs/Navigation/linkingConfig.js | 1 + src/pages/workspace/PublicWorkspaceNewView.js | 24 +++++++++++++++++++ 5 files changed, 42 insertions(+) create mode 100644 src/pages/workspace/PublicWorkspaceNewView.js diff --git a/src/Expensify.js b/src/Expensify.js index 431db2e8d9a1..9af9d8ecadc5 100644 --- a/src/Expensify.js +++ b/src/Expensify.js @@ -18,6 +18,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({ @@ -54,6 +56,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. */ @@ -67,6 +72,7 @@ const defaultProps = { session: { authToken: null, accountID: null, + redirectToWorkspaceNewAfterSignIn: false, }, updateAvailable: false, initialReportDataLoaded: false, @@ -113,6 +119,11 @@ class Expensify extends PureComponent { const previousAuthToken = lodashGet(prevProps, 'session.authToken', null); if (this.getAuthToken() && !previousAuthToken) { BootSplash.show({fade: true}); + // let redirect = lodashGet(this.props, 'session.redirectToWorkspaceNewAfterSignIn', false); + // console.log('should redirect?', redirect); + if (lodashGet(this.props, 'session.redirectToWorkspaceNewAfterSignIn', false)) { + Navigation.navigate(ROUTES.WORKSPACE_NEW); + } } if (this.getAuthToken() && this.props.initialReportDataLoaded) { diff --git a/src/ROUTES.js b/src/ROUTES.js index 8fbb80f1853c..b46703870e4a 100644 --- a/src/ROUTES.js +++ b/src/ROUTES.js @@ -48,6 +48,7 @@ export default { VALIDATE_LOGIN: 'v', VALIDATE_LOGIN_WITH_VALIDATE_CODE: 'v/:accountID/:validateCode', ENABLE_PAYMENTS: 'enable-payments', + WORKSPACE_NEW: 'workspace/new', /** * @param {String} route 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/Navigation/linkingConfig.js b/src/libs/Navigation/linkingConfig.js index 720196767e8b..664cd9aff928 100644 --- a/src/libs/Navigation/linkingConfig.js +++ b/src/libs/Navigation/linkingConfig.js @@ -25,6 +25,7 @@ export default { // Public Routes SetPassword: ROUTES.SET_PASSWORD_WITH_VALIDATE_CODE, ValidateLogin: ROUTES.VALIDATE_LOGIN_WITH_VALIDATE_CODE, + NewWorkspace: ROUTES.WORKSPACE_NEW, // Modal Screens Settings: { diff --git a/src/pages/workspace/PublicWorkspaceNewView.js b/src/pages/workspace/PublicWorkspaceNewView.js new file mode 100644 index 000000000000..772a3404b80b --- /dev/null +++ b/src/pages/workspace/PublicWorkspaceNewView.js @@ -0,0 +1,24 @@ +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, +}; + +const PublicWorkspaceNewView = (props) => { + Onyx.merge(ONYXKEYS.SESSION, {redirectToWorkspaceNewAfterSignIn: true}); + + props.navigation.replace(SCREENS.HOME); + + return null; +}; + +PublicWorkspaceNewView.propTypes = propTypes; +PublicWorkspaceNewView.displayName = 'PublicWorkspaceNewView'; +export default PublicWorkspaceNewView; From 84c4b58b7739677b189cbcfba56f42e4dd393446 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Mon, 14 Jun 2021 19:08:59 +0200 Subject: [PATCH 3/5] Remove old test logs --- src/Expensify.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Expensify.js b/src/Expensify.js index 9af9d8ecadc5..db84fca49fe9 100644 --- a/src/Expensify.js +++ b/src/Expensify.js @@ -119,8 +119,6 @@ class Expensify extends PureComponent { const previousAuthToken = lodashGet(prevProps, 'session.authToken', null); if (this.getAuthToken() && !previousAuthToken) { BootSplash.show({fade: true}); - // let redirect = lodashGet(this.props, 'session.redirectToWorkspaceNewAfterSignIn', false); - // console.log('should redirect?', redirect); if (lodashGet(this.props, 'session.redirectToWorkspaceNewAfterSignIn', false)) { Navigation.navigate(ROUTES.WORKSPACE_NEW); } From 8f4b69e8a72b484928d95945eaa649f9b991758a Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Mon, 14 Jun 2021 19:09:26 +0200 Subject: [PATCH 4/5] Convert placeholder component to class for CDM --- src/pages/workspace/PublicWorkspaceNewView.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/pages/workspace/PublicWorkspaceNewView.js b/src/pages/workspace/PublicWorkspaceNewView.js index 772a3404b80b..fa0ac88b4420 100644 --- a/src/pages/workspace/PublicWorkspaceNewView.js +++ b/src/pages/workspace/PublicWorkspaceNewView.js @@ -1,3 +1,4 @@ +import React from 'react'; import Onyx from 'react-native-onyx'; import PropTypes from 'prop-types'; import ONYXKEYS from '../../ONYXKEYS'; @@ -11,14 +12,17 @@ const propTypes = { }).isRequired, }; -const PublicWorkspaceNewView = (props) => { - Onyx.merge(ONYXKEYS.SESSION, {redirectToWorkspaceNewAfterSignIn: true}); +class PublicWorkspaceNewView extends React.PureComponent { + componentDidMount() { + Onyx.merge(ONYXKEYS.SESSION, {redirectToWorkspaceNewAfterSignIn: true}); + this.props.navigation.replace(SCREENS.HOME); + } - props.navigation.replace(SCREENS.HOME); - - return null; -}; + render() { + return null; + } +} PublicWorkspaceNewView.propTypes = propTypes; -PublicWorkspaceNewView.displayName = 'PublicWorkspaceNewView'; + export default PublicWorkspaceNewView; From 659509d747f031136bed8844c059ae893cc97ef2 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Mon, 14 Jun 2021 19:09:39 +0200 Subject: [PATCH 5/5] Remove duplicate new workspace route --- src/libs/Navigation/linkingConfig.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/Navigation/linkingConfig.js b/src/libs/Navigation/linkingConfig.js index 6db698c0c2c7..58ca48d1cae9 100644 --- a/src/libs/Navigation/linkingConfig.js +++ b/src/libs/Navigation/linkingConfig.js @@ -25,7 +25,6 @@ export default { // Public Routes SetPassword: ROUTES.SET_PASSWORD_WITH_VALIDATE_CODE, ValidateLogin: ROUTES.VALIDATE_LOGIN_WITH_VALIDATE_CODE, - NewWorkspace: ROUTES.WORKSPACE_NEW, // Modal Screens Settings: {