2023-12-28 12:35:50 -05:00
|
|
|
import * as React from 'react';
|
|
|
|
import { useState } from 'react';
|
|
|
|
import { Link, NavLink } from 'react-router-dom';
|
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
2024-04-10 14:35:11 -04:00
|
|
|
import { faCogs, faLayerGroup, faSignOutAlt } from '@fortawesome/free-solid-svg-icons';
|
2023-12-28 12:35:50 -05:00
|
|
|
import { useStoreState } from 'easy-peasy';
|
2024-11-03 02:26:44 -05:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2023-12-28 12:35:50 -05:00
|
|
|
import { ApplicationStore } from '@/state';
|
|
|
|
import SearchContainer from '@/components/dashboard/search/SearchContainer';
|
|
|
|
import tw, { theme } from 'twin.macro';
|
|
|
|
import styled from 'styled-components/macro';
|
|
|
|
import http from '@/api/http';
|
|
|
|
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
|
|
|
|
import Tooltip from '@/components/elements/tooltip/Tooltip';
|
|
|
|
import Avatar from '@/components/Avatar';
|
2023-12-28 18:59:12 -05:00
|
|
|
|
2023-12-28 12:35:50 -05:00
|
|
|
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()};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
export default () => {
|
2024-11-03 02:26:44 -05:00
|
|
|
const { t } = useTranslation('strings');
|
|
|
|
|
2023-12-28 12:35:50 -05:00
|
|
|
const name = useStoreState((state: ApplicationStore) => state.settings.data!.name);
|
2024-11-03 02:26:44 -05:00
|
|
|
const isAdmin = useStoreState((state: ApplicationStore) => state.user.data!.admin);
|
2023-12-28 12:35:50 -05:00
|
|
|
const [isLoggingOut, setIsLoggingOut] = useState(false);
|
|
|
|
|
|
|
|
const onTriggerLogout = () => {
|
|
|
|
setIsLoggingOut(true);
|
|
|
|
http.post('/auth/logout').finally(() => {
|
|
|
|
// @ts-expect-error this is valid
|
|
|
|
window.location = '/';
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2024-11-03 02:26:44 -05:00
|
|
|
<div className={'w-full bg-neutral-900 shadow-md overflow-x-auto'}>
|
2023-12-28 19:03:48 -05:00
|
|
|
<BeforeNavigation />
|
2023-12-28 12:35:50 -05:00
|
|
|
<SpinnerOverlay visible={isLoggingOut} />
|
|
|
|
<div className={'mx-auto w-full flex items-center h-[3.5rem] max-w-[1200px]'}>
|
|
|
|
<div id={'logo'} className={'flex-1'}>
|
|
|
|
<Link
|
|
|
|
to={'/'}
|
|
|
|
className={
|
|
|
|
'text-2xl font-header px-4 no-underline text-neutral-200 hover:text-neutral-100 transition-colors duration-150'
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{name}
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
<RightNavigation className={'flex h-full items-center justify-center'}>
|
|
|
|
<SearchContainer />
|
2024-11-03 02:26:44 -05:00
|
|
|
<Tooltip placement={'bottom'} content={t<string>('dashboard')}>
|
|
|
|
<NavLink to={'/'} exact>
|
2023-12-28 12:35:50 -05:00
|
|
|
<FontAwesomeIcon icon={faLayerGroup} />
|
|
|
|
</NavLink>
|
|
|
|
</Tooltip>
|
2024-11-03 02:26:44 -05:00
|
|
|
{isAdmin && (
|
|
|
|
<Tooltip placement={'bottom'} content={t<string>('admin')}>
|
|
|
|
<a href={'/admin'} rel={'noreferrer'}>
|
2023-12-28 12:35:50 -05:00
|
|
|
<FontAwesomeIcon icon={faCogs} />
|
|
|
|
</a>
|
|
|
|
</Tooltip>
|
|
|
|
)}
|
2023-12-28 18:59:12 -05:00
|
|
|
<AdditionalItems />
|
2024-11-03 02:26:44 -05:00
|
|
|
<Tooltip placement={'bottom'} content={t<string>('account_settings')}>
|
|
|
|
<NavLink to={'/account'}>
|
2023-12-28 12:35:50 -05:00
|
|
|
<span className={'flex items-center w-5 h-5'}>
|
|
|
|
<Avatar.User />
|
|
|
|
</span>
|
|
|
|
</NavLink>
|
|
|
|
</Tooltip>
|
2024-11-03 02:26:44 -05:00
|
|
|
<Tooltip placement={'bottom'} content={t<string>('sign_out')}>
|
|
|
|
<button onClick={onTriggerLogout}>
|
2023-12-28 12:35:50 -05:00
|
|
|
<FontAwesomeIcon icon={faSignOutAlt} />
|
|
|
|
</button>
|
|
|
|
</Tooltip>
|
|
|
|
</RightNavigation>
|
|
|
|
</div>
|
2023-12-28 19:03:48 -05:00
|
|
|
<AfterNavigation />
|
2023-12-28 12:35:50 -05:00
|
|
|
</div>
|
|
|
|
);
|
2024-11-03 02:26:44 -05:00
|
|
|
};
|