frontend/smart-hut/src/components/modalform.js

112 lines
2.9 KiB
JavaScript
Raw Normal View History

2020-03-13 14:21:33 +00:00
import React, { Component } from 'react';
import { Button, Header, Image, Modal, Checkbox, Form, Grid, Input, Icon } from 'semantic-ui-react'
import SelectIcons from "./SelectIcons";
export default class ModalWindow extends Component {
constructor(props) {
super(props);
this.state = {
selectedIcon: 'home',
name: "",
2020-03-14 14:25:55 +00:00
img: "",
openModal: false
2020-03-13 14:21:33 +00:00
}
2020-03-14 14:25:55 +00:00
this.addRoomModal = this.addRoomModal.bind(this);
this.updateIcon = this.updateIcon.bind(this);
}
addRoomModal = (e) => {
let data = {
"icon" : this.state.selectedIcon,
"name" : this.state.name,
"images" : this.state.img
}
console.log(this.props, data);
this.props.addRoom(data);
this.closeModal();
}
deleteRoom = (e) => {
console.log(e);
2020-03-13 14:21:33 +00:00
}
2020-03-14 14:25:55 +00:00
changeSomething = (event) => {
let nam = event.target.name;
let val = event.target.value;
this.setState({[nam]: val});
}
closeModal = (e) => {
this.setState({openModal:false});
this.updateIcon('home');
}
openModal = (e) => {
this.setState({openModal:true})
}
updateIcon(e) {
console.log(e);
this.setState({selectedIcon : e})
}
render(){
2020-03-13 14:21:33 +00:00
const spaceDiv = {
background: '#f4f4f4',
padding: '10px 10px',
margin: '10px 0px'
}
return (
<div>
2020-03-14 14:25:55 +00:00
<Button icon labelPosition='left' inverted onClick={this.openModal}>
<Icon name='plus' size='small'/>
2020-03-13 14:21:33 +00:00
ADD ROOM
2020-03-14 14:25:55 +00:00
</Button>
<Modal
onClose={this.closeModal}
open={this.state.openModal}>
2020-03-13 14:21:33 +00:00
<Header>{this.props.type == "new" ? "Add new room" : "Modify room" }</Header>
<Modal.Content>
<Form>
<p>Insert the name of the room:</p>
<Form.Field>
2020-03-14 14:25:55 +00:00
<Input label='Room name' placeholder='Room Name' name="name" type='text' onChange={this.changeSomething}/>
2020-03-13 14:21:33 +00:00
</Form.Field>
<p>Insert an image of the room:</p>
<Form.Field>
2020-03-14 14:25:55 +00:00
<Input label='Room image' type='file' name="img" onChange={this.changeSomething}/>
2020-03-13 14:21:33 +00:00
</Form.Field>
</Form>
<div style={spaceDiv}>
<p>Select an icon:</p>
2020-03-14 14:25:55 +00:00
<SelectIcons updateIcon={this.updateIcon} currentIcon={this.state.selectedIcon}/>
2020-03-13 14:21:33 +00:00
</div>
2020-03-14 14:25:55 +00:00
{this.props.type == "modify" ?
<Button icon labelPosition='left' inverted color='red' onClick={this.deleteRoom}>
2020-03-13 14:21:33 +00:00
<Icon name='trash alternate' />
Delete room
2020-03-14 14:25:55 +00:00
</Button> : null }
2020-03-13 14:21:33 +00:00
</Modal.Content>
<Modal.Actions>
2020-03-14 14:25:55 +00:00
<Button color='red' onClick={this.closeModal}>
<Icon name='remove' /> {this.props.type == "new" ? "Cancel" : "Discard changes" }
2020-03-13 14:21:33 +00:00
</Button>
2020-03-14 14:25:55 +00:00
<Button color='green' onClick={this.addRoomModal}>
<Icon name='checkmark' /> {this.props.type == "new" ? "Add room" : "Save changes" }
2020-03-13 14:21:33 +00:00
</Button>
</Modal.Actions>
</Modal>
</div>
)
}
}