Skip to content

Commit

Permalink
Merge pull request #3578 from Expensify/beaman-handle-new-workspace-f…
Browse files Browse the repository at this point in the history
…or-nonauth-users

Handle unauthenticated users when creating a new workspace
  • Loading branch information
marcaaron authored Jun 14, 2021
2 parents 892b546 + 659509d commit 7186caf
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/Expensify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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. */
Expand All @@ -68,6 +73,7 @@ const defaultProps = {
session: {
authToken: null,
accountID: null,
redirectToWorkspaceNewAfterSignIn: false,
},
updateAvailable: false,
initialReportDataLoaded: false,
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions src/libs/Navigation/AppNavigator/PublicScreens.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -31,5 +32,9 @@ export default () => (
options={defaultScreenOptions}
component={SetPasswordPage}
/>
<RootStack.Screen
name="NewWorkspace"
component={PublicWorkspaceNewView}
/>
</RootStack.Navigator>
);
8 changes: 3 additions & 5 deletions src/libs/actions/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
});
}

Expand Down
28 changes: 28 additions & 0 deletions src/pages/workspace/PublicWorkspaceNewView.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 7186caf

Please sign in to comment.