Merge branch 'task-37-feature/logout_front' into 'development'

Task 37 feature/logout front

See merge request !22
parents 0869aff6 1ef116bb
import {Button} from "@mui/material"; import {Button, Menu, MenuItem} from "@mui/material";
import {NavLink} from "react-router-dom"; import { useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import {NavLink, useNavigate} from "react-router-dom";
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)
console.log(user)
const handleClick = (event) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
const logout = () => {
dispatch(logoutUser(navigate));
handleClose()
}
return <> return <>
<Button <Button
component={NavLink} component={NavLink}
...@@ -44,13 +64,20 @@ const AdminMenu = () => { ...@@ -44,13 +64,20 @@ const AdminMenu = () => {
Создать сотрудника Создать сотрудника
</Button> </Button>
<Button <Button
component={NavLink}
to="/profile/test"
color="inherit" color="inherit"
size="large" onClick={handleClick}
> >
Профиль Hello, {user?.displayName}
</Button> </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, Menu, MenuItem} from "@mui/material";
import {NavLink} from "react-router-dom"; import { useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import {NavLink, useNavigate} from "react-router-dom";
import { logoutUser } from "../../../store/actions/usersActions";
const WorkerMenu = ({user}) => { const WorkerMenu = () => {
const dispatch = useDispatch();
const navigate = useNavigate()
const [anchorEl, setAnchorEl] = useState(null);
const open = Boolean(anchorEl);
const user = useSelector(state => state.users.user)
console.log(user)
const handleClick = (event) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
const logout = () => {
dispatch(logoutUser(navigate));
handleClose()
}
return <> return <>
<Button <Button
component={NavLink} component={NavLink}
...@@ -28,13 +48,20 @@ const WorkerMenu = ({user}) => { ...@@ -28,13 +48,20 @@ const WorkerMenu = ({user}) => {
Мои задачи Мои задачи
</Button> </Button>
<Button <Button
component={NavLink}
to="/profile/test"
color="inherit" color="inherit"
size="large" onClick={handleClick}
> >
Профиль Hello, {user?.displayName}
</Button> </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>
</> </>
}; };
......
...@@ -40,12 +40,14 @@ const UserRegistrationForm = ({ state, onChange, onSubmit, getFieldError, button ...@@ -40,12 +40,14 @@ const UserRegistrationForm = ({ state, onChange, onSubmit, getFieldError, button
state={state} state={state}
error={getFieldError?.("password")} error={getFieldError?.("password")}
/> />
{/* <FormElement <FormElement
onChange={onChange} onChange={onChange}
name="displayName" name="confirmPassword"
label="DisplayName" label="Confirm password"
type="password"
state={state} state={state}
/> */} error={getFieldError?.("password")}
/>
{/* <FormElement {/* <FormElement
onChange={fileChangeHandler} onChange={fileChangeHandler}
name="avatar" name="avatar"
......
...@@ -3,7 +3,7 @@ import { useDispatch, useSelector } from "react-redux"; ...@@ -3,7 +3,7 @@ import { useDispatch, useSelector } from "react-redux";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import Loader from "../../components/UI/Loader/Loader"; import Loader from "../../components/UI/Loader/Loader";
import UserForm from "../../components/UserForm/UserRegistrationForm"; import UserForm from "../../components/UserForm/UserRegistrationForm";
import { loginUser, registerUser } from "../../store/actions/usersActions"; import { registerUser } from "../../store/actions/usersActions";
import styled from "@emotion/styled"; import styled from "@emotion/styled";
import { Avatar, Container, Typography } from "@mui/material"; import { Avatar, Container, Typography } from "@mui/material";
import LockIcon from "@mui/icons-material/Lock"; import LockIcon from "@mui/icons-material/Lock";
...@@ -28,6 +28,7 @@ const Register = () => { ...@@ -28,6 +28,7 @@ const Register = () => {
email: "", email: "",
// number: "", // number: "",
password: '', password: '',
confirmPassword: "",
// avatar: "", // avatar: "",
}); });
...@@ -64,8 +65,12 @@ const Register = () => { ...@@ -64,8 +65,12 @@ const Register = () => {
formData.append(key, state[key]); formData.append(key, state[key]);
console.log("key " + key + "state " + state[key]) console.log("key " + key + "state " + state[key])
}) })
await dispatch(registerUser(formData, navigate)); if (state["password"] === state["confirmPassword"]) {
// dispatch(loginUser(state, navigate)) await dispatch(registerUser(formData, navigate));
} else {
alert("Пароли не совпадают")
}
}; };
const getFieldError = (fieldname) => { const getFieldError = (fieldname) => {
......
...@@ -20,6 +20,7 @@ export const registerUser = (userData, navigate) => { ...@@ -20,6 +20,7 @@ export const registerUser = (userData, navigate) => {
try { try {
console.log("register " + userData) console.log("register " + userData)
const response = await axios.post("/users", userData); const response = await axios.post("/users", userData);
console.log(response)
dispatch(registerUserSuccess()) dispatch(registerUserSuccess())
navigate("/") navigate("/")
} catch (error) { } catch (error) {
......
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