#94 added submit change user function

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