diff -r fffefefed507 -r e6f85e26b08c client/src/components/Navbar.js --- a/client/src/components/Navbar.js Thu Jun 29 12:06:48 2017 +0200 +++ b/client/src/components/Navbar.js Thu Jun 29 17:02:21 2017 +0200 @@ -4,33 +4,26 @@ import { withRouter } from 'react-router'; import { bindActionCreators } from 'redux'; // import logo from './logo.svg'; -import { Navbar, Nav, NavItem, NavDropdown, MenuItem } from 'react-bootstrap'; +import { Navbar, Nav, NavItem, NavDropdown, MenuItem, Modal, Button } from 'react-bootstrap'; import * as authActions from '../actions/authActions'; -const LoginNav = ({isAuthenticated, currentUser, history, authActions}) => { +const LoginNav = ({isAuthenticated, currentUser, history, authActions, onLogout}) => { const onClickSettings = (e) => { e.preventDefault(); history.push('/settings'); } - const onClickLogout = (e) => { - e.preventDefault(); - authActions.logout(); - history.push('/'); - } - const onClickLogin = (e) => { e.preventDefault(); history.push('/login'); } - if (isAuthenticated) { return ( Settings - Logout + Logout ); } @@ -49,11 +42,47 @@ class AppNavbar extends Component { + state = { + showModal: false + } + + closeModal = () => { + this.setState({ showModal: false }); + } + onClickHome = (e) => { e.preventDefault(); this.props.history.push('/'); } + isOutboxEmpty = () => { + return this.props.offline.outbox.length === 0; + } + + onClickLogout = (e) => { + e.preventDefault(); + const isOutboxEmpty = this.isOutboxEmpty(); + if (isOutboxEmpty) { + this.logout(); + } else { + this.setState({ showModal: true }) + } + } + + confirmLogout = () => { + const isOutboxEmpty = this.isOutboxEmpty(); + if (!isOutboxEmpty) { + this.props.authActions.purgeOutbox(); + } + this.logout(); + this.closeModal(); + } + + logout = () => { + this.props.authActions.logout(); + this.props.history.push('/'); + } + onClickSessions = (e) => { e.preventDefault(); this.props.history.push('/sessions'); @@ -74,9 +103,22 @@ + + +

+ Some data is not synchronized with server. +
+ If you continue, it will be lost. +

+
+ + + + +
); }