frontend/smart-hut/src/App.js

86 lines
2.6 KiB
JavaScript
Raw Normal View History

2020-05-12 13:18:33 +00:00
import React, { Component } from 'react';
import {
BrowserRouter, Switch, Route, Redirect,
} from 'react-router-dom';
import queryString from 'query-string';
import { connect } from 'react-redux';
import Home from './views/Home';
import Dashboard from './views/Dashboard';
import Signup from './views/Signup';
import Login from './views/Login';
import FourOhFour from './views/FourOhFour';
import ForgotPass from './views/Forgot-password';
import ConfirmForgotPasswrod from './views/ConfirmForgotPassword';
import ConfirmRegistration from './views/ConfirmRegistration';
import ConfirmResetPassword from './views/ConfirmResetPassword';
import Instruction from './views/Instruction';
import Videocam from './views/Videocam';
import { RemoteService } from './remote';
2020-03-11 16:38:04 +00:00
class App extends Component {
constructor(props, context) {
super(props, context);
2020-03-11 16:38:04 +00:00
2020-03-23 20:24:17 +00:00
this.state = {
2020-05-12 13:18:33 +00:00
query: '',
info: '',
2020-03-23 20:24:17 +00:00
};
2020-03-02 15:59:32 +00:00
}
componentDidMount() {
2020-03-19 10:52:13 +00:00
if (window.location) {
const values = queryString.parse(window.location.search);
2020-03-07 10:59:04 +00:00
this.setState({
2020-03-23 20:24:17 +00:00
query: values,
2020-03-07 10:59:04 +00:00
});
}
}
2020-03-02 15:59:32 +00:00
render() {
2020-05-12 13:18:33 +00:00
console.log('rendering root', this.props.loggedIn, this.state.query);
2020-03-02 15:59:32 +00:00
return (
2020-03-07 10:59:04 +00:00
<BrowserRouter>
2020-03-02 15:59:32 +00:00
<Switch>
<Route path="/" exact component={Home} />
2020-03-23 20:24:17 +00:00
<Route path="/login">
{this.props.loggedIn ? <Redirect to="/dashboard" /> : <Login />}
2020-03-02 15:59:32 +00:00
</Route>
<Route path="/signup" exact component={Signup} />
2020-03-23 20:24:17 +00:00
<Route path="/dashboard">
{this.props.loggedIn ? <Dashboard /> : <Redirect to="/login" />}
2020-03-02 15:59:32 +00:00
</Route>
2020-03-23 20:24:17 +00:00
<Route path="/forgot-password">
2020-05-10 21:50:59 +00:00
<ForgotPass type="FPassword1" />
2020-03-05 10:02:33 +00:00
</Route>
2020-03-23 20:24:17 +00:00
<Route path="/sent-email">
<ConfirmForgotPasswrod />
2020-03-14 14:48:33 +00:00
</Route>
2020-03-23 20:24:17 +00:00
<Route path="/sent-email-reg">
<ConfirmRegistration />
2020-03-14 14:48:33 +00:00
</Route>
2020-03-23 20:24:17 +00:00
<Route path="/instruction">
<Instruction />
</Route>
2020-05-10 21:50:59 +00:00
<Route path="/forgot-pass-reset">
<ForgotPass type="FPassword1" />
</Route>
2020-03-23 20:24:17 +00:00
<Route path="/password-reset">
2020-05-10 21:50:59 +00:00
<ForgotPass type="FPassword2" query={this.state.query} />
2020-03-05 10:02:33 +00:00
</Route>
2020-03-24 14:57:22 +00:00
<Route path="/conf-reset-pass">
<ConfirmResetPassword />
</Route>
<Route path="/videocam">
<Videocam />
2020-04-28 10:04:01 +00:00
</Route>
2020-03-07 10:59:04 +00:00
<Route component={FourOhFour} />
2020-03-02 15:59:32 +00:00
</Switch>
2020-03-07 10:59:04 +00:00
</BrowserRouter>
2020-03-02 15:59:32 +00:00
);
}
2020-02-24 14:22:19 +00:00
}
2020-04-09 12:48:24 +00:00
const mapStateToProps = (state, _) => ({ loggedIn: state.login.loggedIn });
const AppContainer = connect(mapStateToProps, RemoteService)(App);
export default AppContainer;