@@ -20,8 +20,12 @@ class HideImageForm extends React.PureComponent {
20
20
21
21
handleChange ( event ) {
22
22
event . preventDefault ( ) ;
23
+ const id = parseInt ( event . target . value , 10 ) ;
24
+ if ( isNaN ( id ) ) {
25
+ return ;
26
+ }
23
27
this . setState ( {
24
- comment : event . target . value
28
+ imageId : id
25
29
} ) ;
26
30
}
27
31
@@ -34,45 +38,46 @@ class HideImageForm extends React.PureComponent {
34
38
validationErrors : [ ]
35
39
} ) ;
36
40
37
- axios . patch (
38
- this . props . url , [
39
- {
40
- op : 'add' ,
41
- path : '/comment' ,
42
- value : this . state . imageId
43
- }
44
- ] ,
41
+ axios . post (
42
+ this . props . url ,
43
+ {
44
+ 'action' : 'HIDE' ,
45
+ 'imageId' : this . state . imageId
46
+ } ,
45
47
{
46
48
headers : {
47
49
[ this . props . csrfHeaderName ] : this . props . csrfTokenValue ,
48
50
'Cache-Control' : 'no-store'
49
51
} ,
50
- validateStatus : status => {
52
+ validateStatus : ( status ) => {
51
53
return status == 204 || status == 400 ;
52
54
}
53
- } )
54
- . then ( response => {
55
- const data = response . data ;
55
+ }
56
+ ) . then ( response => {
57
+ const data = response . data ;
56
58
57
- if ( data . hasOwnProperty ( 'fieldErrors' ) ) {
58
- const fieldErrors = [ ] ;
59
- if ( data . fieldErrors . value ) {
60
- fieldErrors . push ( ...data . fieldErrors . value ) ;
61
- }
62
- this . setState ( {
63
- isDisabled : false ,
64
- validationErrors : fieldErrors
65
- } ) ;
66
- return ;
59
+ if ( data . hasOwnProperty ( 'fieldErrors' ) ) {
60
+ const fieldErrors = [ ] ;
61
+ if ( data . fieldErrors . action ) {
62
+ fieldErrors . push ( ...data . fieldErrors . action ) ;
67
63
}
64
+ if ( data . fieldErrors . imageId ) {
65
+ fieldErrors . push ( ...data . fieldErrors . imageId ) ;
66
+ }
67
+ this . setState ( {
68
+ isDisabled : false ,
69
+ validationErrors : fieldErrors
70
+ } ) ;
71
+ return ;
72
+ }
68
73
69
- // no need to reset the state as page will be reloaded
70
- window . location . reload ( ) ;
71
- } )
72
- . catch ( error => {
73
- console . error ( error ) ;
74
- this . setState ( { isDisabled : false , hasServerError : true } ) ;
75
- } ) ;
74
+ // no need to reset the state as page will be reloaded
75
+ window . location . reload ( ) ;
76
+ } )
77
+ . catch ( error => {
78
+ console . error ( error ) ;
79
+ this . setState ( { isDisabled : false , hasServerError : true } ) ;
80
+ } ) ;
76
81
}
77
82
render ( ) {
78
83
return (
@@ -118,7 +123,7 @@ class HideImageFormView extends React.PureComponent {
118
123
< option value = "" > { l10n [ 't_not_chosen' ] || 'Not chosen' } </ option >
119
124
{
120
125
this . props . imageIds . map ( imageId =>
121
- < option key = { imageId } value = " { imageId }" > { imageId } </ option >
126
+ < option key = { imageId } value = { imageId } > { imageId } </ option >
122
127
)
123
128
}
124
129
</ select >
0 commit comments