@@ -7,8 +7,8 @@ import NavItem from 'react-bootstrap/lib/NavItem';
7
7
import Alert from 'react-bootstrap/lib/Alert' ;
8
8
import ReactCSSTransitionGroup from 'react/lib/ReactCSSTransitionGroup' ;
9
9
import _ from 'lodash' ;
10
- import I18n from 'i18n-js ' ;
11
-
10
+ import { injectIntl , intlShape } from 'react-intl ' ;
11
+ import { defaultMessages } from '../../../common/i18nHelper' ;
12
12
import BaseComponent from 'libs/components/BaseComponent' ;
13
13
14
14
const emptyComment = { author : '' , text : '' } ;
@@ -22,12 +22,13 @@ function bsStyleFor(propName, error) {
22
22
return null ;
23
23
}
24
24
25
- export default class CommentForm extends BaseComponent {
25
+ class CommentForm extends BaseComponent {
26
26
static propTypes = {
27
27
isSaving : PropTypes . bool . isRequired ,
28
28
actions : PropTypes . object . isRequired ,
29
29
error : PropTypes . any ,
30
30
cssTransitionGroupClassNames : PropTypes . object . isRequired ,
31
+ intl : intlShape . isRequired ,
31
32
} ;
32
33
33
34
constructor ( props , context ) {
@@ -114,16 +115,17 @@ export default class CommentForm extends BaseComponent {
114
115
}
115
116
116
117
formHorizontal ( ) {
118
+ const { formatMessage } = this . props . intl ;
117
119
return (
118
120
< div >
119
121
< hr />
120
- < form className = " commentForm form-horizontal" onSubmit = { this . handleSubmit } >
122
+ < form className = ' commentForm form-horizontal' onSubmit = { this . handleSubmit } >
121
123
< Input
122
- type = " text"
123
- label = { I18n . t ( 'input.name.label' ) }
124
- placeholder = { I18n . t ( 'input.name.placeholder' ) }
125
- labelClassName = " col-sm-2"
126
- wrapperClassName = " col-sm-10"
124
+ type = ' text'
125
+ label = { formatMessage ( defaultMessages . inputNameLabel ) }
126
+ placeholder = { formatMessage ( defaultMessages . inputNamePlaceholder ) }
127
+ labelClassName = ' col-sm-2'
128
+ wrapperClassName = ' col-sm-10'
127
129
ref = { node => { this . horizontalAuthorNode = node ; } }
128
130
value = { this . state . comment . author }
129
131
onChange = { this . handleChange }
@@ -132,24 +134,26 @@ export default class CommentForm extends BaseComponent {
132
134
bsStyle = { bsStyleFor ( 'author' , this . props . error ) }
133
135
/>
134
136
< Input
135
- type = " textarea"
136
- label = { I18n . t ( 'input.text.label' ) }
137
- placeholder = { I18n . t ( 'input.text.placeholder' ) }
138
- labelClassName = " col-sm-2"
139
- wrapperClassName = " col-sm-10"
137
+ type = ' textarea'
138
+ label = { formatMessage ( defaultMessages . inputTextLabel ) }
139
+ placeholder = { formatMessage ( defaultMessages . inputTextPlaceholder ) }
140
+ labelClassName = ' col-sm-2'
141
+ wrapperClassName = ' col-sm-10'
140
142
ref = { node => { this . horizontalTextNode = node ; } }
141
143
value = { this . state . comment . text }
142
144
onChange = { this . handleChange }
143
145
disabled = { this . props . isSaving }
144
146
hasFeedback
145
147
bsStyle = { bsStyleFor ( 'text' , this . props . error ) }
146
148
/>
147
- < div className = " form-group" >
148
- < div className = " col-sm-offset-2 col-sm-10" >
149
+ < div className = ' form-group' >
150
+ < div className = ' col-sm-offset-2 col-sm-10' >
149
151
< input
150
- type = "submit"
151
- className = "btn btn-primary"
152
- value = { this . props . isSaving ? `${ I18n . t ( 'input.saving' ) } ...` : I18n . t ( 'input.post' ) }
152
+ type = 'submit'
153
+ className = 'btn btn-primary'
154
+ value = { this . props . isSaving
155
+ ? `${ formatMessage ( defaultMessages . inputSaving ) } ...`
156
+ : formatMessage ( defaultMessages . inputPost ) }
153
157
disabled = { this . props . isSaving }
154
158
/>
155
159
</ div >
@@ -160,14 +164,15 @@ export default class CommentForm extends BaseComponent {
160
164
}
161
165
162
166
formStacked ( ) {
167
+ const { formatMessage } = this . props . intl ;
163
168
return (
164
169
< div >
165
170
< hr />
166
- < form className = " commentForm form" onSubmit = { this . handleSubmit } >
171
+ < form className = ' commentForm form' onSubmit = { this . handleSubmit } >
167
172
< Input
168
- type = " text"
169
- label = { I18n . t ( 'input.name.label' ) }
170
- placeholder = { I18n . t ( 'input.name.placeholder' ) }
173
+ type = ' text'
174
+ label = { formatMessage ( defaultMessages . inputNameLabel ) }
175
+ placeholder = { formatMessage ( defaultMessages . inputNamePlaceholder ) }
171
176
ref = { node => { this . stackedAuthorNode = node ; } }
172
177
value = { this . state . comment . author }
173
178
onChange = { this . handleChange }
@@ -176,9 +181,9 @@ export default class CommentForm extends BaseComponent {
176
181
bsStyle = { bsStyleFor ( 'author' , this . props . error ) }
177
182
/>
178
183
< Input
179
- type = " textarea"
180
- label = { I18n . t ( 'input.text.label' ) }
181
- placeholder = { I18n . t ( 'input.text.placeholder' ) }
184
+ type = ' textarea'
185
+ label = { formatMessage ( defaultMessages . inputTextLabel ) }
186
+ placeholder = { formatMessage ( defaultMessages . inputTextPlaceholder ) }
182
187
ref = { node => { this . stackedTextNode = node ; } }
183
188
value = { this . state . comment . text }
184
189
onChange = { this . handleChange }
@@ -187,9 +192,11 @@ export default class CommentForm extends BaseComponent {
187
192
bsStyle = { bsStyleFor ( 'text' , this . props . error ) }
188
193
/>
189
194
< input
190
- type = "submit"
191
- className = "btn btn-primary"
192
- value = { this . props . isSaving ? `${ I18n . t ( 'input.saving' ) } ...` : I18n . t ( 'input.post' ) }
195
+ type = 'submit'
196
+ className = 'btn btn-primary'
197
+ value = { this . props . isSaving
198
+ ? `${ formatMessage ( defaultMessages . inputSaving ) } ...`
199
+ : formatMessage ( defaultMessages . inputPost ) }
193
200
disabled = { this . props . isSaving }
194
201
/>
195
202
</ form >
@@ -198,17 +205,21 @@ export default class CommentForm extends BaseComponent {
198
205
}
199
206
200
207
formInline ( ) {
208
+ const { formatMessage } = this . props . intl ;
201
209
return (
202
210
< div >
203
211
< hr />
204
- < form className = "commentForm form" onSubmit = { this . handleSubmit } >
205
- < Input label = "Inline Form" wrapperClassName = "wrapper" >
212
+ < form className = 'commentForm form' onSubmit = { this . handleSubmit } >
213
+ < Input
214
+ label = { formatMessage ( defaultMessages . formInline ) }
215
+ wrapperClassName = 'wrapper'
216
+ >
206
217
< Row >
207
218
< Col xs = { 3 } >
208
219
< input
209
- type = " text"
210
- className = " form-control"
211
- placeholder = { I18n . t ( 'input.name.placeholder' ) }
220
+ type = ' text'
221
+ className = ' form-control'
222
+ placeholder = { formatMessage ( defaultMessages . inputNamePlaceholder ) }
212
223
ref = { node => { this . inlineAuthorNode = node ; } }
213
224
value = { this . state . comment . author }
214
225
onChange = { this . handleChange }
@@ -217,9 +228,9 @@ export default class CommentForm extends BaseComponent {
217
228
</ Col >
218
229
< Col xs = { 8 } >
219
230
< input
220
- type = " text"
221
- className = " form-control"
222
- placeholder = { I18n . t ( 'input.text.placeholder' ) }
231
+ type = ' text'
232
+ className = ' form-control'
233
+ placeholder = { formatMessage ( defaultMessages . inputTextPlaceholder ) }
223
234
ref = { node => { this . inlineTextNode = node ; } }
224
235
value = { this . state . comment . text }
225
236
onChange = { this . handleChange }
@@ -228,12 +239,11 @@ export default class CommentForm extends BaseComponent {
228
239
</ Col >
229
240
< Col xs = { 1 } >
230
241
< input
231
- type = " submit"
232
- className = " btn btn-primary"
242
+ type = ' submit'
243
+ className = ' btn btn-primary'
233
244
value = { this . props . isSaving
234
- ? `${ I18n . t ( 'input.saving' ) } ...`
235
- : I18n . t ( 'input.post' )
236
- }
245
+ ? `${ formatMessage ( defaultMessages . inputSaving ) } ...`
246
+ : formatMessage ( defaultMessages . inputPost ) }
237
247
disabled = { this . props . isSaving }
238
248
/>
239
249
</ Col >
@@ -257,7 +267,7 @@ export default class CommentForm extends BaseComponent {
257
267
} , [ ] ) ;
258
268
259
269
return (
260
- < Alert bsStyle = " danger" key = " commentSubmissionError" >
270
+ < Alert bsStyle = ' danger' key = ' commentSubmissionError' >
261
271
< strong > Your comment was not saved!</ strong >
262
272
< ul >
263
273
{ errorElements }
@@ -283,6 +293,7 @@ export default class CommentForm extends BaseComponent {
283
293
}
284
294
285
295
const { cssTransitionGroupClassNames } = this . props ;
296
+ const { formatMessage } = this . props . intl ;
286
297
287
298
return (
288
299
< div >
@@ -294,13 +305,15 @@ export default class CommentForm extends BaseComponent {
294
305
{ this . errorWarning ( ) }
295
306
</ ReactCSSTransitionGroup >
296
307
297
- < Nav bsStyle = " pills" activeKey = { this . state . formMode } onSelect = { this . handleSelect } >
298
- < NavItem eventKey = { 0 } > { I18n . t ( 'form.horizontal' ) } </ NavItem >
299
- < NavItem eventKey = { 1 } > { I18n . t ( 'form.stacked' ) } </ NavItem >
300
- < NavItem eventKey = { 2 } > { I18n . t ( 'form.inline' ) } </ NavItem >
308
+ < Nav bsStyle = ' pills' activeKey = { this . state . formMode } onSelect = { this . handleSelect } >
309
+ < NavItem eventKey = { 0 } > { formatMessage ( defaultMessages . formHorizontal ) } </ NavItem >
310
+ < NavItem eventKey = { 1 } > { formatMessage ( defaultMessages . formStacked ) } </ NavItem >
311
+ < NavItem eventKey = { 2 } > { formatMessage ( defaultMessages . formInline ) } </ NavItem >
301
312
</ Nav >
302
313
{ inputForm }
303
314
</ div >
304
315
) ;
305
316
}
306
317
}
318
+
319
+ export default injectIntl ( CommentForm ) ;
0 commit comments