Commit bdaf0f3a authored by Ermolaev Timur's avatar Ermolaev Timur

Merge branch 'development' of…

Merge branch 'development' of ssh://git.attractor-school.com:30022/apollo64/crm-team-one into task-103-feature/check_other_calendar
parents 0fe75260 65f72257
...@@ -143,16 +143,32 @@ router.post('/add-user/', authAdminProject, async (req: Request, res: Response): ...@@ -143,16 +143,32 @@ 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>=> {
console.log('req.body ', req.body)
const {projectId} = req.body; const {projectId} = req.body;
const {userId }=req.params; const {userId }=req.params;
try{ console.log('projectId ', projectId, 'userId ',userId )
await dataSource
.createQueryBuilder() try{
.delete() const projectMember = await dataSource
.from(Member) .getRepository(Member)
.where("user= :userId", { userId }) .findOne({
.andWhere("project=:projectId",{projectId}) relations:{
.execute() user:true,
project:true
},
where:{
user:{
id:userId
},
project:{
id:projectId
}
}
})
console.log('projectMember ', projectMember)
if(!projectMember) return res.status(404).send({message:"this member is not present"})
await Member.delete({id:projectMember.id})
console.log('projectMember deleted successfully')
return res.send({message:"User removed from project successfully" }) return res.send({message:"User removed from project successfully" })
} catch(e){ } catch(e){
return res.send({message:'Failed to remove user from project'}) return res.send({message:'Failed to remove user from project'})
......
import { Box, Button, Grid, Modal } from "@mui/material"; import { Box, Button, Grid, Modal } from "@mui/material";
import { useState } from "react"; import { useState } from "react";
import { useSelector, useDispatch } from "react-redux"; import { useSelector, useDispatch } from "react-redux";
import FormElement from "../UI/Form/FormElement/FormElement";
import { Typography } from "@mui/material"; import { Typography } from "@mui/material";
import TextField from '@mui/material/TextField'; import TextField from '@mui/material/TextField';
import Stack from '@mui/material/Stack';
import Autocomplete from '@mui/material/Autocomplete'; import Autocomplete from '@mui/material/Autocomplete';
import { useParams } from "react-router-dom"; import { useParams } from "react-router-dom";
import PersonAddIcon from '@mui/icons-material/PersonAdd'; import PersonAddIcon from '@mui/icons-material/PersonAdd';
import { fetchUsers } from "../../store/actions/usersActions";
import { useEffect } from "react"; import { useEffect } from "react";
import { fetchProject } from "../../store/actions/projectsActions"; import { fetchProject } from "../../store/actions/projectsActions";
...@@ -34,16 +31,15 @@ const MemberForm = ({ onSubmit, members }) => { ...@@ -34,16 +31,15 @@ const MemberForm = ({ onSubmit, members }) => {
const handleOpen = () => setOpen(true); const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false); const handleClose = () => setOpen(false);
const [state, setState] = useState({ const [state, setState] = useState({
// displayName: "",
roleProject: "", roleProject: "",
user: "", user: "",
projectId: "" projectId: ""
}); });
const submitFormHandler = (e) => { const submitFormHandler = (e) => {
e.preventDefault(); e.preventDefault();
let members = {roleProject: state.roleProject, projectId: params.id, userId: state.user.id} let members = { roleProject: state.roleProject, projectId: params.id, userId: state.user.id }
console.log(members); console.log(members);
onSubmit(members); onSubmit(members);
setOpen(false); setOpen(false);
...@@ -52,20 +48,11 @@ const MemberForm = ({ onSubmit, members }) => { ...@@ -52,20 +48,11 @@ const MemberForm = ({ onSubmit, members }) => {
useEffect(() => { useEffect(() => {
dispatch(fetchProject(params.id)) dispatch(fetchProject(params.id))
}, [members, dispatch, params]); }, [params]);
// console.log(user)
// const onChange = (e) => {
// const value = e.target.value;
// const name = e.target.name;
// const newState= { ...state, [name]: value };
// console.log("newState " + newState)
// console.log("e.target " + e.target)
// console.log("e " + e)
// setState(newState);
// };
const memberChangeHandler = (e, value) => { const memberChangeHandler = (e, value) => {
setState(() => { return { ...state, user: value, projectId: params.id} }); setState(() => { return { ...state, user: value, projectId: params.id } });
console.log("memberChangeHandler" + value) console.log("memberChangeHandler" + value)
} }
const roleChangeHandler = (e, value) => { const roleChangeHandler = (e, value) => {
...@@ -74,18 +61,18 @@ const MemberForm = ({ onSubmit, members }) => { ...@@ -74,18 +61,18 @@ const MemberForm = ({ onSubmit, members }) => {
} }
return ( return (
<div > <div >
<PersonAddIcon onClick={handleOpen} style={{marginLeft: "30px", marginTop: "-3px", cursor: 'pointer'}} >Добавить участника</PersonAddIcon> <PersonAddIcon onClick={handleOpen} style={{ marginLeft: "30px", marginTop: "-3px", cursor: 'pointer' }} >Добавить участника</PersonAddIcon>
<Modal <Modal
open={open} open={open}
onClose={handleClose} onClose={handleClose}
aria-labelledby="modal-modal-title" aria-labelledby="modal-modal-title"
aria-describedby="modal-modal-description" aria-describedby="modal-modal-description"
> >
<Box sx={style}> <Box sx={style}>
<form onSubmit={submitFormHandler}> <form onSubmit={submitFormHandler}>
<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>
<Autocomplete <Autocomplete
id="free-solo-demo" id="free-solo-demo"
freeSolo freeSolo
...@@ -95,7 +82,7 @@ const MemberForm = ({ onSubmit, members }) => { ...@@ -95,7 +82,7 @@ const MemberForm = ({ onSubmit, members }) => {
name={"userId"} name={"userId"}
value={state.user} value={state.user}
renderInput={(params) => <TextField renderInput={(params) => <TextField
style={{margin: "5px"}} style={{ margin: "5px" }}
label={"Участник"} label={"Участник"}
state={state} state={state}
{...params} />} {...params} />}
...@@ -107,7 +94,7 @@ const MemberForm = ({ onSubmit, members }) => { ...@@ -107,7 +94,7 @@ const MemberForm = ({ onSubmit, members }) => {
value={state.roleProject} value={state.roleProject}
onChange={roleChangeHandler} onChange={roleChangeHandler}
renderInput={(params) => <TextField renderInput={(params) => <TextField
style={{margin: "5px"}} style={{ margin: "5px" }}
name={"roleProject"} name={"roleProject"}
label={"Роль в проекте"} label={"Роль в проекте"}
state={state} state={state}
...@@ -118,7 +105,6 @@ const MemberForm = ({ onSubmit, members }) => { ...@@ -118,7 +105,6 @@ const MemberForm = ({ onSubmit, members }) => {
type="submit" type="submit"
color="primary" color="primary"
variant="contained" variant="contained"
> >
Create Create
</Button> </Button>
......
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,13 +35,14 @@ const deleteMemberRequest = () => { ...@@ -35,13 +35,14 @@ 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("deleteMember ", response.data)
dispatch(deleteMemberSuccess()) dispatch(deleteMemberSuccess())
dispatch(fetchProject()) dispatch(fetchProject(projectId))
} catch (error) { } catch (error) {
dispatch(deleteMemberFailure(error.response.data)); dispatch(deleteMemberFailure(error.response.data));
} }
......
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