#94 added submit change user function

parent 550447c8
......@@ -31,7 +31,7 @@ const SwitchUserForm=({submitFormHandler, users})=> {
<>
{/* <Box sx={style}> */}
{users?
<form onSubmit={submitFormHandler}>
<form onSubmit={(e)=>submitFormHandler(e,currentUser)}>
<Grid container direction="column" spacing={2}>
<Typography variant="h5" style={{margin: "5px", textAlign: "center"}} >Выберите юзера</Typography>
......
import React, {useEffect, useState} from 'react';
import Box from '@mui/material/Box';
import Button from '@mui/material/Button';
import Typography from '@mui/material/Typography';
import Modal from '@mui/material/Modal';
import { useDispatch, useSelector } from "react-redux";
import { fetchUsersAllFields } from '../../store/actions/usersActions';
import SwitchUserTable from './SwitchUserTable/SwitchUserTable';
import { logoutUser, loginUser } from '../../store/actions/usersActions';
import SwitchUserForm from './SwitchUserForm/SwitchUserForm';
import { useNavigate } from "react-router-dom";
const style = {
......@@ -23,13 +20,16 @@ const style = {
};
const SwitchUserModal= ({open, handleClose})=> {
const dispatch= useDispatch();
const usersAllFields = useSelector(state => state.users.usersAllFields)
const submitFormHandler=(e)=>{
const navigate= useNavigate();
const submitFormHandler=(e, currentUser)=>{
dispatch(logoutUser(navigate))
e.preventDefault();
console.log('submitFormHandler',
'e.target.name ', e.target.name,
'e.target.value ', e.target.value)
dispatch(loginUser({
"email": currentUser.email,
"password": "123"
}, navigate))
}
return (
......
......@@ -13,11 +13,21 @@ const SwitchUserTable=({projectsRoles})=>{
return (
<TableContainer component={Paper}>
<Table sx={{ minWidth: 450 }} aria-label="simple table">
<Table sx={{ minWidth: 350 }} aria-label="simple table">
<TableHead>
<TableRow>
<TableCell>Проекты</TableCell>
<TableCell align="right">Роли</TableCell>
<TableCell
sx ={{
'backgroundColor':'black',
'color': 'white'
}}
>Проекты</TableCell>
<TableCell
sx ={{
'backgroundColor':'black',
'color': 'white'
}} align="right"
>Роли</TableCell>
</TableRow>
</TableHead>
<TableBody>
......
......@@ -83,7 +83,7 @@ export const loginUser = (userData, navigate) => {
export const forgottenPassword = (userData, navigate) => {
return async (dispatch) => {
try {
console.log(userData)
console.log( 'forgottenPassword userData ',userData)
const response = await axios.post("users/requestPasswordReset", userData);
// if (userData.email === response.data.email) {
......@@ -130,9 +130,9 @@ export const fetchUsersAllFields = () => {
try {
const response = await axios.get("/users/all-fields/");
dispatch(fetchUsersAllFieldsSuccess(response.data.users));
console.log("users/all-fields/ ",response.data.users)
} catch (e) {
dispatch(fetchUsersAllFieldsFailure(e));
}
}
};
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