Commit 5b0ba753 authored by Ermolaev Timur's avatar Ermolaev Timur

Merge branch 'task-92-enhance/optimize-header' into 'development'

Task 92 enhance/optimize header

See merge request !68
parents 341f950a 9b875917
...@@ -100,6 +100,7 @@ router.delete('/sessions', async(req: Request, res: Response):Promise<void | obj ...@@ -100,6 +100,7 @@ router.delete('/sessions', async(req: Request, res: Response):Promise<void | obj
if(!user) return res.send({successMsg}); if(!user) return res.send({successMsg});
user.token = nanoid(); user.token = nanoid();
await user.save(); await user.save();
return res.send(successMsg)
}) })
......
import {Button, Menu, MenuItem} from "@mui/material"; import {Button} from "@mui/material";
import { useState } from "react"; import {NavLink} from "react-router-dom";
import { useDispatch, useSelector } from "react-redux"; import { superuserMenuButtons } from "../../../constants";
import {NavLink, useNavigate} from "react-router-dom"; import ProfileBlock from "../ProfileBlock/ProfileBlock";
import { logoutUser } from "../../../store/actions/usersActions";
const AdminMenu = () => { const AdminMenu = () => {
const dispatch = useDispatch();
const navigate = useNavigate()
const [anchorEl, setAnchorEl] = useState(null);
const open = Boolean(anchorEl);
const user = useSelector(state => state.users.user)
const handleClick = (event) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
const logout = () => {
dispatch(logoutUser(navigate));
handleClose()
}
return <> return <>
<Button {superuserMenuButtons.map((button, i)=>{
component={NavLink} return(
to="/projects" <Button
color="inherit" key={i}
size="large" component={NavLink}
> to={button.path}
Проекты color="inherit"
</Button> size="large"
<Button >
component={NavLink} {button.text}
to="/week" </Button>
color="inherit" )
size="large" })}
> <ProfileBlock/>
Неделя
</Button>
<Button
component={NavLink}
to="/month"
color="inherit"
size="large"
id='test_month_header'
>
Месяц
</Button>
<Button
component={NavLink}
to="/my-tasks"
color="inherit"
size="large"
>
Мои задачи
</Button>
<Button
component={NavLink}
to="/workers-tasks"
color="inherit"
size="large"
>
Задачи сотрудников
</Button>
<Button
component={NavLink}
to="/sign-up"
color="inherit"
size="large"
>
Создать сотрудника
</Button>
<Button
color="inherit"
onClick={handleClick}
id='test_greetings'
>
Hello, {user?.displayName}
</Button>
<Menu
anchorEl={anchorEl}
open={open}
onClose={handleClose}
>
<MenuItem component={NavLink} to="/profile/test" color="inherit" onClick={handleClose}>Profile</MenuItem>
<MenuItem onClick={logout}>Logout</MenuItem>
</Menu>
</> </>
}; };
......
import {Button} from "@mui/material"; import {Button} from "@mui/material";
import {NavLink} from "react-router-dom"; import {NavLink} from "react-router-dom";
import { anonymoysMenuButtons } from "../../../constants";
const AnonymousMenu = () => { const AnonymousMenu = () => {
return <> return <>
<Button {anonymoysMenuButtons.map((button, i)=>{
component={NavLink} return(
color="inherit" <Button
to="/sign-in" key={i}
> component={NavLink}
Вход to={button.path}
</Button> color="inherit"
size="large"
>
{button.text}
</Button>
)
})}
</> </>
}; };
......
import {Button, Menu, MenuItem} from "@mui/material";
import { useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import {NavLink, useNavigate} from "react-router-dom";
import { logoutUser } from "../../../store/actions/usersActions";
const ProfileBlock = () => {
const dispatch = useDispatch();
const navigate = useNavigate()
const [anchorEl, setAnchorEl] = useState(null);
const open = Boolean(anchorEl);
const user = useSelector(state => state.users.user)
const handleClick = (event) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
const logout = () => {
dispatch(logoutUser(navigate));
handleClose()
}
return <>
<Button
color="inherit"
onClick={handleClick}
id='test_greetings'
>
Hello, {user?.displayName}
</Button>
<Menu
anchorEl={anchorEl}
open={open}
onClose={handleClose}
>
<MenuItem component={NavLink} to="/profile/test" color="inherit" onClick={handleClose}>Profile</MenuItem>
<MenuItem onClick={()=>{logout()}}>Logout</MenuItem>
</Menu>
</>
};
export default ProfileBlock;
\ No newline at end of file
import {Button, Menu, MenuItem} from "@mui/material"; import {Button} from "@mui/material";
import { useState } from "react"; import {NavLink} from "react-router-dom";
import { useDispatch, useSelector } from "react-redux"; import { workerMenuButtons } from "../../../constants";
import {NavLink, useNavigate} from "react-router-dom"; import ProfileBlock from "../ProfileBlock/ProfileBlock";
import { logoutUser } from "../../../store/actions/usersActions";
const WorkerMenu = () => { const WorkerMenu = () => {
const dispatch = useDispatch();
const navigate = useNavigate()
const [anchorEl, setAnchorEl] = useState(null);
const open = Boolean(anchorEl);
const user = useSelector(state => state.users.user)
const handleClick = (event) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
const logout = () => {
dispatch(logoutUser(navigate));
handleClose()
}
return <> return <>
<Button {workerMenuButtons.map((button, i)=>{
component={NavLink} return(
to="/projects" <Button
color="inherit" key={i}
size="large" component={NavLink}
> to={button.path}
Проекты color="inherit"
</Button> size="large"
<Button >
component={NavLink} {button.text}
to="/week" </Button>
color="inherit" )
size="large" })}
>
Неделя <ProfileBlock/>
</Button>
<Button
component={NavLink}
to="/month"
color="inherit"
size="large"
id='test_month_header'
>
Месяц
</Button>
<Button
component={NavLink}
to="/my-tasks"
color="inherit"
size="large"
>
Мои задачи
</Button>
<Button
color="inherit"
onClick={handleClick}
id='test_greetings'
>
Hello, {user?.displayName}
</Button>
<Menu
anchorEl={anchorEl}
open={open}
onClose={handleClose}
>
<MenuItem component={NavLink} to="/profile/test" color="inherit" onClick={handleClose}>Profile</MenuItem>
<MenuItem onClick={logout}>Logout</MenuItem>
</Menu>
</> </>
}; };
......
export const apiUrl = "http://localhost:8000"; export const apiUrl = "http://localhost:8000";
export const uploadsUrl = `${apiUrl}/uploads`; export const uploadsUrl = `${apiUrl}/uploads`;
export const workerMenuButtons = [
{text: 'Проекты', path: '/projects'},
{text: 'Неделя', path: '/week'},
{text: 'Месяц', path: '/month'},
{text: 'Мои задачи', path: '/my-tasks'}
]
export const superuserMenuButtons = [
{text: 'Проекты', path: '/projects'},
{text: 'Неделя', path: '/week'},
{text: 'Месяц', path: '/month'},
{text: 'Мои задачи', path: '/my-tasks'},
{text: 'Задачи Сотрудников', path: '/workers-tasks'},
{text: 'Создать Сотрудника', path: '/sign-up'}
]
export const anonymoysMenuButtons = [
{text: 'Вход', path: '/sign-in'},
]
\ No newline at end of file
...@@ -85,13 +85,9 @@ export const forgottenPassword = (userData, navigate) => { ...@@ -85,13 +85,9 @@ export const forgottenPassword = (userData, navigate) => {
} }
export const logoutUser = (navigate) => { export const logoutUser = (navigate) => {
return async (dispatch, getState) => { return async (dispatch) => {
try { try {
await axios.delete("/users/sessions", { await axios.delete("/users/sessions");
headers: {
'Authorization': getState().users.user?.token
}
});
dispatch(logoutUserSuccess()); dispatch(logoutUserSuccess());
navigate("/"); navigate("/");
dispatch(showNotification("Вы успешно вышли")); dispatch(showNotification("Вы успешно вышли"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment