Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/resources/scripts/components/NavigationBar.tsx
7461 views
1
import * as React from 'react';
2
import { useState } from 'react';
3
import { Link, NavLink } from 'react-router-dom';
4
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
5
import { faCogs, faLayerGroup, faSignOutAlt } from '@fortawesome/free-solid-svg-icons';
6
import { useStoreState } from 'easy-peasy';
7
import { ApplicationStore } from '@/state';
8
import SearchContainer from '@/components/dashboard/search/SearchContainer';
9
import tw, { theme } from 'twin.macro';
10
import styled from 'styled-components/macro';
11
import http from '@/api/http';
12
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
13
import Tooltip from '@/components/elements/tooltip/Tooltip';
14
import Avatar from '@/components/Avatar';
15
16
const RightNavigation = styled.div`
17
& > a,
18
& > button,
19
& > .navigation-link {
20
${tw`flex items-center h-full no-underline text-neutral-300 px-6 cursor-pointer transition-all duration-150`};
21
22
&:active,
23
&:hover {
24
${tw`text-neutral-100 bg-black`};
25
}
26
27
&:active,
28
&:hover,
29
&.active {
30
box-shadow: inset 0 -2px ${theme`colors.cyan.600`.toString()};
31
}
32
}
33
`;
34
35
export default () => {
36
const name = useStoreState((state: ApplicationStore) => state.settings.data!.name);
37
const rootAdmin = useStoreState((state: ApplicationStore) => state.user.data!.rootAdmin);
38
const [isLoggingOut, setIsLoggingOut] = useState(false);
39
40
const onTriggerLogout = () => {
41
setIsLoggingOut(true);
42
http.post('/auth/logout').finally(() => {
43
// @ts-expect-error this is valid
44
window.location = '/';
45
});
46
};
47
48
return (
49
<div className={'w-full bg-neutral-900 shadow-md overflow-x-auto'}>
50
<SpinnerOverlay visible={isLoggingOut} />
51
<div className={'mx-auto w-full flex items-center h-[3.5rem] max-w-[1200px]'}>
52
<div id={'logo'} className={'flex-1'}>
53
<Link
54
to={'/'}
55
className={
56
'text-2xl font-header px-4 no-underline text-neutral-200 hover:text-neutral-100 transition-colors duration-150'
57
}
58
>
59
{name}
60
</Link>
61
</div>
62
<RightNavigation className={'flex h-full items-center justify-center'}>
63
<SearchContainer />
64
<Tooltip placement={'bottom'} content={'Dashboard'}>
65
<NavLink to={'/'} exact>
66
<FontAwesomeIcon icon={faLayerGroup} />
67
</NavLink>
68
</Tooltip>
69
{rootAdmin && (
70
<Tooltip placement={'bottom'} content={'Admin'}>
71
<a href={'/admin'} rel={'noreferrer'}>
72
<FontAwesomeIcon icon={faCogs} />
73
</a>
74
</Tooltip>
75
)}
76
<Tooltip placement={'bottom'} content={'Account Settings'}>
77
<NavLink to={'/account'}>
78
<span className={'flex items-center w-5 h-5'}>
79
<Avatar.User />
80
</span>
81
</NavLink>
82
</Tooltip>
83
<Tooltip placement={'bottom'} content={'Sign Out'}>
84
<button onClick={onTriggerLogout}>
85
<FontAwesomeIcon icon={faSignOutAlt} />
86
</button>
87
</Tooltip>
88
</RightNavigation>
89
</div>
90
</div>
91
);
92
};
93
94