frontend/smart-hut/src/App.js

82 lines
2.5 KiB
JavaScript
Raw Normal View History

2020-03-23 20:24:17 +00:00
import React, { Component } from "react";
import { BrowserRouter, Switch, Route, Redirect } from "react-router-dom";
2020-03-02 15:59:32 +00:00
import Home from "./views/Home";
2020-03-11 16:38:04 +00:00
import Dashboard from "./views/Dashboard";
2020-03-02 15:59:32 +00:00
import Signup from "./views/Signup";
import Login from "./views/Login";
2020-03-07 10:59:04 +00:00
import FourOhFour from "./views/FourOhFour";
2020-03-05 10:02:33 +00:00
import ForgotPass from "./views/Forgot-password";
import ChangePass from "./views/Forgot-pass-reset";
2020-03-14 14:48:33 +00:00
import ConfirmForgotPasswrod from "./views/ConfirmForgotPassword";
import ConfirmRegistration from "./views/ConfirmRegistration";
2020-03-24 14:57:22 +00:00
import ConfirmResetPassword from "./views/ConfirmResetPassword";
import Instruction from "./views/Instruction";
2020-03-23 20:24:17 +00:00
import queryString from "query-string";
import { RemoteService } from "./remote";
import { connect } from "react-redux";
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 = {
query: "",
2020-03-25 23:15:02 +00:00
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() {
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">
<ForgotPass />
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-03-23 20:24:17 +00:00
<Route path="/forgot-pass-reset"> </Route>
<Route path="/password-reset">
<ChangePass 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>
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
}
const mapStateToProps = (state, _) => {
console.log("malusae react", state);
return { loggedIn: !!(state.login && state.login.loggedIn) };
};
const AppContainer = connect(mapStateToProps, RemoteService)(App);
export default AppContainer;