Fixed and beautified merge

This commit is contained in:
Claudio Maggioni 2020-03-23 21:29:42 +01:00
parent 897d6705b0
commit bca57e2a9b
2 changed files with 91 additions and 68 deletions

View file

@ -16,10 +16,10 @@ export default class ModalWindow extends Component {
this.state = { this.state = {
id: "", id: "",
selectedIcon: "", selectedIcon: "",
name: this.props.type === 'new' ? '' : this.props.idRoom.name, name: this.props.type === "new" ? "" : this.props.idRoom.name,
img: this.props.type === 'new' ? '' : this.props.idRoom.images, img: this.props.type === "new" ? "" : this.props.idRoom.images,
openModal: false openModal: false,
} };
this.addRoomModal = this.addRoomModal.bind(this); this.addRoomModal = this.addRoomModal.bind(this);
this.updateIcon = this.updateIcon.bind(this); this.updateIcon = this.updateIcon.bind(this);
@ -59,16 +59,10 @@ export default class ModalWindow extends Component {
this.setState({ [nam]: val }); this.setState({ [nam]: val });
}; };
let nam = event.target.name;
let val = event.target.value;
this.setState({[nam]: val});
console.log(this.state);
}
closeModal = (e) => { closeModal = (e) => {
this.setState({ openModal: false }); this.setState({ openModal: false });
this.updateIcon('home'); this.updateIcon("home");
} };
openModal = (e) => { openModal = (e) => {
this.setState({ openModal: true }); this.setState({ openModal: true });
@ -93,63 +87,92 @@ export default class ModalWindow extends Component {
<Icon name="plus" size="small" /> <Icon name="plus" size="small" />
ADD ROOM ADD ROOM
</Button> </Button>
: ) : (
<Icon name='pencil' size='small' onClick={this.openModal} /> <Icon name="pencil" size="small" onClick={this.openModal} />
} )}
</Responsive> </Responsive>
<Responsive maxWidth={768}> <Responsive maxWidth={768}>
{ {this.props.type === "new" ? (
this.props.type === "new" ? <Button icon fluid labelPosition="left" onClick={this.openModal}>
<Button icon fluid labelPosition='left' onClick={this.openModal}> <Icon name="plus" size="small" />
<Icon name='plus' size='small'/>
ADD ROOM ADD ROOM
</Button> </Button>
: ) : (
<Button icon fluid labelPosition='left' onClick={this.openModal}> <Button icon fluid labelPosition="left" onClick={this.openModal}>
<Icon name='pencil' size='small'/> <Icon name="pencil" size="small" />
EDIT ROOM EDIT ROOM
</Button> </Button>
} )}
</Responsive> </Responsive>
<Modal <Modal onClose={this.closeModal} open={this.state.openModal}>
onClose={this.closeModal} <Header>
open={this.state.openModal}> {this.props.type === "new" ? "Add new room" : "Modify room"}
<Header>{this.props.type === "new" ? "Add new room" : "Modify room" }</Header> </Header>
<Modal.Content> <Modal.Content>
<Form> <Form>
<p>Insert the name of the room:</p> <p>Insert the name of the room:</p>
<Form.Field> <Form.Field>
<Input label='Room name' placeholder='Room Name' name="name" type='text' onChange={this.changeSomething} <Input
value={this.state.name}/> label="Room name"
placeholder="Room Name"
name="name"
type="text"
onChange={this.changeSomething}
value={this.state.name}
/>
</Form.Field> </Form.Field>
<p>Insert an image of the room:</p> <p>Insert an image of the room:</p>
<Form.Field> <Form.Field>
<Input label='Room image' type='file' name="img" onChange={this.changeSomething} <Input
value={this.state.img}/> label="Room image"
type="file"
name="img"
onChange={this.changeSomething}
value={this.state.img}
/>
</Form.Field> </Form.Field>
</Form> </Form>
<div style={spaceDiv}> <div style={spaceDiv}>
<p>Select an icon:</p> <p>Select an icon:</p>
<SelectIcons updateIcon={this.updateIcon} currentIcon={this.props.type === "new" ? "home" : this.props.idRoom.icon }/> <SelectIcons
updateIcon={this.updateIcon}
currentIcon={
this.props.type === "new" ? "home" : this.props.idRoom.icon
}
/>
</div> </div>
{this.props.type === "modify" ? {this.props.type === "modify" ? (
<Button icon labelPosition='left' inverted color='red' onClick={this.deleteRoom}> <Button
<Icon name='trash alternate' /> icon
labelPosition="left"
inverted
color="red"
onClick={this.deleteRoom}
>
<Icon name="trash alternate" />
Delete room Delete room
</Button> : null } </Button>
) : null}
</Modal.Content> </Modal.Content>
<Modal.Actions> <Modal.Actions>
<Button color='red' onClick={this.closeModal}> <Button color="red" onClick={this.closeModal}>
<Icon name='remove' /> {this.props.type === "new" ? "Cancel" : "Discard changes" } <Icon name="remove" />{" "}
{this.props.type === "new" ? "Cancel" : "Discard changes"}
</Button> </Button>
<Button
<Button color='green' onClick={this.props.type === "new" ? this.addRoomModal : this.modifyRoomModal}> color="green"
<Icon name='checkmark' /> {this.props.type === "new" ? "Add room" : "Save changes"} onClick={
this.props.type === "new"
? this.addRoomModal
: this.modifyRoomModal
}
>
<Icon name="checkmark" />{" "}
{this.props.type === "new" ? "Add room" : "Save changes"}
</Button> </Button>
<Button <Button