From 5f70cdd979f747f10e2e3e3f1372ee769c6629f7 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Fri, 2 Feb 2018 14:24:46 -0800 Subject: [PATCH] added redirect from login page to publish page if user logs in --- .../components/ChannelClaimsDisplay/index.js | 2 +- react/containers/LoginPage/index.js | 10 +++++++++ .../LoginPage/view.jsx} | 22 +++++++++++++------ react/root.js | 2 +- task-scripts/update-password.js | 2 +- 5 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 react/containers/LoginPage/index.js rename react/{components/LoginPage/index.js => containers/LoginPage/view.jsx} (62%) diff --git a/react/components/ChannelClaimsDisplay/index.js b/react/components/ChannelClaimsDisplay/index.js index 2912dbfa..4edc9c86 100644 --- a/react/components/ChannelClaimsDisplay/index.js +++ b/react/components/ChannelClaimsDisplay/index.js @@ -1,4 +1,4 @@ -import React from 'react/index'; +import React from 'react'; import AssetPreview from 'components/AssetPreview'; import request from 'utils/request'; diff --git a/react/containers/LoginPage/index.js b/react/containers/LoginPage/index.js new file mode 100644 index 00000000..2e193098 --- /dev/null +++ b/react/containers/LoginPage/index.js @@ -0,0 +1,10 @@ +import {connect} from 'react-redux'; +import View from './view'; + +const mapStateToProps = ({ channel }) => { + return { + loggedInChannelName: channel.loggedInChannel.name, + }; +}; + +export default connect(mapStateToProps, null)(View); diff --git a/react/components/LoginPage/index.js b/react/containers/LoginPage/view.jsx similarity index 62% rename from react/components/LoginPage/index.js rename to react/containers/LoginPage/view.jsx index b76f8242..dea4f950 100644 --- a/react/components/LoginPage/index.js +++ b/react/containers/LoginPage/view.jsx @@ -1,9 +1,17 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; import NavBar from 'containers/NavBar'; import ChannelLoginForm from 'containers/ChannelLoginForm'; import ChannelCreateForm from 'containers/ChannelCreateForm'; class PublishPage extends React.Component { + componentWillReceiveProps (newProps) { + // re-route the user to the homepage if the user is logged in + if (newProps.loggedInChannelName !== this.props.loggedInChannelName) { + console.log('user logged into new channel:', newProps.loggedInChannelName); + this.props.history.push(`/`); + } + } render () { return (
@@ -14,17 +22,17 @@ class PublishPage extends React.Component {

Channels allow you to publish and group content under an identity. You can create a channel for yourself, or share one with like-minded friends. You can create 1 channel, or 100, so whether you're documenting important events, or making a public repository for cat gifs (password: '1234'), try creating a channel for it!

-
-

Log in to an existing channel:

- -

Create a brand new channel:

- -
+
+

Log in to an existing channel:

+ +

Create a brand new channel:

+
+ ); } }; -export default PublishPage; +export default withRouter(PublishPage); diff --git a/react/root.js b/react/root.js index 170f1759..e296ea7b 100644 --- a/react/root.js +++ b/react/root.js @@ -5,7 +5,7 @@ import { BrowserRouter, Route, Switch } from 'react-router-dom'; import PublishPage from 'components/PublishPage'; import AboutPage from 'components/AboutPage'; -import LoginPage from 'components/LoginPage'; +import LoginPage from 'containers/LoginPage'; import ShowPage from 'containers/ShowPage'; const Root = ({ store }) => ( diff --git a/task-scripts/update-password.js b/task-scripts/update-password.js index 6a5176d4..89cff11f 100644 --- a/task-scripts/update-password.js +++ b/task-scripts/update-password.js @@ -1,6 +1,6 @@ // load dependencies const logger = require('winston'); -const db = require('../models/index'); // require our models for syncing +const db = require('../models'); // require our models for syncing // configure logging const config = require('../config/speechConfig.js'); const { logLevel } = config.logging;