]> git.localhorst.tv Git - alttp.git/blob - resources/js/components/common/Header.js
6bab1a240fad9aa41008c21f0d215f26b70d208b
[alttp.git] / resources / js / components / common / Header.js
1 import PropTypes from 'prop-types';
2 import React from 'react';
3 import { Button, Container, Nav, Navbar } from 'react-bootstrap';
4 import { LinkContainer } from 'react-router-bootstrap';
5 import { withTranslation } from 'react-i18next';
6
7 import Icon from './Icon';
8 import { getAvatarUrl } from '../../helpers/User';
9 import { withUser } from '../../helpers/UserContext';
10 import i18n from '../../i18n';
11
12 const Header = ({ doLogout, user }) =>
13         <Navbar id="header" bg="dark" variant="dark">
14                 <Container fluid>
15                         <LinkContainer to="/">
16                                 <Navbar.Brand>
17                                         ALttP
18                                 </Navbar.Brand>
19                         </LinkContainer>
20                         <Nav className="ms-auto">
21                                 {user ?
22                                         <>
23                                                 <LinkContainer to={`/users/${user.id}`}>
24                                                         <Nav.Link>
25                                                                 <img alt="" src={getAvatarUrl(user)} />
26                                                                 {user.username}
27                                                                 <span className="text-muted">#{user.discriminator}</span>
28                                                         </Nav.Link>
29                                                 </LinkContainer>
30                                                 <Button
31                                                         onClick={doLogout}
32                                                         title={i18n.t('button.logout')}
33                                                         variant="outline-secondary"
34                                                 >
35                                                         <Icon.LOGOUT title="" />
36                                                 </Button>
37                                         </>
38                                 :
39                                         <Button href="/login" variant="discord">
40                                                 <Icon.DISCORD />
41                                                 {' '}
42                                                 {i18n.t('button.login')}
43                                         </Button>
44                                 }
45                         </Nav>
46                 </Container>
47         </Navbar>
48 ;
49
50 Header.propTypes = {
51         doLogout: PropTypes.func,
52         user: PropTypes.shape({
53                 avatar: PropTypes.string,
54                 discriminator: PropTypes.string,
55                 id: PropTypes.string,
56                 username: PropTypes.string,
57         }),
58 };
59
60 export default withTranslation()(withUser(Header));