badguardhome/client/src/components/Header/index.js

83 lines
3.0 KiB
JavaScript
Raw Normal View History

2018-08-30 14:25:33 +00:00
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import PropTypes from 'prop-types';
import classnames from 'classnames';
2018-10-29 03:26:19 +00:00
import { Trans, withNamespaces } from 'react-i18next';
2018-08-30 14:25:33 +00:00
import Menu from './Menu';
2019-01-18 17:17:48 +00:00
import logo from '../ui/svg/logo.svg';
2018-08-30 14:25:33 +00:00
import './Header.css';
class Header extends Component {
state = {
isMenuOpen: false,
};
toggleMenuOpen = () => {
this.setState(prevState => ({ isMenuOpen: !prevState.isMenuOpen }));
};
closeMenu = () => {
this.setState({ isMenuOpen: false });
};
render() {
2019-09-05 16:07:14 +00:00
const { dashboard, location } = this.props;
const { isMenuOpen } = this.state;
2018-08-30 14:25:33 +00:00
const badgeClass = classnames({
'badge dns-status': true,
'badge-success': dashboard.protectionEnabled,
'badge-danger': !dashboard.protectionEnabled,
2018-08-30 14:25:33 +00:00
});
return (
<div className="header">
2019-09-05 16:07:14 +00:00
<div className="header__container">
<div className="header__row">
<div
className="header-toggler d-lg-none ml-lg-0 collapsed"
onClick={this.toggleMenuOpen}
>
2018-08-30 14:25:33 +00:00
<span className="header-toggler-icon"></span>
</div>
2019-09-05 16:07:14 +00:00
<div className="header__column">
2018-08-30 14:25:33 +00:00
<div className="d-flex align-items-center">
<Link to="/" className="nav-link pl-0 pr-1">
<img src={logo} alt="" className="header-brand-img" />
</Link>
2019-09-05 16:07:14 +00:00
{!dashboard.proccessing && dashboard.isCoreRunning && (
2018-08-30 14:25:33 +00:00
<span className={badgeClass}>
2018-11-09 06:51:28 +00:00
<Trans>{dashboard.protectionEnabled ? 'on' : 'off'}</Trans>
2018-08-30 14:25:33 +00:00
</span>
2019-09-05 16:07:14 +00:00
)}
2018-08-30 14:25:33 +00:00
</div>
</div>
<Menu
2019-06-25 14:56:50 +00:00
location={location}
isMenuOpen={isMenuOpen}
2018-08-30 14:25:33 +00:00
toggleMenuOpen={this.toggleMenuOpen}
closeMenu={this.closeMenu}
/>
2019-09-05 16:07:14 +00:00
<div className="header__column">
<div className="header__right">
<a href="/control/logout" className="btn btn-sm btn-outline-secondary">
2019-09-19 15:08:28 +00:00
<Trans>sign_out</Trans>
2019-09-05 16:07:14 +00:00
</a>
</div>
2019-09-05 16:07:14 +00:00
</div>
2018-08-30 14:25:33 +00:00
</div>
</div>
</div>
);
}
}
Header.propTypes = {
2019-06-25 14:56:50 +00:00
dashboard: PropTypes.object.isRequired,
location: PropTypes.object.isRequired,
getVersion: PropTypes.func.isRequired,
2019-09-05 16:07:14 +00:00
t: PropTypes.func.isRequired,
2018-08-30 14:25:33 +00:00
};
2018-10-29 03:26:19 +00:00
export default withNamespaces()(Header);