Merge branch 'fix-default-device-name' into 'dev'
fix device default name See merge request sa4-2020/the-sanmarinoes/frontend!72
This commit is contained in:
commit
ecbe64d21e
7 changed files with 81 additions and 45 deletions
|
@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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 = (
|
||||
<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
|
||||
name="typeOfDevice"
|
||||
placeholder="Select Lights"
|
||||
|
@ -267,7 +293,7 @@ export default class NewDevice extends Component {
|
|||
);
|
||||
const dimmerOptions = (
|
||||
<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
|
||||
name="typeOfDevice"
|
||||
placeholder="Select Lights"
|
||||
|
|
|
@ -84,6 +84,7 @@ export default class Dashboard extends Component {
|
|||
.then((res) => {
|
||||
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) => {
|
||||
|
|
|
@ -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}
|
||||
>
|
||||
<Message
|
||||
error
|
||||
header="Send E-mail Error"
|
||||
content={this.state.error.message}
|
||||
/>
|
||||
<Message error>
|
||||
<Message.Header>Reset Password Error</Message.Header>
|
||||
|
||||
{this.state.error.message.map((e, i) => (
|
||||
<span key={i}>
|
||||
{e}
|
||||
<br />
|
||||
</span>
|
||||
))}
|
||||
</Message>
|
||||
<Form.Input
|
||||
icon="address card outline"
|
||||
iconPosition="left"
|
||||
|
|
|
@ -7,7 +7,6 @@ import {
|
|||
Image,
|
||||
Message,
|
||||
Icon,
|
||||
Checkbox,
|
||||
Input,
|
||||
} from "semantic-ui-react";
|
||||
|
||||
|
@ -35,9 +34,16 @@ export default class Login extends Component {
|
|||
params: params,
|
||||
})
|
||||
.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 {
|
||||
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}
|
||||
/>
|
||||
<Checkbox
|
||||
type="checkbox"
|
||||
name="rememberme"
|
||||
onClick={this.toggle}
|
||||
label="Remember me"
|
||||
style={{ margin: "1.5em 0", float: "left" }}
|
||||
/>
|
||||
|
||||
<Button
|
||||
color="blue"
|
||||
|
|
|
@ -11,6 +11,7 @@ class Navbar extends Component {
|
|||
activeItem: -1,
|
||||
edited: "",
|
||||
editMode: false,
|
||||
room: "",
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -24,23 +25,20 @@ class Navbar extends Component {
|
|||
this.setState((prevState) => ({ editMode: !prevState.editMode }));
|
||||
|
||||
handleClick = (e, { id, name }) => {
|
||||
let obj = undefined;
|
||||
this.props.rooms.forEach((e) => {
|
||||
if (e.id === id) {
|
||||
obj = e;
|
||||
}
|
||||
});
|
||||
|
||||
const room = this.props.rooms.filter((d) => d.id === id)[0];
|
||||
this.setState({
|
||||
activeItem: id,
|
||||
activeRoom: obj,
|
||||
activeRoom: room,
|
||||
activeItemName: name,
|
||||
});
|
||||
this.forceUpdate();
|
||||
console.log(this.state.activeRoom);
|
||||
this.props.handleItemClick(id);
|
||||
};
|
||||
|
||||
render() {
|
||||
//const { activeItem } = this.state
|
||||
const { activeRoom } = this.state;
|
||||
console.log("DIO", activeRoom);
|
||||
return (
|
||||
<div style={{ background: "#1b1c1d!important", padding: "0 20px" }}>
|
||||
<Responsive minWidth={768}>
|
||||
|
@ -172,7 +170,7 @@ class Navbar extends Component {
|
|||
<Grid.Column width={8}>
|
||||
<ModalWindow
|
||||
type="modify"
|
||||
idRoom={this.state.activeRoom}
|
||||
idRoom={activeRoom}
|
||||
updateRoom={this.props.updateRoom}
|
||||
deleteRoom={this.props.deleteRoom}
|
||||
/>
|
||||
|
|
|
@ -20,7 +20,7 @@ export default class Signup extends Component {
|
|||
username: "",
|
||||
email: "",
|
||||
password: "",
|
||||
error: { state: false, message: "" },
|
||||
error: { state: false, message: [] },
|
||||
success: false,
|
||||
};
|
||||
}
|
||||
|
@ -39,12 +39,14 @@ export default class Signup extends Component {
|
|||
.then((res) => {
|
||||
if (res.status === 200 && res.data) {
|
||||
this.setState({ success: true });
|
||||
} else {
|
||||
this.setState({ error: { state: true, message: "Errore" } });
|
||||
}
|
||||
})
|
||||
.catch((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" }}
|
||||
error={this.state.error.state}
|
||||
>
|
||||
<Message
|
||||
error
|
||||
header="Singup Error"
|
||||
content={this.state.error.message}
|
||||
/>
|
||||
<Message error>
|
||||
<Message.Header>Singup Error</Message.Header>
|
||||
|
||||
{this.state.error.message.map((e, i) => (
|
||||
<span key={i}>
|
||||
{e}
|
||||
<br />
|
||||
</span>
|
||||
))}
|
||||
</Message>
|
||||
<Form.Input
|
||||
icon="address card outline"
|
||||
iconPosition="left"
|
||||
|
|
Loading…
Reference in a new issue