@@ -58,18 +58,44 @@ module.exports = React.createClass({
5858 handleSavePlanetProfile : function ( e ) {
5959 var planet = this . props . planet
6060
61- this . setState ( { profileSubmitStatus : 'sending' } , function ( ) {
61+ this . setState ( { profileFormStatus : 'sending' , profileFormError : null } , function ( ) {
6262 Hq . updatePlanet ( planet . userName , planet . name , this . state . planet )
6363 . then ( function ( res ) {
6464 var planet = res . body
65-
66- this . setState ( { profileSubmitStatus : 'done' } )
65+ console . log ( planet )
66+ this . setState ( { profileFormStatus : 'done' } )
6767
6868 PlanetStore . Actions . update ( planet )
69+ this . props . close ( )
6970 } . bind ( this ) )
7071 . catch ( function ( err ) {
71- this . setState ( { profileSubmitStatus : 'error' } )
7272 console . error ( err )
73+ var newState = {
74+ profileFormStatus : 'error'
75+ }
76+
77+ if ( err . status == null ) {
78+ newState . profileFormError = { message : 'Check your network connection' }
79+ return this . setState ( newState )
80+ }
81+
82+ switch ( err . status ) {
83+ case 403 :
84+ newState . profileFormError = err . response . body
85+ this . setState ( newState )
86+ break
87+ case 422 :
88+ newState . profileFormError = { message : 'Planet name should be Alphanumeric with _, -' }
89+ this . setState ( newState )
90+ break
91+ case 409 :
92+ newState . profileFormError = { message : 'The entered name already in use' }
93+ this . setState ( newState )
94+ break
95+ default :
96+ newState . profileFormError = { message : 'Undefined error please try again' }
97+ this . setState ( newState )
98+ }
7399 } . bind ( this ) )
74100 } )
75101 } ,
@@ -130,11 +156,11 @@ module.exports = React.createClass({
130156 < div className = 'formConfirm' >
131157 < button onClick = { this . handleSavePlanetProfile } className = 'saveButton btn-primary' > Save</ button >
132158
133- < div className = { 'alertInfo' + ( this . state . profileSubmitStatus === 'sending' ? '' : ' hide' ) } > on Sending...</ div >
159+ < div className = { 'alertInfo' + ( this . state . profileFormStatus === 'sending' ? '' : ' hide' ) } > on Sending...</ div >
134160
135- < div className = { 'alertError' + ( this . state . profileSubmitStatus === 'error' ? '' : ' hide' ) } > Connection failed.. Try again. </ div >
161+ < div className = { 'alertError' + ( this . state . profileFormStatus === 'error' ? '' : ' hide' ) } > { this . state . profileFormError != null ? this . state . profileFormError . message : 'Unexpected error occured! please try again' } </ div >
136162
137- < div className = { 'alertSuccess' + ( this . state . profileSubmitStatus === 'done' ? '' : ' hide' ) } > Successfully done!!</ div >
163+ < div className = { 'alertSuccess' + ( this . state . profileFormStatus === 'done' ? '' : ' hide' ) } > Successfully done!!</ div >
138164 </ div >
139165 </ div >
140166 )
0 commit comments