11var React = require ( 'react/addons' )
22var ReactRouter = require ( 'react-router' )
33
4+ var ModalBase = require ( '../Components/ModalBase' )
5+
46var AuthActions = require ( '../Actions/AuthActions' )
57
6- var currentUser = {
7- name : 'testcat' ,
8- email : 'testcat@example.com' ,
9- profileName : 'Test Cat'
10- }
8+ var AuthStore = require ( '../Stores/AuthStore' )
9+
10+ var LogOutModal = React . createClass ( {
11+ propTypes : {
12+ close : React . PropTypes . func
13+ } ,
14+ componentDidMount : function ( ) {
15+ React . findDOMNode ( this . refs . cancel ) . focus ( )
16+ } ,
17+ submit : function ( ) {
18+ AuthActions . logout ( )
19+ } ,
20+ handleKeyDown : function ( e ) {
21+ if ( e . keyCode === 13 && e . metaKey ) {
22+ this . submit ( )
23+ return
24+ }
25+ if ( e . keyCode === 27 ) {
26+ this . props . close ( )
27+ return
28+ }
29+ } ,
30+ render : function ( ) {
31+ return (
32+ < div onKeyDown = { this . handleKeyDown } className = 'logOutModal modal' >
33+ < div className = 'modal-header' >
34+ < h1 > Logout</ h1 >
35+ </ div >
36+ < div className = 'modal-body' >
37+ < p > Are you sure to log out?</ p >
38+ </ div >
39+ < div className = 'modal-footer' >
40+ < div className = 'modal-control' >
41+ < button ref = 'cancel' onClick = { this . props . close } className = 'btn-default' > Cancel</ button >
42+ < button onClick = { this . submit } className = 'btn-primary' > Logout</ button >
43+ </ div >
44+ </ div >
45+ </ div >
46+ )
47+ }
48+ } )
1149
1250var UserSettingNavigation = React . createClass ( {
1351 propTypes : {
@@ -17,13 +55,21 @@ var UserSettingNavigation = React.createClass({
1755 current : React . PropTypes . string ,
1856 changeCurrent : React . PropTypes . func
1957 } ,
58+ getInitialState : function ( ) {
59+ return {
60+ isLogOutModalOpen : false
61+ }
62+ } ,
2063 changeFactory : function ( current ) {
2164 return function ( ) {
2265 this . props . changeCurrent ( current )
2366 } . bind ( this )
2467 } ,
25- logOut : function ( ) {
26- AuthActions . logout ( )
68+ openLogOutModal : function ( ) {
69+ this . setState ( { isLogOutModalOpen : true } )
70+ } ,
71+ closeLogOutModal : function ( ) {
72+ this . setState ( { isLogOutModalOpen : false } )
2773 } ,
2874 render : function ( ) {
2975 return (
@@ -34,8 +80,11 @@ var UserSettingNavigation = React.createClass({
3480 < a className = { this . props . current === 'setting' ? 'active' : '' } onClick = { this . changeFactory ( 'setting' ) } > < i className = 'fa fa-gears fa-fw' /> Setting</ a >
3581 < a className = { this . props . current === 'integration' ? 'active' : '' } onClick = { this . changeFactory ( 'integration' ) } > < i className = 'fa fa-share-alt fa-fw' /> Integration</ a >
3682 < a className = { this . props . current === 'help' ? 'active' : '' } onClick = { this . changeFactory ( 'help' ) } > < i className = 'fa fa-info-circle fa-fw' /> Help</ a >
37- < a onClick = { this . logOut } > < i className = 'fa fa-sign-out fa-fw' /> Logout</ a >
83+ < a onClick = { this . openLogOutModal } > < i className = 'fa fa-sign-out fa-fw' /> Logout</ a >
3884 </ nav >
85+ < ModalBase close = { this . closeLogOutModal } isOpen = { this . state . isLogOutModalOpen } >
86+ < LogOutModal close = { this . closeLogOutModal } />
87+ </ ModalBase >
3988 </ div >
4089 )
4190 }
@@ -112,6 +161,8 @@ module.exports = React.createClass({
112161 } )
113162 } ,
114163 render : function ( ) {
164+ var currentUser = AuthStore . getUser ( )
165+
115166 return (
116167 < div className = 'UserSettingContainer' >
117168 < UserSettingNavigation currentUser = { currentUser } current = { this . state . current } changeCurrent = { this . changeCurrent } />
0 commit comments