From a8c8de8bdcf29c5048e2f2fc51b67c78daca9677 Mon Sep 17 00:00:00 2001 From: britea Date: Wed, 25 Mar 2020 22:15:52 +0100 Subject: [PATCH] fix device default name --- smart-hut/src/App.js | 5 ++-- .../components/dashboard/devices/NewDevice.js | 30 +++++++++++++++++-- smart-hut/src/views/Dashboard.js | 4 +++ smart-hut/src/views/Forgot-password.js | 27 +++++++++-------- smart-hut/src/views/Login.js | 19 ++++++------ smart-hut/src/views/Navbar.js | 18 +++++------ smart-hut/src/views/Signup.js | 23 +++++++++----- 7 files changed, 81 insertions(+), 45 deletions(-) diff --git a/smart-hut/src/App.js b/smart-hut/src/App.js index 003ee6c..2b2ec7a 100644 --- a/smart-hut/src/App.js +++ b/smart-hut/src/App.js @@ -84,12 +84,11 @@ class App extends Component { this.setState({ error: res.data.message, }); - return this.state.error; + return res.status; } }) .catch((err) => { - console.log(err); - return { status: "Errore" }; + return err; }); } diff --git a/smart-hut/src/components/dashboard/devices/NewDevice.js b/smart-hut/src/components/dashboard/devices/NewDevice.js index 6829eff..56640cd 100644 --- a/smart-hut/src/components/dashboard/devices/NewDevice.js +++ b/smart-hut/src/components/dashboard/devices/NewDevice.js @@ -36,6 +36,7 @@ export default class NewDevice extends Component { step: 1, openModal: false, motion: false, + name: "", }; this.baseState = this.state; this.createDevice = this.createDevice.bind(this); @@ -95,22 +96,47 @@ export default class NewDevice extends Component { }; switch (this.state.typeOfDevice) { + case "regularLight": + if (this.state.name === "") { + data.params["name"] = "Regular Light"; + } + break; + case "smartPlug": + if (this.state.name === "") { + data.params["name"] = "Smart Plug"; + } + break; case "dimmableLight": + if (this.state.name === "") { + data.params["name"] = "Dimmable Light"; + } data.params["intensity"] = 1; break; case "sensor": + if (this.state.name === "") { + data.params["name"] = "Sensor"; + } if (!this.state.motion) { data.params["sensor"] = this.state.typeOfSensor; data.params["value"] = 0; } break; case "switch": + if (this.state.name === "") { + data.params["name"] = "Switch"; + } data.params["lights"] = this.state.lightsAttached; break; case "buttonDimmer": + if (this.state.name === "") { + data.params["name"] = "Button Dimmer"; + } data.params["lights"] = this.state.lightsAttached; break; case "knobDimmer": + if (this.state.name === "") { + data.params["name"] = "Knob Dimmer"; + } data.params["lights"] = this.state.lightsAttached; break; default: @@ -254,7 +280,7 @@ export default class NewDevice extends Component { ); const switchOptions = ( - + - + { if (res.status === 200 && res.data) { this.getRooms(); + this.handleItemClick(-1); } }) .catch((err) => { @@ -100,6 +101,9 @@ export default class Dashboard extends Component { .then((res) => { //remove room in state.rooms this.getRooms(); + this.setState({ + activeItem: -1, + }); this.handleItemClick(-1); }) .catch((err) => { diff --git a/smart-hut/src/views/Forgot-password.js b/smart-hut/src/views/Forgot-password.js index 2ed14e6..b53e88d 100644 --- a/smart-hut/src/views/Forgot-password.js +++ b/smart-hut/src/views/Forgot-password.js @@ -18,7 +18,7 @@ export default class ForgotPass extends Component { user: "", error: { state: false, - message: "", + message: [], }, success: false, }; @@ -39,17 +39,15 @@ 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" } }); - } - //set a message that an email has been sent }) .catch((err) => { - console.log(err); + let errs = [ + ...new Set(err.response.data.errors.map((e) => e.defaultMessage)), + ]; + this.setState({ error: { state: true, message: errs } }); }); }; @@ -77,11 +75,16 @@ export default class ForgotPass extends Component { style={{ marginTop: "2em" }} error={this.state.error.state} > - + + Reset Password Error + + {this.state.error.message.map((e, i) => ( + + {e} +
+
+ ))} +
{ - if (res.status === 200) { + if (res.response.status === 200) { + } else if (res.response.status === 401) { + this.setState({ + error: { state: true, message: "Wrong credentials" }, + }); } else { - this.setState({ error: { state: true, message: "Errore" } }); + console.log(res); + this.setState({ + error: { state: true, message: "An error occurred while logging" }, + }); } }) .catch((err) => { @@ -97,13 +103,6 @@ export default class Login extends Component { type="password" onChange={this.onChangeHandler} /> -