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