fix device default name
This commit is contained in:
parent
6b09bdf016
commit
a8c8de8bdc
7 changed files with 81 additions and 45 deletions
|
@ -84,12 +84,11 @@ class App extends Component {
|
||||||
this.setState({
|
this.setState({
|
||||||
error: res.data.message,
|
error: res.data.message,
|
||||||
});
|
});
|
||||||
return this.state.error;
|
return res.status;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err);
|
return err;
|
||||||
return { status: "Errore" };
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ export default class NewDevice extends Component {
|
||||||
step: 1,
|
step: 1,
|
||||||
openModal: false,
|
openModal: false,
|
||||||
motion: false,
|
motion: false,
|
||||||
|
name: "",
|
||||||
};
|
};
|
||||||
this.baseState = this.state;
|
this.baseState = this.state;
|
||||||
this.createDevice = this.createDevice.bind(this);
|
this.createDevice = this.createDevice.bind(this);
|
||||||
|
@ -95,22 +96,47 @@ export default class NewDevice extends Component {
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (this.state.typeOfDevice) {
|
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":
|
case "dimmableLight":
|
||||||
|
if (this.state.name === "") {
|
||||||
|
data.params["name"] = "Dimmable Light";
|
||||||
|
}
|
||||||
data.params["intensity"] = 1;
|
data.params["intensity"] = 1;
|
||||||
break;
|
break;
|
||||||
case "sensor":
|
case "sensor":
|
||||||
|
if (this.state.name === "") {
|
||||||
|
data.params["name"] = "Sensor";
|
||||||
|
}
|
||||||
if (!this.state.motion) {
|
if (!this.state.motion) {
|
||||||
data.params["sensor"] = this.state.typeOfSensor;
|
data.params["sensor"] = this.state.typeOfSensor;
|
||||||
data.params["value"] = 0;
|
data.params["value"] = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "switch":
|
case "switch":
|
||||||
|
if (this.state.name === "") {
|
||||||
|
data.params["name"] = "Switch";
|
||||||
|
}
|
||||||
data.params["lights"] = this.state.lightsAttached;
|
data.params["lights"] = this.state.lightsAttached;
|
||||||
break;
|
break;
|
||||||
case "buttonDimmer":
|
case "buttonDimmer":
|
||||||
|
if (this.state.name === "") {
|
||||||
|
data.params["name"] = "Button Dimmer";
|
||||||
|
}
|
||||||
data.params["lights"] = this.state.lightsAttached;
|
data.params["lights"] = this.state.lightsAttached;
|
||||||
break;
|
break;
|
||||||
case "knobDimmer":
|
case "knobDimmer":
|
||||||
|
if (this.state.name === "") {
|
||||||
|
data.params["name"] = "Knob Dimmer";
|
||||||
|
}
|
||||||
data.params["lights"] = this.state.lightsAttached;
|
data.params["lights"] = this.state.lightsAttached;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -254,7 +280,7 @@ export default class NewDevice extends Component {
|
||||||
);
|
);
|
||||||
const switchOptions = (
|
const switchOptions = (
|
||||||
<Form.Field style={{ marginTop: "1rem" }}>
|
<Form.Field style={{ marginTop: "1rem" }}>
|
||||||
<label>Select the Lights You Want to Attach: </label>
|
<label>Select the lights or smart plugs You Want to Attach: </label>
|
||||||
<Dropdown
|
<Dropdown
|
||||||
name="typeOfDevice"
|
name="typeOfDevice"
|
||||||
placeholder="Select Lights"
|
placeholder="Select Lights"
|
||||||
|
@ -267,7 +293,7 @@ export default class NewDevice extends Component {
|
||||||
);
|
);
|
||||||
const dimmerOptions = (
|
const dimmerOptions = (
|
||||||
<Form.Field style={{ marginTop: "1rem" }}>
|
<Form.Field style={{ marginTop: "1rem" }}>
|
||||||
<label>Select the Lights You Want to Attach: </label>
|
<label>Select the dimmable lights You Want to Attach: </label>
|
||||||
<Dropdown
|
<Dropdown
|
||||||
name="typeOfDevice"
|
name="typeOfDevice"
|
||||||
placeholder="Select Lights"
|
placeholder="Select Lights"
|
||||||
|
|
|
@ -84,6 +84,7 @@ export default class Dashboard extends Component {
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.status === 200 && res.data) {
|
if (res.status === 200 && res.data) {
|
||||||
this.getRooms();
|
this.getRooms();
|
||||||
|
this.handleItemClick(-1);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
@ -100,6 +101,9 @@ export default class Dashboard extends Component {
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
//remove room in state.rooms
|
//remove room in state.rooms
|
||||||
this.getRooms();
|
this.getRooms();
|
||||||
|
this.setState({
|
||||||
|
activeItem: -1,
|
||||||
|
});
|
||||||
this.handleItemClick(-1);
|
this.handleItemClick(-1);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
|
|
@ -18,7 +18,7 @@ export default class ForgotPass extends Component {
|
||||||
user: "",
|
user: "",
|
||||||
error: {
|
error: {
|
||||||
state: false,
|
state: false,
|
||||||
message: "",
|
message: [],
|
||||||
},
|
},
|
||||||
success: false,
|
success: false,
|
||||||
};
|
};
|
||||||
|
@ -39,17 +39,15 @@ export default class ForgotPass extends Component {
|
||||||
call
|
call
|
||||||
.initResetPassword(params)
|
.initResetPassword(params)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log(res);
|
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
this.setState({ success: true });
|
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) => {
|
.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" }}
|
style={{ marginTop: "2em" }}
|
||||||
error={this.state.error.state}
|
error={this.state.error.state}
|
||||||
>
|
>
|
||||||
<Message
|
<Message error>
|
||||||
error
|
<Message.Header>Reset Password Error</Message.Header>
|
||||||
header="Send E-mail Error"
|
|
||||||
content={this.state.error.message}
|
{this.state.error.message.map((e, i) => (
|
||||||
/>
|
<span key={i}>
|
||||||
|
{e}
|
||||||
|
<br />
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</Message>
|
||||||
<Form.Input
|
<Form.Input
|
||||||
icon="address card outline"
|
icon="address card outline"
|
||||||
iconPosition="left"
|
iconPosition="left"
|
||||||
|
|
|
@ -7,7 +7,6 @@ import {
|
||||||
Image,
|
Image,
|
||||||
Message,
|
Message,
|
||||||
Icon,
|
Icon,
|
||||||
Checkbox,
|
|
||||||
Input,
|
Input,
|
||||||
} from "semantic-ui-react";
|
} from "semantic-ui-react";
|
||||||
|
|
||||||
|
@ -35,9 +34,16 @@ export default class Login extends Component {
|
||||||
params: params,
|
params: params,
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.status === 200) {
|
if (res.response.status === 200) {
|
||||||
|
} else if (res.response.status === 401) {
|
||||||
|
this.setState({
|
||||||
|
error: { state: true, message: "Wrong credentials" },
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
this.setState({ error: { state: true, message: "Errore" } });
|
console.log(res);
|
||||||
|
this.setState({
|
||||||
|
error: { state: true, message: "An error occurred while logging" },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
@ -97,13 +103,6 @@ export default class Login extends Component {
|
||||||
type="password"
|
type="password"
|
||||||
onChange={this.onChangeHandler}
|
onChange={this.onChangeHandler}
|
||||||
/>
|
/>
|
||||||
<Checkbox
|
|
||||||
type="checkbox"
|
|
||||||
name="rememberme"
|
|
||||||
onClick={this.toggle}
|
|
||||||
label="Remember me"
|
|
||||||
style={{ margin: "1.5em 0", float: "left" }}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
color="blue"
|
color="blue"
|
||||||
|
|
|
@ -11,6 +11,7 @@ class Navbar extends Component {
|
||||||
activeItem: -1,
|
activeItem: -1,
|
||||||
edited: "",
|
edited: "",
|
||||||
editMode: false,
|
editMode: false,
|
||||||
|
room: "",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,23 +25,20 @@ class Navbar extends Component {
|
||||||
this.setState((prevState) => ({ editMode: !prevState.editMode }));
|
this.setState((prevState) => ({ editMode: !prevState.editMode }));
|
||||||
|
|
||||||
handleClick = (e, { id, name }) => {
|
handleClick = (e, { id, name }) => {
|
||||||
let obj = undefined;
|
const room = this.props.rooms.filter((d) => d.id === id)[0];
|
||||||
this.props.rooms.forEach((e) => {
|
|
||||||
if (e.id === id) {
|
|
||||||
obj = e;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
activeItem: id,
|
activeItem: id,
|
||||||
activeRoom: obj,
|
activeRoom: room,
|
||||||
activeItemName: name,
|
activeItemName: name,
|
||||||
});
|
});
|
||||||
|
this.forceUpdate();
|
||||||
|
console.log(this.state.activeRoom);
|
||||||
this.props.handleItemClick(id);
|
this.props.handleItemClick(id);
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
//const { activeItem } = this.state
|
const { activeRoom } = this.state;
|
||||||
|
console.log("DIO", activeRoom);
|
||||||
return (
|
return (
|
||||||
<div style={{ background: "#1b1c1d!important", padding: "0 20px" }}>
|
<div style={{ background: "#1b1c1d!important", padding: "0 20px" }}>
|
||||||
<Responsive minWidth={768}>
|
<Responsive minWidth={768}>
|
||||||
|
@ -172,7 +170,7 @@ class Navbar extends Component {
|
||||||
<Grid.Column width={8}>
|
<Grid.Column width={8}>
|
||||||
<ModalWindow
|
<ModalWindow
|
||||||
type="modify"
|
type="modify"
|
||||||
idRoom={this.state.activeRoom}
|
idRoom={activeRoom}
|
||||||
updateRoom={this.props.updateRoom}
|
updateRoom={this.props.updateRoom}
|
||||||
deleteRoom={this.props.deleteRoom}
|
deleteRoom={this.props.deleteRoom}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -20,7 +20,7 @@ export default class Signup extends Component {
|
||||||
username: "",
|
username: "",
|
||||||
email: "",
|
email: "",
|
||||||
password: "",
|
password: "",
|
||||||
error: { state: false, message: "" },
|
error: { state: false, message: [] },
|
||||||
success: false,
|
success: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -39,12 +39,14 @@ export default class Signup extends Component {
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.status === 200 && res.data) {
|
if (res.status === 200 && res.data) {
|
||||||
this.setState({ success: true });
|
this.setState({ success: true });
|
||||||
} else {
|
|
||||||
this.setState({ error: { state: true, message: "Errore" } });
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
//console.log(err);
|
//console.log(err);
|
||||||
|
let errs = [
|
||||||
|
...new Set(err.response.data.errors.map((e) => e.defaultMessage)),
|
||||||
|
];
|
||||||
|
this.setState({ error: { state: true, message: errs } });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -78,11 +80,16 @@ export default class Signup extends Component {
|
||||||
style={{ marginTop: "2em" }}
|
style={{ marginTop: "2em" }}
|
||||||
error={this.state.error.state}
|
error={this.state.error.state}
|
||||||
>
|
>
|
||||||
<Message
|
<Message error>
|
||||||
error
|
<Message.Header>Singup Error</Message.Header>
|
||||||
header="Singup Error"
|
|
||||||
content={this.state.error.message}
|
{this.state.error.message.map((e, i) => (
|
||||||
/>
|
<span key={i}>
|
||||||
|
{e}
|
||||||
|
<br />
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</Message>
|
||||||
<Form.Input
|
<Form.Input
|
||||||
icon="address card outline"
|
icon="address card outline"
|
||||||
iconPosition="left"
|
iconPosition="left"
|
||||||
|
|
Loading…
Reference in a new issue