| author | salimr <riwad.salim@yahoo.fr> |
| Mon, 08 Oct 2018 04:09:19 +0200 | |
| changeset 161 | a642639dbc07 |
| parent 155 | e55ae84508bf |
| child 167 | 1f340f3597a8 |
| permissions | -rw-r--r-- |
| 152 | 1 |
import React, { Component } from 'react'; |
2 |
import Modal from 'react-modal'; |
|
|
155
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
3 |
import PropTypes from 'prop-types'; |
| 152 | 4 |
import uuidV1 from 'uuid/v1'; |
5 |
import '../App.css'; |
|
6 |
import './CreateSession.css'; |
|
7 |
||
|
155
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
8 |
export default class CreateSession extends Component { |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
9 |
|
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
10 |
static propTypes = { |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
11 |
history: PropTypes.object.isRequired, |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
12 |
group: PropTypes.object.isRequired, |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
13 |
createSession: PropTypes.func.isRequired, |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
14 |
}; |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
15 |
|
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
16 |
state = { |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
17 |
createGroup: false, |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
18 |
protocolOpen: false, |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
19 |
title: "", |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
20 |
description: "" |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
21 |
// protocol:null |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
22 |
} |
| 152 | 23 |
|
24 |
componentWillMount() { |
|
25 |
Modal.setAppElement('body'); |
|
26 |
} |
|
27 |
||
28 |
||
29 |
openSessionModal = () => { |
|
30 |
this.setState({modalIsOpen: true}); |
|
31 |
} |
|
32 |
||
33 |
createSession = () => { |
|
34 |
const sessionId = uuidV1(); |
|
|
155
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
35 |
const groupName = this.props.group ? this.props.group.get('name') : null; |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
36 |
const protocol = this.props.group ? this.props.group.get('protocol') : null; |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
37 |
const {title, description} = this.state; |
| 152 | 38 |
|
|
155
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
39 |
this.props.createSession(sessionId, groupName, protocol, title, description); |
| 152 | 40 |
this.props.history.push('/sessions/' + sessionId); |
41 |
} |
|
42 |
||
43 |
getGroupProtocol = () => { |
|
|
155
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
44 |
if (this.props.group) { |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
45 |
return this.props.group.protocol; |
| 152 | 46 |
} |
|
155
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
47 |
return null; |
| 152 | 48 |
} |
49 |
||
|
155
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
50 |
onChange = (e) => { |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
51 |
const { name, value } = e.target; |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
52 |
this.setState({[name]: value}); |
| 152 | 53 |
} |
54 |
||
55 |
toggleProtocol = () => { |
|
56 |
this.setState({ |
|
57 |
protocolOpen: !this.state.protocolOpen, |
|
58 |
show: false |
|
59 |
}); |
|
60 |
} |
|
61 |
||
62 |
closeModal = () => { |
|
63 |
this.setState({modalIsOpen: false}); |
|
64 |
} |
|
65 |
||
66 |
handleModalCloseRequest = (e) => { |
|
67 |
e.preventDefault(); |
|
68 |
this.setState({modalIsOpen: false}); |
|
69 |
} |
|
70 |
||
71 |
render() { |
|
72 |
||
73 |
return ( |
|
74 |
<div> |
|
|
154
a28361bda28c
Adapt all css classes with Bootstrap 4 Utilities
salimr <riwad.salim@yahoo.fr>
parents:
152
diff
changeset
|
75 |
<a id="session-button" className="text-center" onClick={this.openSessionModal}>Créer une nouvelle session</a> |
| 152 | 76 |
<Modal |
|
154
a28361bda28c
Adapt all css classes with Bootstrap 4 Utilities
salimr <riwad.salim@yahoo.fr>
parents:
152
diff
changeset
|
77 |
className="Modal__Bootstrap modal-dialog" |
| 152 | 78 |
isOpen={this.state.modalIsOpen} |
79 |
onRequestClose={this.handleModalCloseRequest} |
|
80 |
> |
|
|
161
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
155
diff
changeset
|
81 |
<div className="modal-content bg-primary w-75 mt-5"> |
|
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
155
diff
changeset
|
82 |
<div className="modal-body mt-3"> |
| 152 | 83 |
<form onSubmit={ e => { e.preventDefault() } }> |
84 |
<div className="form-group"> |
|
|
154
a28361bda28c
Adapt all css classes with Bootstrap 4 Utilities
salimr <riwad.salim@yahoo.fr>
parents:
152
diff
changeset
|
85 |
<label className="col-form-label text-secondary font-weight-bold pt-3">Titre</label> |
|
a28361bda28c
Adapt all css classes with Bootstrap 4 Utilities
salimr <riwad.salim@yahoo.fr>
parents:
152
diff
changeset
|
86 |
<input className="form-control text-primary w-100" |
| 152 | 87 |
name="title" |
88 |
onChange={ this.onChange } |
|
89 |
type="text" |
|
90 |
placeholder="Entrez un titre" |
|
91 |
/> |
|
92 |
</div> |
|
93 |
<div className="form-group"> |
|
|
154
a28361bda28c
Adapt all css classes with Bootstrap 4 Utilities
salimr <riwad.salim@yahoo.fr>
parents:
152
diff
changeset
|
94 |
<label className="col-form-label text-secondary font-weight-bold pt-3 mt-3">Description</label> |
|
a28361bda28c
Adapt all css classes with Bootstrap 4 Utilities
salimr <riwad.salim@yahoo.fr>
parents:
152
diff
changeset
|
95 |
<textarea className="form-control text-primary w-100" |
| 152 | 96 |
type="textarea" |
97 |
name="description" |
|
98 |
onChange={ this.onChange } |
|
99 |
placeholder="Entrez une description" |
|
|
155
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
100 |
></textarea> |
| 152 | 101 |
</div> |
102 |
<div className="form-group"> |
|
|
154
a28361bda28c
Adapt all css classes with Bootstrap 4 Utilities
salimr <riwad.salim@yahoo.fr>
parents:
152
diff
changeset
|
103 |
<label className="col-form-label text-secondary font-weight-bold mt-5 ml-5" onClick={this.toggleProtocol}>Protocole de la prise de note {this.state.protocolOpen?<span className="material-icons protocol-toggle"></span>:<span className="material-icons protocol-toggle"></span>}</label> |
|
161
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
155
diff
changeset
|
104 |
<div className={ "collapse" + (this.state.protocolOpen?'in':'')} > |
| 152 | 105 |
{/* <pre>{JSON.stringify(this.props.currentSession.protocol, null, 2)}</pre> */} |
|
161
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
155
diff
changeset
|
106 |
<pre className="text-secondary">{JSON.stringify(this.getGroupProtocol(), null, 2)}</pre> |
| 152 | 107 |
</div> |
108 |
</div> |
|
109 |
<div className="text-center"> |
|
|
154
a28361bda28c
Adapt all css classes with Bootstrap 4 Utilities
salimr <riwad.salim@yahoo.fr>
parents:
152
diff
changeset
|
110 |
<button id="create-button" type="submit" className="btn btn-secondary btn-lg text-primary font-weight-bold m-3" onClick={this.createSession}>Commencer</button> |
| 152 | 111 |
</div> |
112 |
</form> |
|
113 |
</div> |
|
114 |
</div> |
|
115 |
</Modal> |
|
116 |
</div> |
|
117 |
); |
|
118 |
} |
|
119 |
} |