mirror of
https://github.com/nowcommunity/nowdatabase.git
synced 2026-10-12 19:13:52 +03:00
* update project update prosess in frontend, and add project validators * change project update process in backend * update project backend files, projectReducer, project validators and tests * update project api tests, and error handling in ProjectDetails * update frontend project creation form * remove ProjectEditPage tests and fix ProjectNewPage tests * update project api tests, project write process, and project validators * remove unneeded files relating to projects, and merge project/ and projects/ route files * remove project validators from backend, and update other project files * allow all users to view projects table * fix import issue * update project api tests to use correct url, and add --runInBand flag to backend unit tests * update cypress test
93 lines
3.1 KiB
TypeScript
Executable File
93 lines
3.1 KiB
TypeScript
Executable File
import { AppBar, Box, MenuItem, MenuList, Stack, Typography } from '@mui/material'
|
|
import { Link, useNavigate } from 'react-router-dom'
|
|
import { useDispatch } from 'react-redux'
|
|
import { clearUser } from '../redux/userReducer'
|
|
import { api } from '../redux/api'
|
|
import { Role } from '@/shared/types'
|
|
import { useUser } from '@/hooks/user'
|
|
import { useNotify } from '@/hooks/notification'
|
|
import PersonIcon from '@mui/icons-material/Person'
|
|
import '../styles/NavBar.css'
|
|
import { LinkDefinition, NavBarLink } from './NavBarLink'
|
|
import { occurrenceLabels } from '@/constants/occurrenceLabels'
|
|
|
|
import logo from '../resource/nowlogo.jpg'
|
|
|
|
export const NavBar = () => {
|
|
const user = useUser()
|
|
const navigate = useNavigate()
|
|
const dispatch = useDispatch()
|
|
const { notify } = useNotify()
|
|
const pages: LinkDefinition[] = [
|
|
{ title: 'Localities', url: '/locality' },
|
|
{ title: 'Species', url: '/species' },
|
|
{ title: occurrenceLabels.plural, url: '/occurrence' },
|
|
{ title: 'References', url: '/reference' },
|
|
{ title: 'Time Units', url: '/time-unit' },
|
|
{ title: 'Time Bounds', url: '/time-bound', allowedRoles: [Role.Admin, Role.EditUnrestricted] },
|
|
{ title: 'Museums', url: '/museum' },
|
|
{ title: 'Projects', url: '/project' },
|
|
{
|
|
title: 'Admin',
|
|
url: '/admin',
|
|
allowedRoles: [Role.Admin],
|
|
children: [
|
|
{ title: 'Regions', url: '/region' },
|
|
{ title: 'People', url: '/person' },
|
|
{ title: 'Email', url: '/email' },
|
|
{ title: 'Merge Species', url: '/admin/merge-species' },
|
|
{ title: 'Emergency shutdown', url: '/admin/emergency-shutdown' },
|
|
],
|
|
},
|
|
]
|
|
|
|
const logout = () => {
|
|
dispatch(clearUser())
|
|
// Reset api, so that we won't show cached private data to guest user
|
|
dispatch(api.util.resetApiState())
|
|
localStorage.clear()
|
|
notify('Logged out!')
|
|
navigate('/')
|
|
}
|
|
|
|
const logoutButton = (
|
|
<MenuItem onClick={logout} className="logout-link menu-item">
|
|
<Typography textAlign="center" fontSize={18}>
|
|
Logout
|
|
</Typography>
|
|
</MenuItem>
|
|
)
|
|
|
|
return (
|
|
<AppBar position="static" id="main-navbar">
|
|
<div className="container">
|
|
<MenuItem component={Link} to="/" className="logo-link">
|
|
<img src={logo} title="Logo © Noira Martiskainen" />
|
|
</MenuItem>
|
|
<MenuList className="menu-list">
|
|
{pages
|
|
.filter(childLink => !childLink.allowedRoles || childLink.allowedRoles.includes(user.role))
|
|
.map(page => (
|
|
<NavBarLink key={page.url} link={page} />
|
|
))}
|
|
</MenuList>
|
|
<Box className="user-controls">
|
|
{user.username ? (
|
|
<Stack className="logged-in-controls">
|
|
<Link className="username-box" to="/person/user-page">
|
|
<PersonIcon />
|
|
<span>{user.username}</span>
|
|
</Link>
|
|
{logoutButton}
|
|
</Stack>
|
|
) : (
|
|
<Stack>
|
|
<NavBarLink link={{ title: 'Login', url: 'login' }} />
|
|
</Stack>
|
|
)}
|
|
</Box>
|
|
</div>
|
|
</AppBar>
|
|
)
|
|
}
|