Merge branch '31-fix-and-update-dashboard' into 'dev'

fix and update Dashboard

Closes #31

See merge request sa4-2020/the-sanmarinoes/frontend!25
This commit is contained in:
Claudio Maggioni 2020-03-14 15:56:16 +01:00
commit f7dac7fcdb
6 changed files with 54 additions and 26 deletions

View file

@ -7,6 +7,8 @@ import Login from "./views/Login";
import FourOhFour from "./views/FourOhFour"; import FourOhFour from "./views/FourOhFour";
import ForgotPass from "./views/Forgot-password"; import ForgotPass from "./views/Forgot-password";
import ChangePass from "./views/Forgot-pass-reset"; import ChangePass from "./views/Forgot-pass-reset";
import ConfirmForgotPasswrod from "./views/ConfirmForgotPassword";
import ConfirmRegistration from "./views/ConfirmRegistration";
import queryString from 'query-string'; import queryString from 'query-string';
import { call } from './client_server'; import { call } from './client_server';
@ -63,6 +65,7 @@ class App extends Component {
loggedIn: true, loggedIn: true,
} }
); );
return res;
//this.props.history.push("/dashboard"); //this.props.history.push("/dashboard");
} else { } else {
this.setState({ this.setState({
@ -91,15 +94,21 @@ class App extends Component {
<Switch> <Switch>
<Route path="/" exact component={Home} /> <Route path="/" exact component={Home} />
<Route path="/login" > <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>
<Route path="/signup" exact component={Signup} /> <Route path="/signup" exact component={Signup} />
<Route path="/dashboard" > <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>
<Route path="/forgot-password" > <Route path="/forgot-password" >
<ForgotPass /> <ForgotPass />
</Route> </Route>
<Route path="/sent-email" >
<ConfirmForgotPasswrod />
</Route>
<Route path="/sent-email-reg" >
<ConfirmRegistration />
</Route>
<Route path="/forgot-pass-reset" > <Route path="/forgot-pass-reset" >
<ChangePass query={this.state.query}/> <ChangePass query={this.state.query}/>
</Route> </Route>

View file

@ -49,7 +49,10 @@ export var call = {
}); });
}, },
getAllRooms: function(token) { 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 => { .then(res => {
return res; return res;
}).catch(err => { }).catch(err => {

View file

@ -1,6 +1,6 @@
import React, {Component} from 'react'; import React, {Component} from 'react';
import DevicePanel from "../components/dashboard/DevicePanel"; import DevicePanel from "../components/dashboard/DevicePanel";
import NavbarTest from './NavbarTest' import Navbar from './Navbar'
import MyHeader from '../components/HeaderController' import MyHeader from '../components/HeaderController'
import { call } from '../client_server'; import { call } from '../client_server';
@ -14,7 +14,8 @@ export default class Dashboard extends Component{
super(props); super(props);
this.state = { this.state = {
rooms: [], rooms: [],
activeItem: "Home" activeItem: "Home",
tkn: this.props.tkn
}; };
this.addRoom = this.addRoom.bind(this); this.addRoom = this.addRoom.bind(this);
@ -22,27 +23,20 @@ export default class Dashboard extends Component{
} }
componentDidMount() { componentDidMount() {
call.getAllRooms(this.props.token) call.getAllRooms(this.props.tkn)
.then(res => { .then(res => {
res.data.forEach((e) => { res.data.forEach((e) => {
this.setState(state => ({ this.setState(state => ({
rooms: state.rooms.concat([e]) rooms: state.rooms.concat([e])
})); }));
}); });
console.log(res, this.state.rooms)
}).catch(err => { }).catch(err => {
console.log(err); console.log(err);
}); });
} }
addRoom(e) { addRoom(data) {
e.preventDefault(); call.createRoom(data)
const params = {
"icon": "ciao",
"image": "ciao",
"name": "kitchen"
}
call.createRoom(params)
.then(res => { .then(res => {
console.log(res); console.log(res);
if (res.status === 200 && res.data) { if (res.status === 200 && res.data) {
@ -50,12 +44,15 @@ export default class Dashboard extends Component{
rooms: state.rooms.concat([res.data]) rooms: state.rooms.concat([res.data])
})); }));
} }
console.log(this.state.rooms);
}).catch(err => { }).catch(err => {
console.log(err); console.log(err);
}); });
}; };
deleteRoom(id) {
}
handleItemClick(el) { handleItemClick(el) {
//da fare richiesta get della room e settare activeItem //da fare richiesta get della room e settare activeItem
} }
@ -63,11 +60,15 @@ export default class Dashboard extends Component{
render () { render () {
return( return(
<div style={{height : "110vh", background: '#1b1c1d'}}> <div style={{height : "110vh", background: '#1b1c1d'}}>
<MyHeader />
<Grid > <Grid >
<Grid.Row color='black'>
<Grid.Column>
<MyHeader />
</Grid.Column>
</Grid.Row>
<Grid.Row color='black'> <Grid.Row color='black'>
<Grid.Column width={3}> <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>
<Grid.Column width={13}> <Grid.Column width={13}>

View file

@ -1,5 +1,6 @@
import React, {Component} from 'react'; import React, {Component} from 'react';
import {Button, Form, Grid, Header, Image, Icon, Message} from 'semantic-ui-react'; import {Button, Form, Grid, Header, Image, Icon, Message} from 'semantic-ui-react';
import {Redirect } from "react-router-dom";
import { call } from '../client_server'; import { call } from '../client_server';
@ -11,7 +12,8 @@ export default class ForgotPass extends Component {
error: { error: {
state: false, state: false,
message: "", message: "",
} },
success: false,
} }
} }
@ -29,6 +31,10 @@ export default class ForgotPass extends Component {
call.initResetPassword(params) call.initResetPassword(params)
.then(res => { .then(res => {
console.log(res);
if (res.status === 200) {
this.setState({success : true});
}
if (res.status === "Errore") { if (res.status === "Errore") {
this.setState({ error: { state: true, this.setState({ error: { state: true,
message: "Errore"}}); message: "Errore"}});
@ -40,6 +46,9 @@ export default class ForgotPass extends Component {
}; };
render() { render() {
if (this.state.success) {
return <Redirect to="sent-email" />
}
return ( return (
<React.Fragment> <React.Fragment>
<Button <Button

View file

@ -25,7 +25,9 @@ export default class Login extends Component {
user: this.state.user, user: this.state.user,
params : params, params : params,
}).then(res => { }).then(res => {
if (res.status === "Errore") { if (res.status === 200) {
} else {
this.setState({error: { state: true, this.setState({error: { state: true,
message: "Errore"}}); message: "Errore"}});
} }
@ -47,7 +49,6 @@ export default class Login extends Component {
<React.Fragment> <React.Fragment>
<Button <Button
circular circular
icon="right arrow"
style={{margin: "2em"}} style={{margin: "2em"}}
href="/" href="/"
> >

View file

@ -1,5 +1,6 @@
import React, {Component} from 'react'; import React, {Component} from 'react';
import {Button, Form, Grid, Header, Image, Icon, Input, Message} from 'semantic-ui-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'; import { call } from '../client_server';
export default class Signup extends Component{ export default class Signup extends Component{
@ -12,6 +13,7 @@ export default class Signup extends Component{
password : "", password : "",
error : { state : false, error : { state : false,
message: ""}, message: ""},
success : false,
}; };
} }
@ -26,11 +28,11 @@ export default class Signup extends Component{
call.register(params) call.register(params)
.then(res => { .then(res => {
if (res.status === "Errore") { if (res.status === 200 && res.data){
this.setState({success: true});
} else {
this.setState({error: { state: true, this.setState({error: { state: true,
message: "Errore"}}); message: "Errore"}});
} else if (res.status === 200 && res.data){
this.props.history.push("/");
} }
}).catch(err => { }).catch(err => {
//console.log(err); //console.log(err);
@ -44,6 +46,9 @@ export default class Signup extends Component{
}; };
render() { render() {
if (this.state.success) {
return <Redirect to="sent-email-reg" />
}
return ( return (
<React.Fragment> <React.Fragment>
<Button <Button