From 29dccdd21cd83d9bff5c47595cf2e4541e6019ef Mon Sep 17 00:00:00 2001 From: britea Date: Sat, 14 Mar 2020 15:48:33 +0100 Subject: [PATCH] fix and update Dashboard --- smart-hut/src/App.js | 13 +++++++++-- smart-hut/src/client_server.js | 5 ++++- smart-hut/src/views/Dashboard.js | 31 +++++++++++++------------- smart-hut/src/views/Forgot-password.js | 11 ++++++++- smart-hut/src/views/Login.js | 7 +++--- smart-hut/src/views/Signup.js | 13 +++++++---- 6 files changed, 54 insertions(+), 26 deletions(-) diff --git a/smart-hut/src/App.js b/smart-hut/src/App.js index b7af952..1405c68 100644 --- a/smart-hut/src/App.js +++ b/smart-hut/src/App.js @@ -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 { - { this.state.loggedIn ? : } + { this.state.loggedIn && this.state.token ? : } - {this.state.loggedIn ? : } + {this.state.loggedIn ? : } + + + + + + diff --git a/smart-hut/src/client_server.js b/smart-hut/src/client_server.js index 5e6dc22..18c2ae4 100644 --- a/smart-hut/src/client_server.js +++ b/smart-hut/src/client_server.js @@ -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 => { diff --git a/smart-hut/src/views/Dashboard.js b/smart-hut/src/views/Dashboard.js index c27746f..30f36e0 100644 --- a/smart-hut/src/views/Dashboard.js +++ b/smart-hut/src/views/Dashboard.js @@ -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(
- + + + + + - + diff --git a/smart-hut/src/views/Forgot-password.js b/smart-hut/src/views/Forgot-password.js index 99a454d..299405b 100644 --- a/smart-hut/src/views/Forgot-password.js +++ b/smart-hut/src/views/Forgot-password.js @@ -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 + } return (