| author | ymh <ymh.work@gmail.com> |
| Tue, 04 Dec 2018 18:17:56 +0100 | |
| changeset 191 | 3f71ad81a5a9 |
| parent 172 | 4b780ebbedc6 |
| child 193 | 99e342f9fb0c |
| 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'; |
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
5 |
import { withNamespaces } from 'react-i18next'; |
| 152 | 6 |
|
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
7 |
class CreateSession extends Component { |
|
155
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
8 |
|
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
9 |
static propTypes = { |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
10 |
history: PropTypes.object.isRequired, |
|
168
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
167
diff
changeset
|
11 |
group: PropTypes.object, |
|
155
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
12 |
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
|
13 |
}; |
|
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 |
state = { |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
16 |
createGroup: false, |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
17 |
protocolOpen: false, |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
18 |
title: "", |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
19 |
description: "" |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
20 |
} |
| 152 | 21 |
|
22 |
componentWillMount() { |
|
23 |
Modal.setAppElement('body'); |
|
24 |
} |
|
25 |
||
26 |
||
27 |
openSessionModal = () => { |
|
28 |
this.setState({modalIsOpen: true}); |
|
29 |
} |
|
30 |
||
31 |
createSession = () => { |
|
32 |
const sessionId = uuidV1(); |
|
|
168
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
167
diff
changeset
|
33 |
const groupName = this.props.group ? this.props.group.name : null; |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
167
diff
changeset
|
34 |
const protocol = this.props.group ? this.props.group.protocol : null; |
|
155
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
35 |
const {title, description} = this.state; |
| 152 | 36 |
|
|
155
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
37 |
this.props.createSession(sessionId, groupName, protocol, title, description); |
| 152 | 38 |
this.props.history.push('/sessions/' + sessionId); |
39 |
} |
|
40 |
||
41 |
getGroupProtocol = () => { |
|
|
155
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
42 |
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
|
43 |
return this.props.group.protocol; |
| 152 | 44 |
} |
|
155
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
45 |
return null; |
| 152 | 46 |
} |
47 |
||
|
155
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
48 |
onChange = (e) => { |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
49 |
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
|
50 |
this.setState({[name]: value}); |
| 152 | 51 |
} |
52 |
||
53 |
toggleProtocol = () => { |
|
54 |
this.setState({ |
|
55 |
protocolOpen: !this.state.protocolOpen, |
|
56 |
show: false |
|
57 |
}); |
|
58 |
} |
|
59 |
||
60 |
closeModal = () => { |
|
61 |
this.setState({modalIsOpen: false}); |
|
62 |
} |
|
63 |
||
64 |
handleModalCloseRequest = (e) => { |
|
65 |
e.preventDefault(); |
|
66 |
this.setState({modalIsOpen: false}); |
|
67 |
} |
|
68 |
||
69 |
render() { |
|
70 |
||
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
71 |
const t = this.props.t; |
| 152 | 72 |
return ( |
|
167
1f340f3597a8
Adapt css for CreateSession and Navbar components
salimr <riwad.salim@yahoo.fr>
parents:
161
diff
changeset
|
73 |
<div className="container-fluid"> |
| 172 | 74 |
<span className="nav-link btn" onClick={this.openSessionModal}>{t('create_session.new_session')}</span> |
| 152 | 75 |
<Modal |
|
167
1f340f3597a8
Adapt css for CreateSession and Navbar components
salimr <riwad.salim@yahoo.fr>
parents:
161
diff
changeset
|
76 |
className="Modal__Bootstrap modal-dialog ml-5 mt-5 fixed-top w-100" |
| 152 | 77 |
isOpen={this.state.modalIsOpen} |
78 |
onRequestClose={this.handleModalCloseRequest} |
|
79 |
> |
|
|
167
1f340f3597a8
Adapt css for CreateSession and Navbar components
salimr <riwad.salim@yahoo.fr>
parents:
161
diff
changeset
|
80 |
<div className="modal-content bg-primary w-75"> |
|
161
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
155
diff
changeset
|
81 |
<div className="modal-body mt-3"> |
| 152 | 82 |
<form onSubmit={ e => { e.preventDefault() } }> |
83 |
<div className="form-group"> |
|
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
84 |
<label className="col-form-label text-secondary font-weight-bold pt-3 text-capitalize">{t('common.title')}</label> |
|
154
a28361bda28c
Adapt all css classes with Bootstrap 4 Utilities
salimr <riwad.salim@yahoo.fr>
parents:
152
diff
changeset
|
85 |
<input className="form-control text-primary w-100" |
| 152 | 86 |
name="title" |
87 |
onChange={ this.onChange } |
|
88 |
type="text" |
|
89 |
placeholder="Entrez un titre" |
|
90 |
/> |
|
91 |
</div> |
|
92 |
<div className="form-group"> |
|
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
93 |
<label className="col-form-label text-secondary font-weight-bold pt-3 mt-3 text-capitalize">{t('common.description')}</label> |
|
154
a28361bda28c
Adapt all css classes with Bootstrap 4 Utilities
salimr <riwad.salim@yahoo.fr>
parents:
152
diff
changeset
|
94 |
<textarea className="form-control text-primary w-100" |
| 152 | 95 |
type="textarea" |
96 |
name="description" |
|
97 |
onChange={ this.onChange } |
|
98 |
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
|
99 |
></textarea> |
| 152 | 100 |
</div> |
101 |
<div className="form-group"> |
|
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
102 |
<label className="col-form-label text-secondary font-weight-bold mt-5 ml-5" onClick={this.toggleProtocol}>{t('create_session.protocol')} {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
|
103 |
<div className={ "collapse" + (this.state.protocolOpen?'in':'')} > |
| 152 | 104 |
{/* <pre>{JSON.stringify(this.props.currentSession.protocol, null, 2)}</pre> */} |
|
167
1f340f3597a8
Adapt css for CreateSession and Navbar components
salimr <riwad.salim@yahoo.fr>
parents:
161
diff
changeset
|
105 |
<pre className=" protocol text-secondary">{JSON.stringify(this.getGroupProtocol(), null, 2)}</pre> |
| 152 | 106 |
</div> |
107 |
</div> |
|
108 |
<div className="text-center"> |
|
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
109 |
<button id="create-button" type="submit" className="btn btn-secondary btn-lg text-primary font-weight-bold m-3 text-capitalize" onClick={this.createSession}>{t('common.begin')}</button> |
| 152 | 110 |
</div> |
111 |
</form> |
|
112 |
</div> |
|
113 |
</div> |
|
114 |
</Modal> |
|
115 |
</div> |
|
116 |
); |
|
117 |
} |
|
118 |
} |
|
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
119 |
|
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
120 |
export default withNamespaces()(CreateSession); |