fix and update Dashboard
This commit is contained in:
parent
fda609f6bf
commit
29dccdd21c
6 changed files with 54 additions and 26 deletions
|
@ -7,6 +7,8 @@ import Login from "./views/Login";
|
|||
import FourOhFour from "./views/FourOhFour";
|
||||
import ForgotPass from "./views/Forgot-password";
|
||||
import ChangePass from "./views/Forgot-pass-reset";
|
||||
import ConfirmForgotPasswrod from "./views/ConfirmForgotPassword";
|
||||
import ConfirmRegistration from "./views/ConfirmRegistration";
|
||||
import queryString from 'query-string';
|
||||
|
||||
import { call } from './client_server';
|
||||
|
@ -63,6 +65,7 @@ class App extends Component {
|
|||
loggedIn: true,
|
||||
}
|
||||
);
|
||||
return res;
|
||||
//this.props.history.push("/dashboard");
|
||||
} else {
|
||||
this.setState({
|
||||
|
@ -91,15 +94,21 @@ class App extends Component {
|
|||
<Switch>
|
||||
<Route path="/" exact component={Home} />
|
||||
<Route path="/login" >
|
||||
{ this.state.loggedIn ? <Redirect tkn={this.state.token} to="/dashboard" /> : <Login auth={this.auth} /> }
|
||||
{ this.state.loggedIn && this.state.token ? <Redirect tkn={this.state.token} to="/dashboard" /> : <Login auth={this.auth} /> }
|
||||
</Route>
|
||||
<Route path="/signup" exact component={Signup} />
|
||||
<Route path="/dashboard" >
|
||||
{this.state.loggedIn ? <Dashboard logout={this.logout} /> : <Redirect to="/login" />}
|
||||
{this.state.loggedIn ? <Dashboard tkn={this.state.token} logout={this.logout} /> : <Redirect to="/login" />}
|
||||
</Route>
|
||||
<Route path="/forgot-password" >
|
||||
<ForgotPass />
|
||||
</Route>
|
||||
<Route path="/sent-email" >
|
||||
<ConfirmForgotPasswrod />
|
||||
</Route>
|
||||
<Route path="/sent-email-reg" >
|
||||
<ConfirmRegistration />
|
||||
</Route>
|
||||
<Route path="/forgot-pass-reset" >
|
||||
<ChangePass query={this.state.query}/>
|
||||
</Route>
|
||||
|
|
|
@ -49,7 +49,10 @@ export var call = {
|
|||
});
|
||||
},
|
||||
getAllRooms: function(token) {
|
||||
return axios.get(config + 'room', { headers: { Authorization : "Bearer " + tkn } })
|
||||
if (!token){
|
||||
token = tkn;
|
||||
}
|
||||
return axios.get(config + 'room', { headers: { Authorization : "Bearer " + token } })
|
||||
.then(res => {
|
||||
return res;
|
||||
}).catch(err => {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import React, {Component} from 'react';
|
||||
import DevicePanel from "../components/dashboard/DevicePanel";
|
||||
import NavbarTest from './NavbarTest'
|
||||
import Navbar from './Navbar'
|
||||
import MyHeader from '../components/HeaderController'
|
||||
|
||||
import { call } from '../client_server';
|
||||
|
@ -14,7 +14,8 @@ export default class Dashboard extends Component{
|
|||
super(props);
|
||||
this.state = {
|
||||
rooms: [],
|
||||
activeItem: "Home"
|
||||
activeItem: "Home",
|
||||
tkn: this.props.tkn
|
||||
};
|
||||
|
||||
this.addRoom = this.addRoom.bind(this);
|
||||
|
@ -22,27 +23,20 @@ export default class Dashboard extends Component{
|
|||
}
|
||||
|
||||
componentDidMount() {
|
||||
call.getAllRooms(this.props.token)
|
||||
call.getAllRooms(this.props.tkn)
|
||||
.then(res => {
|
||||
res.data.forEach((e) => {
|
||||
this.setState(state => ({
|
||||
rooms: state.rooms.concat([e])
|
||||
}));
|
||||
});
|
||||
console.log(res, this.state.rooms)
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
|
||||
addRoom(e) {
|
||||
e.preventDefault();
|
||||
const params = {
|
||||
"icon": "ciao",
|
||||
"image": "ciao",
|
||||
"name": "kitchen"
|
||||
}
|
||||
call.createRoom(params)
|
||||
addRoom(data) {
|
||||
call.createRoom(data)
|
||||
.then(res => {
|
||||
console.log(res);
|
||||
if (res.status === 200 && res.data) {
|
||||
|
@ -50,12 +44,15 @@ export default class Dashboard extends Component{
|
|||
rooms: state.rooms.concat([res.data])
|
||||
}));
|
||||
}
|
||||
console.log(this.state.rooms);
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
};
|
||||
|
||||
deleteRoom(id) {
|
||||
|
||||
}
|
||||
|
||||
handleItemClick(el) {
|
||||
//da fare richiesta get della room e settare activeItem
|
||||
}
|
||||
|
@ -63,11 +60,15 @@ export default class Dashboard extends Component{
|
|||
render () {
|
||||
return(
|
||||
<div style={{height : "110vh", background: '#1b1c1d'}}>
|
||||
<MyHeader />
|
||||
<Grid >
|
||||
<Grid.Row color='black'>
|
||||
<Grid.Column>
|
||||
<MyHeader />
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
<Grid.Row color='black'>
|
||||
<Grid.Column width={3}>
|
||||
<NavbarTest addRoom={this.addRoom} rooms={this.state.rooms} handleItemClick={this.handleItemClick}/>
|
||||
<Navbar addRoom={this.addRoom} rooms={this.state.rooms} handleItemClick={this.handleItemClick}/>
|
||||
</Grid.Column>
|
||||
|
||||
<Grid.Column width={13}>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import React, {Component} from 'react';
|
||||
import {Button, Form, Grid, Header, Image, Icon, Message} from 'semantic-ui-react';
|
||||
import {Redirect } from "react-router-dom";
|
||||
import { call } from '../client_server';
|
||||
|
||||
|
||||
|
@ -11,7 +12,8 @@ export default class ForgotPass extends Component {
|
|||
error: {
|
||||
state: false,
|
||||
message: "",
|
||||
}
|
||||
},
|
||||
success: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,6 +31,10 @@ export default class ForgotPass extends Component {
|
|||
|
||||
call.initResetPassword(params)
|
||||
.then(res => {
|
||||
console.log(res);
|
||||
if (res.status === 200) {
|
||||
this.setState({success : true});
|
||||
}
|
||||
if (res.status === "Errore") {
|
||||
this.setState({ error: { state: true,
|
||||
message: "Errore"}});
|
||||
|
@ -40,6 +46,9 @@ export default class ForgotPass extends Component {
|
|||
};
|
||||
|
||||
render() {
|
||||
if (this.state.success) {
|
||||
return <Redirect to="sent-email" />
|
||||
}
|
||||
return (
|
||||
<React.Fragment>
|
||||
<Button
|
||||
|
|
|
@ -25,9 +25,11 @@ export default class Login extends Component {
|
|||
user: this.state.user,
|
||||
params : params,
|
||||
}).then(res => {
|
||||
if (res.status === "Errore") {
|
||||
if (res.status === 200) {
|
||||
|
||||
} else {
|
||||
this.setState({error: { state: true,
|
||||
message: "Errore"}});
|
||||
message: "Errore"}});
|
||||
}
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
|
@ -47,7 +49,6 @@ export default class Login extends Component {
|
|||
<React.Fragment>
|
||||
<Button
|
||||
circular
|
||||
icon="right arrow"
|
||||
style={{margin: "2em"}}
|
||||
href="/"
|
||||
>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import React, {Component} from 'react';
|
||||
import {Button, Form, Grid, Header, Image, Icon, Input, Message} from 'semantic-ui-react';
|
||||
import {Redirect } from "react-router-dom";
|
||||
import { call } from '../client_server';
|
||||
|
||||
export default class Signup extends Component{
|
||||
|
@ -12,6 +13,7 @@ export default class Signup extends Component{
|
|||
password : "",
|
||||
error : { state : false,
|
||||
message: ""},
|
||||
success : false,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -26,11 +28,11 @@ export default class Signup extends Component{
|
|||
|
||||
call.register(params)
|
||||
.then(res => {
|
||||
if (res.status === "Errore") {
|
||||
if (res.status === 200 && res.data){
|
||||
this.setState({success: true});
|
||||
} else {
|
||||
this.setState({error: { state: true,
|
||||
message: "Errore"}});
|
||||
} else if (res.status === 200 && res.data){
|
||||
this.props.history.push("/");
|
||||
message: "Errore"}});
|
||||
}
|
||||
}).catch(err => {
|
||||
//console.log(err);
|
||||
|
@ -44,6 +46,9 @@ export default class Signup extends Component{
|
|||
};
|
||||
|
||||
render() {
|
||||
if (this.state.success) {
|
||||
return <Redirect to="sent-email-reg" />
|
||||
}
|
||||
return (
|
||||
<React.Fragment>
|
||||
<Button
|
||||
|
|
Loading…
Reference in a new issue