misc_pterodactyl-panel/resources/scripts/components/NavigationBar.tsx

96 lines
3.5 KiB
TypeScript
Raw Normal View History

import { useState } from 'react';
2019-06-26 04:28:56 +00:00
import { Link, NavLink } from 'react-router-dom';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faLayerGroup, faScrewdriverWrench, faSignOutAlt } from '@fortawesome/free-solid-svg-icons';
2019-11-16 21:08:38 +00:00
import { useStoreState } from 'easy-peasy';
import { ApplicationStore } from '@/state';
import SearchContainer from '@/components/dashboard/search/SearchContainer';
import tw, { theme } from 'twin.macro';
2022-11-25 20:25:03 +00:00
import styled from 'styled-components';
import http from '@/api/http';
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
import Tooltip from '@/components/elements/tooltip/Tooltip';
import Avatar from '@/components/Avatar';
const RightNavigation = styled.div`
& > a,
& > button,
& > .navigation-link {
${tw`flex items-center h-full no-underline text-neutral-300 px-6 cursor-pointer transition-all duration-150`};
&:active,
&:hover {
${tw`text-neutral-100 bg-black`};
}
&:active,
&:hover,
&.active {
box-shadow: inset 0 -2px ${theme`colors.cyan.600`.toString()};
}
}
`;
2019-06-26 04:28:56 +00:00
2019-11-16 21:08:38 +00:00
export default () => {
2019-12-16 02:07:16 +00:00
const name = useStoreState((state: ApplicationStore) => state.settings.data!.name);
2020-08-26 04:39:00 +00:00
const rootAdmin = useStoreState((state: ApplicationStore) => state.user.data!.rootAdmin);
const [isLoggingOut, setIsLoggingOut] = useState(false);
const onTriggerLogout = () => {
setIsLoggingOut(true);
2022-11-25 20:25:03 +00:00
http.post('/auth/logout').finally(() => {
2022-06-26 19:30:05 +00:00
// @ts-expect-error this is valid
window.location = '/';
});
};
2019-11-16 21:08:38 +00:00
return (
2022-11-25 20:25:03 +00:00
<div className="w-full bg-neutral-900 shadow-md overflow-x-auto">
<SpinnerOverlay visible={isLoggingOut} />
2022-11-25 20:25:03 +00:00
<div className="mx-auto w-full flex items-center h-[3.5rem] max-w-[1200px]">
<div id="logo" className="flex-1">
<Link
2022-11-25 20:25:03 +00:00
to="/"
className="text-2xl font-header px-4 no-underline text-neutral-200 hover:text-neutral-100 transition-colors duration-150"
>
2019-12-16 02:07:16 +00:00
{name}
2019-11-16 21:08:38 +00:00
</Link>
</div>
2022-11-25 20:25:03 +00:00
<RightNavigation className="flex h-full items-center justify-center">
<SearchContainer />
2022-11-25 20:25:03 +00:00
<Tooltip placement="bottom" content="Dashboard">
<NavLink to="/" end>
<FontAwesomeIcon icon={faLayerGroup} />
</NavLink>
</Tooltip>
2022-11-25 20:25:03 +00:00
<Tooltip placement="bottom" content="Account Settings">
<NavLink to="/account">
<span className="flex items-center w-5 h-5">
<Avatar.User />
</span>
</NavLink>
</Tooltip>
2022-11-25 20:25:03 +00:00
{rootAdmin && (
<Tooltip placement="bottom" content="Admin">
<a href="/admin" rel="noreferrer">
<FontAwesomeIcon icon={faScrewdriverWrench} />
</a>
</Tooltip>
)}
2022-11-25 20:25:03 +00:00
<Tooltip placement="bottom" content="Sign Out">
<button onClick={onTriggerLogout}>
<FontAwesomeIcon icon={faSignOutAlt} />
</button>
</Tooltip>
</RightNavigation>
2019-06-26 04:28:56 +00:00
</div>
</div>
2019-11-16 21:08:38 +00:00
);
};