@@ -10,7 +10,8 @@ class ChatRoomEditorModal extends Component {
1010 this . state = {
1111 modal : false ,
1212 nameInput : '' ,
13- descInput : ''
13+ descInput : '' ,
14+ alert : ''
1415 }
1516 this . toggle = this . toggle . bind ( this ) ;
1617 this . handleNameInput = this . handleNameInput . bind ( this ) ;
@@ -27,7 +28,9 @@ class ChatRoomEditorModal extends Component {
2728 */
2829
2930 editChatRoom ( ) {
30- editChatRoom ( this . props . chatRoomId , this . state . nameInput , this . state . descInput ) ;
31+ editChatRoom ( this . props . chatRoomId , this . state . nameInput , this . state . descInput ) . then ( jsonResponse => {
32+ this . handleResponseFromAPI ( jsonResponse ) ;
33+ } ) ;
3134 }
3235
3336 setFieldsValue ( ) {
@@ -46,6 +49,23 @@ class ChatRoomEditorModal extends Component {
4649 }
4750 }
4851
52+ handleResponseFromAPI ( jsonResponse ) {
53+ switch ( jsonResponse . response ) {
54+ case "INSUFFICIENT_RIGHTS" :
55+ this . setAlert ( 'warning' , "It seems that you don't have right to do that." ) ;
56+ break ;
57+ case "CHAT_ROOM_NAME_TAKEN" :
58+ this . setAlert ( 'warning' , "Well this name is already taken, think about something else." ) ;
59+ break ;
60+ case "CANT_UPDATE_CHAT_ROOM_THAT_DOESNT_EXIST" :
61+ this . setAlert ( 'warning' , "Are you trying to edit a room that doesn't exist?" ) ;
62+ break ;
63+ case "CHAT_ROOM_UPDATED_SUCCESSFULLY" :
64+ this . setAlert ( 'success' , "ChatRoom has been edited successfully" ) ;
65+ break ;
66+ }
67+ }
68+
4969 /**
5070 * DOM related
5171 */
@@ -68,12 +88,22 @@ class ChatRoomEditorModal extends Component {
6888 } )
6989 }
7090
91+ setAlert ( type , message ) {
92+ const alertClass = 'alert alert-' + type ;
93+ this . setState ( {
94+ alert : < div className = { alertClass } role = 'alert' > { message } </ div >
95+ } )
96+ }
97+
7198 render ( ) {
99+ const alert = this . state . alert ;
100+
72101 return (
73102 < div >
74103 < Modal isOpen = { this . state . modal } toggle = { this . toggle } >
75104 < ModalHeader toggle = { this . toggle } > Edit ChatRoom</ ModalHeader >
76105 < ModalBody >
106+ { alert }
77107 < label > Name:</ label >
78108 < input type = "text" className = "form-control" value = { this . state . nameInput } onChange = { this . handleNameInput } />
79109 < label > Description:</ label >
0 commit comments