2022-06-12 13:35:02 +00:00
|
|
|
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';
|
2022-12-21 21:27:50 +00:00
|
|
|
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';
|
2020-04-04 05:39:53 +00:00
|
|
|
import SearchContainer from '@/components/dashboard/search/SearchContainer';
|
2020-12-26 18:41:25 +00:00
|
|
|
import tw, { theme } from 'twin.macro';
|
2022-11-25 20:25:03 +00:00
|
|
|
import styled from 'styled-components';
|
2021-10-23 20:00:21 +00:00
|
|
|
import http from '@/api/http';
|
|
|
|
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
|
2022-06-12 13:35:02 +00:00
|
|
|
import Tooltip from '@/components/elements/tooltip/Tooltip';
|
2022-06-19 17:46:15 +00:00
|
|
|
import Avatar from '@/components/Avatar';
|
2020-07-03 21:50:37 +00:00
|
|
|
|
|
|
|
const RightNavigation = styled.div`
|
2022-06-26 19:13:52 +00:00
|
|
|
& > a,
|
|
|
|
& > button,
|
|
|
|
& > .navigation-link {
|
2020-07-03 21:50:37 +00:00
|
|
|
${tw`flex items-center h-full no-underline text-neutral-300 px-6 cursor-pointer transition-all duration-150`};
|
2022-06-12 13:35:02 +00:00
|
|
|
|
2022-06-26 19:13:52 +00:00
|
|
|
&:active,
|
|
|
|
&:hover {
|
2020-07-03 21:50:37 +00:00
|
|
|
${tw`text-neutral-100 bg-black`};
|
|
|
|
}
|
2022-06-12 13:35:02 +00:00
|
|
|
|
2022-06-26 19:13:52 +00:00
|
|
|
&:active,
|
|
|
|
&:hover,
|
|
|
|
&.active {
|
2022-06-12 13:35:02 +00:00
|
|
|
box-shadow: inset 0 -2px ${theme`colors.cyan.600`.toString()};
|
2020-07-03 21:50:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
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);
|
2022-06-26 19:13:52 +00:00
|
|
|
const [isLoggingOut, setIsLoggingOut] = useState(false);
|
2021-10-23 20:00:21 +00:00
|
|
|
|
|
|
|
const onTriggerLogout = () => {
|
|
|
|
setIsLoggingOut(true);
|
2022-11-25 20:25:03 +00:00
|
|
|
|
2021-10-23 20:00:21 +00:00
|
|
|
http.post('/auth/logout').finally(() => {
|
2022-06-26 19:30:05 +00:00
|
|
|
// @ts-expect-error this is valid
|
2021-10-23 20:00:21 +00:00
|
|
|
window.location = '/';
|
|
|
|
});
|
|
|
|
};
|
2019-11-16 21:08:38 +00:00
|
|
|
|
|
|
|
return (
|
2023-01-12 19:31:47 +00:00
|
|
|
<div className="w-full overflow-x-auto bg-neutral-900 shadow-md">
|
2022-06-26 19:13:52 +00:00
|
|
|
<SpinnerOverlay visible={isLoggingOut} />
|
2023-01-12 19:31:47 +00:00
|
|
|
<div className="mx-auto flex h-[3.5rem] w-full max-w-[1200px] items-center">
|
2022-11-25 20:25:03 +00:00
|
|
|
<div id="logo" className="flex-1">
|
2022-06-12 13:35:02 +00:00
|
|
|
<Link
|
2022-11-25 20:25:03 +00:00
|
|
|
to="/"
|
2023-01-12 19:31:47 +00:00
|
|
|
className="px-4 font-header text-2xl text-neutral-200 no-underline transition-colors duration-150 hover:text-neutral-100"
|
2022-06-12 13:35:02 +00:00
|
|
|
>
|
2019-12-16 02:07:16 +00:00
|
|
|
{name}
|
2019-11-16 21:08:38 +00:00
|
|
|
</Link>
|
|
|
|
</div>
|
2022-12-21 21:27:50 +00:00
|
|
|
|
2022-11-25 20:25:03 +00:00
|
|
|
<RightNavigation className="flex h-full items-center justify-center">
|
2022-06-26 19:13:52 +00:00
|
|
|
<SearchContainer />
|
2022-11-25 20:25:03 +00:00
|
|
|
|
|
|
|
<Tooltip placement="bottom" content="Dashboard">
|
|
|
|
<NavLink to="/" end>
|
2022-06-26 19:13:52 +00:00
|
|
|
<FontAwesomeIcon icon={faLayerGroup} />
|
2022-06-12 13:35:02 +00:00
|
|
|
</NavLink>
|
|
|
|
</Tooltip>
|
2022-11-25 20:25:03 +00:00
|
|
|
|
|
|
|
<Tooltip placement="bottom" content="Account Settings">
|
|
|
|
<NavLink to="/account">
|
2023-01-12 19:31:47 +00:00
|
|
|
<span className="flex h-5 w-5 items-center">
|
2022-06-19 17:46:15 +00:00
|
|
|
<Avatar.User />
|
|
|
|
</span>
|
|
|
|
</NavLink>
|
|
|
|
</Tooltip>
|
2022-11-25 20:25:03 +00:00
|
|
|
|
2022-12-21 21:27:50 +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">
|
2022-06-12 13:35:02 +00:00
|
|
|
<button onClick={onTriggerLogout}>
|
2022-06-26 19:13:52 +00:00
|
|
|
<FontAwesomeIcon icon={faSignOutAlt} />
|
2022-06-12 13:35:02 +00:00
|
|
|
</button>
|
|
|
|
</Tooltip>
|
2020-07-03 21:50:37 +00:00
|
|
|
</RightNavigation>
|
2019-06-26 04:28:56 +00:00
|
|
|
</div>
|
2022-06-12 13:35:02 +00:00
|
|
|
</div>
|
2019-11-16 21:08:38 +00:00
|
|
|
);
|
|
|
|
};
|