Commit 959d2099 authored by Ibadullina Inabat's avatar Ibadullina Inabat

на доработке кнопка удаления участника

parent 8f1aa7fe
...@@ -143,7 +143,8 @@ router.post('/add-user/', authAdminProject, async (req: Request, res: Response): ...@@ -143,7 +143,8 @@ router.post('/add-user/', authAdminProject, async (req: Request, res: Response):
/** Remove user from specific project by userId */ /** Remove user from specific project by userId */
router.delete('/remove-user/:userId', authAdminProject,async (req: Request, res: Response):Promise<Response>=> { router.delete('/remove-user/:userId', authAdminProject,async (req: Request, res: Response):Promise<Response>=> {
const {projectId} = req.body; console.log('req ', req)
const {projectId} = req.body.data;
const {userId }=req.params; const {userId }=req.params;
try{ try{
await dataSource await dataSource
......
...@@ -52,7 +52,7 @@ const MemberForm = ({ onSubmit, members }) => { ...@@ -52,7 +52,7 @@ const MemberForm = ({ onSubmit, members }) => {
useEffect(() => { useEffect(() => {
dispatch(fetchProject(params.id)) dispatch(fetchProject(params.id))
}, [members, dispatch, params]); }, []);
// console.log(user) // console.log(user)
// const onChange = (e) => { // const onChange = (e) => {
// const value = e.target.value; // const value = e.target.value;
......
import { Card, CardActions, CardContent, Grid, IconButton, Tooltip } from "@mui/material"; import { Card, CardActions, CardContent, Grid, IconButton, Tooltip } from "@mui/material";
import { Link } from "react-router-dom"; import { Link, useParams } from "react-router-dom";
import ArrowForwardIcon from "@mui/icons-material/ArrowForward"; import ArrowForwardIcon from "@mui/icons-material/ArrowForward";
import { useDispatch, useSelector } from "react-redux"; import { useDispatch, useSelector } from "react-redux";
import DeleteIcon from "@mui/icons-material/Delete"; import DeleteIcon from "@mui/icons-material/Delete";
import { deleteMember } from "../../../store/actions/projectsActions";
const ProjectMembersItem = ({ displayName, roleProject, id, roleProjectOfAuthor }) => { const ProjectMembersItem = ({ displayName, roleProject, id, roleProjectOfAuthor, userId }) => {
console.log(displayName) console.log(displayName)
const dispatch = useDispatch(); const dispatch = useDispatch();
const user = useSelector(state => state.users) const user = useSelector(state => state.users)
console.log(user) let params = useParams()
console.log(params)
console.log(userId)
const { projects, project } = useSelector(state => state.projects); const { projects, project } = useSelector(state => state.projects);
const deleteHandle = (userId, projectId) => {
dispatch(deleteMember(userId, params.id));
};
return <> return <>
<Grid item xs={12} sm={12} md={6} lg={4}> <Grid item xs={12} sm={12} md={6} lg={4}>
<Card> <Card>
...@@ -30,7 +37,7 @@ const ProjectMembersItem = ({ displayName, roleProject, id, roleProjectOfAuthor ...@@ -30,7 +37,7 @@ const ProjectMembersItem = ({ displayName, roleProject, id, roleProjectOfAuthor
<Tooltip title="Удалить"> <Tooltip title="Удалить">
<IconButton <IconButton
onClick={(id) => { onClick={(id) => {
// deleteHandle(task.id); deleteHandle(userId);
}} }}
> >
<DeleteIcon style={{ marginTop: "-5px" }} /> <DeleteIcon style={{ marginTop: "-5px" }} />
......
...@@ -12,6 +12,7 @@ const ProjectMembersList = ({members, roleProjectOfAuthor}) => { ...@@ -12,6 +12,7 @@ const ProjectMembersList = ({members, roleProjectOfAuthor}) => {
id={member.id} id={member.id}
key={member.id} key={member.id}
roleProjectOfAuthor={roleProjectOfAuthor} roleProjectOfAuthor={roleProjectOfAuthor}
userId={member.user.id}
/> />
})} })}
</Grid> </Grid>
......
...@@ -35,11 +35,12 @@ const deleteMemberRequest = () => { ...@@ -35,11 +35,12 @@ const deleteMemberRequest = () => {
return {type: DELETE_MEMBER_FAILURE, error} return {type: DELETE_MEMBER_FAILURE, error}
}; };
export const deleteMember = (memberId) => { export const deleteMember = (memberId, projectId) => {
return async (dispatch) => { return async (dispatch) => {
dispatch(deleteMemberRequest()); dispatch(deleteMemberRequest());
try { try {
await axios.delete(`/tasks/${memberId}`); const response = await axios.delete(`/projects/remove-user/${memberId}`, { data: { projectId: projectId}});
console.log(response.data)
dispatch(deleteMemberSuccess()) dispatch(deleteMemberSuccess())
dispatch(fetchProject()) dispatch(fetchProject())
} 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