Merge branch '5-add-delete-or-modify-rooms' into 'dev'

Resolve "Add, Delete, or Modify rooms"

Closes #5

See merge request sa4-2020/the-sanmarinoes/frontend!31
This commit is contained in:
Claudio Maggioni 2020-03-17 17:35:55 +01:00
commit 707a5630fc
16 changed files with 48 additions and 27 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 644 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 320 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

View file

@ -7,7 +7,8 @@ export default class ModalWindow extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
selectedIcon: 'home', id : "",
selectedIcon: "",
name: "", name: "",
img: "", img: "",
openModal: false openModal: false
@ -23,14 +24,26 @@ export default class ModalWindow extends Component {
"name" : this.state.name, "name" : this.state.name,
"images" : this.state.img "images" : this.state.img
} }
console.log(this.props, data);
this.props.addRoom(data); this.props.addRoom(data);
this.closeModal(); this.closeModal();
} }
modifyRoomModal = (e) => {
let data = {
"icon" : this.state.selectedIcon,
"name" : this.state.name,
"images" : this.state.img
}
this.props.updateRoom(data);
this.closeModal();
}
deleteRoom = (e) => { deleteRoom = (e) => {
console.log(e); let data = {
"id" : this.state.id
}
this.props.deleteRoom(data);
this.closeModal();
} }
changeSomething = (event) => { changeSomething = (event) => {
@ -49,7 +62,6 @@ export default class ModalWindow extends Component {
} }
updateIcon(e) { updateIcon(e) {
console.log(e);
this.setState({selectedIcon : e}) this.setState({selectedIcon : e})
} }
@ -64,10 +76,16 @@ export default class ModalWindow extends Component {
return ( return (
<div> <div>
{this.props.type == "new" ?
<Button icon labelPosition='left' inverted onClick={this.openModal}> <Button icon labelPosition='left' inverted onClick={this.openModal}>
<Icon name='plus' size='small'/> <Icon name='plus' size='small'/>
ADD ROOM ADD ROOM
</Button> </Button>
:
<Icon name="pencil" size="small" onClick={this.openModal}/>
}
<Modal <Modal
onClose={this.closeModal} onClose={this.closeModal}
open={this.state.openModal}> open={this.state.openModal}>
@ -76,16 +94,19 @@ export default class ModalWindow extends Component {
<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 label='Room name' placeholder='Room Name' name="name" type='text' onChange={this.changeSomething}
value={this.props.type == "new" ? null : this.props.idRoom.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 label='Room image' type='file' name="img" onChange={this.changeSomething}
value={this.props.type == "new" ? null : this.props.idRoom.images }/>
</Form.Field> </Form.Field>
</Form> </Form>
<div style={spaceDiv}> <div style={spaceDiv}>
<p>Select an icon:</p> <p>Select an icon:</p>
{this.props.selectedIcon == "new" ? "home" : this.props.idRoom.icon }
<SelectIcons updateIcon={this.updateIcon} currentIcon={this.state.selectedIcon}/> <SelectIcons updateIcon={this.updateIcon} currentIcon={this.state.selectedIcon}/>
</div> </div>
@ -100,9 +121,12 @@ export default class ModalWindow extends Component {
<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 color='green' onClick={this.addRoomModal}>
<Icon name='checkmark' /> {this.props.type == "new" ? "Add room" : "Save changes" }
<Button color='green' onClick={this.props.type == "new" ? this.addRoomModal : this.modifyRoomModal}>
<Icon name='checkmark' /> {this.props.type == "new" ? "Add room" : "Save changes"}
</Button> </Button>
</Modal.Actions> </Modal.Actions>
</Modal> </Modal>
</div> </div>

View file

@ -8,17 +8,14 @@ class Navbar extends Component {
super(props); super(props);
this.state = { this.state = {
activeItem: 'Home', activeItem: 'Home',
edited: "" edited: "",
editMode : false
} }
} }
showForm = (event) => { editModeController = (e) => {
console.log(event); this.setState((prevState) => ({ editMode: !prevState.editMode }));
if (event === "new"){ };
console.log("funziona");
return (<ModalWindow type="new"/>)
}
}
handleClick = (e, { i }) => { handleClick = (e, { i }) => {
this.setState({ activeItem: e.name, this.setState({ activeItem: e.name,
@ -50,7 +47,7 @@ class Navbar extends Component {
<Icon name="home" size="small"/> <Icon name="home" size="small"/>
</Grid.Column> </Grid.Column>
<Grid.Column> <Grid.Column>
Home HOME
</Grid.Column> </Grid.Column>
</Grid.Row> </Grid.Row>
</Grid> </Grid>
@ -69,20 +66,21 @@ class Navbar extends Component {
> >
<Grid> <Grid>
<Grid.Row> <Grid.Row>
<Grid.Column width={1}> <Grid.Column>
<Icon name={e.icon} size="small"/> <Icon name={e.icon} size="small"/>
</Grid.Column> </Grid.Column>
<Grid.Column width={12}> <Grid.Column width={8}>
{e.name} {e.name}
</Grid.Column> </Grid.Column>
<Grid.Column width={1}> <Grid.Column floated="right">
<Icon name="pencil" size="small"/> {this.state.edit ?
<ModalWindow type="modify" idRoom={e} modifyRoom={this.props.updateRoom} deleteRoom={this.props.deleteRoom}/>
: null
}
</Grid.Column> </Grid.Column>
</Grid.Row> </Grid.Row>
</Grid> </Grid>
</ Menu.Item> </ Menu.Item>
) )
}) : null }) : null
} }
@ -91,11 +89,10 @@ class Navbar extends Component {
name='newM' name='newM'
active={activeItem === 'Plus'} active={activeItem === 'Plus'}
> >
<Grid> <Grid>
<Grid.Row centered onClick={this.showForm} name='new'> <Grid.Row centered name='new'>
<ModalWindow type="new" addRoom={this.props.addRoom}/> <ModalWindow type="new" addRoom={this.props.addRoom}/>
</Grid.Row> </Grid.Row>
</Grid> </Grid>