| author | ymh <ymh.work@gmail.com> |
| Tue, 13 Nov 2018 16:46:15 +0100 | |
| changeset 172 | 4b780ebbedc6 |
| parent 171 | 03334a31130a |
| child 191 | 3f71ad81a5a9 |
| 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 |
import '../App.css'; |
7 |
import './CreateSession.css'; |
|
8 |
||
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
9 |
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
|
10 |
|
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
11 |
static propTypes = { |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
12 |
history: PropTypes.object.isRequired, |
|
168
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
167
diff
changeset
|
13 |
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
|
14 |
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
|
15 |
}; |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
16 |
|
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
17 |
state = { |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
18 |
createGroup: false, |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
19 |
protocolOpen: false, |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
20 |
title: "", |
|
e55ae84508bf
Clean CreateSession component and remove trace of previous create session button
ymh <ymh.work@gmail.com>
parents:
154
diff
changeset
|
21 |
description: "" |
|
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(); |
|
|
168
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
167
diff
changeset
|
35 |
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
|
36 |
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
|
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 |
||
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
73 |
const t = this.props.t; |
| 152 | 74 |
return ( |
|
167
1f340f3597a8
Adapt css for CreateSession and Navbar components
salimr <riwad.salim@yahoo.fr>
parents:
161
diff
changeset
|
75 |
<div className="container-fluid"> |
| 172 | 76 |
<span className="nav-link btn" onClick={this.openSessionModal}>{t('create_session.new_session')}</span> |
| 152 | 77 |
<Modal |
|
167
1f340f3597a8
Adapt css for CreateSession and Navbar components
salimr <riwad.salim@yahoo.fr>
parents:
161
diff
changeset
|
78 |
className="Modal__Bootstrap modal-dialog ml-5 mt-5 fixed-top w-100" |
| 152 | 79 |
isOpen={this.state.modalIsOpen} |
80 |
onRequestClose={this.handleModalCloseRequest} |
|
81 |
> |
|
|
167
1f340f3597a8
Adapt css for CreateSession and Navbar components
salimr <riwad.salim@yahoo.fr>
parents:
161
diff
changeset
|
82 |
<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
|
83 |
<div className="modal-body mt-3"> |
| 152 | 84 |
<form onSubmit={ e => { e.preventDefault() } }> |
85 |
<div className="form-group"> |
|
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
86 |
<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
|
87 |
<input className="form-control text-primary w-100" |
| 152 | 88 |
name="title" |
89 |
onChange={ this.onChange } |
|
90 |
type="text" |
|
91 |
placeholder="Entrez un titre" |
|
92 |
/> |
|
93 |
</div> |
|
94 |
<div className="form-group"> |
|
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
95 |
<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
|
96 |
<textarea className="form-control text-primary w-100" |
| 152 | 97 |
type="textarea" |
98 |
name="description" |
|
99 |
onChange={ this.onChange } |
|
100 |
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
|
101 |
></textarea> |
| 152 | 102 |
</div> |
103 |
<div className="form-group"> |
|
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
104 |
<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
|
105 |
<div className={ "collapse" + (this.state.protocolOpen?'in':'')} > |
| 152 | 106 |
{/* <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
|
107 |
<pre className=" protocol text-secondary">{JSON.stringify(this.getGroupProtocol(), null, 2)}</pre> |
| 152 | 108 |
</div> |
109 |
</div> |
|
110 |
<div className="text-center"> |
|
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
111 |
<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 | 112 |
</div> |
113 |
</form> |
|
114 |
</div> |
|
115 |
</div> |
|
116 |
</Modal> |
|
117 |
</div> |
|
118 |
); |
|
119 |
} |
|
120 |
} |
|
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
121 |
|
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
122 |
export default withNamespaces()(CreateSession); |