import React, { Component } from 'react'; import { Button, Header, Modal, Form, Input, Icon, Responsive, Image } from 'semantic-ui-react'; import SelectIcons from "./SelectIcons"; const NO_IMAGE="https://react.semantic-ui.com/images/wireframe/image.png"; export default class ModalWindow extends Component { constructor(props) { super(props); console.table(this.props); this.state = { id : "", selectedIcon: "", name: "", img: this.props.type === "new" ? null : this.props.idRoom.image, openModal: false }; this.fileInputRef = React.createRef(); this.addRoomModal = this.addRoomModal.bind(this); this.updateIcon = this.updateIcon.bind(this); } addRoomModal = (e) => { let data = { "icon" : this.state.selectedIcon, "name" : this.state.name, "image" : this.state.img } this.props.addRoom(data); this.closeModal(); } modifyRoomModal = (e) => { let data = { "icon" : this.state.selectedIcon === "" ? this.props.idRoom.icon : this.state.selectedIcon , "name" : this.state.name === ""? this.props.idRoom.name : this.state.name, "image" : this.state.img } this.props.updateRoom(data); this.closeModal(); } deleteRoom = (e) => { this.props.deleteRoom(); this.closeModal(); } 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) { this.setState({selectedIcon : e}) } getBase64(file, callback) { let reader = new FileReader(); reader.readAsDataURL(file.target.files[0]); reader.onload = () => { this.state.img = reader.result; this.setState(this.state); }; reader.onerror = console.error; } render(){ const spaceDiv = { background: '#f4f4f4', padding: '10px 10px', margin: '10px 0px' } return (
{this.props.type === "new" ? : } { this.props.type === "new" ? : }
{this.props.type === "new" ? "Add new room" : "Modify room" }

Insert the name of the room:

Insert an image of the room:

this.fileInputRef.current.click()}/>

Select an icon:

{this.props.type === "modify" ? : null }
) } }