Commit 0ee7fdf1 authored by Ibadullina Inabat's avatar Ibadullina Inabat

Merge branch 'task-118-feature/delete_project_front' into 'development'

Task 118 feature/delete project front

See merge request !96
parents df6a871b eafabf99
...@@ -92,8 +92,8 @@ router.get("/:id",async (req:Request, res:Response): Promise<Response> => { ...@@ -92,8 +92,8 @@ router.get("/:id",async (req:Request, res:Response): Promise<Response> => {
}) })
/** Delete project by project ID*/ /** Delete project by project ID*/
router.delete('/:projectId',authAdminProject,async (req: Request, res: Response):Promise<Response>=>{ router.delete('/',authAdminProject,async (req: Request, res: Response):Promise<Response>=>{
const projectId = req.params.projectId; const {projectId} = req.body;
await myDataSource await myDataSource
.createQueryBuilder() .createQueryBuilder()
.delete() .delete()
......
import { Card, CardActions, CardContent, Grid, IconButton } from "@mui/material"; import { Button, Card, CardActions, CardContent, Grid, IconButton } from "@mui/material";
import { Link } from "react-router-dom"; import { Link } 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 { deleteProject } from "../../../store/actions/projectsActions";
const ProjectItem = ({ title, tasks, id }) => { const ProjectItem = ({ title, tasks, projectId }) => {
const user = useSelector(state => state.users.user); const user = useSelector(state => state.users.user);
const dispatch = useDispatch(); const dispatch = useDispatch();
console.log(user) console.log(user)
const deleteHandle = (projectId) => {
console.log("project id", projectId)
dispatch(deleteProject(projectId))
};
return <> return <>
<Grid item xs={12} sm={12} md={6} lg={4}> <Grid item xs={12} sm={12} md={6} lg={4}>
<Card> <Card>
...@@ -23,17 +30,15 @@ const ProjectItem = ({ title, tasks, id }) => { ...@@ -23,17 +30,15 @@ const ProjectItem = ({ title, tasks, id }) => {
</strong> </strong>
</CardContent> </CardContent>
<CardActions> <CardActions>
<IconButton component={Link} to={"/projects/" + id}> {(title !== "Личные дела") ? <Button onClick={() => {
deleteHandle(projectId);
}} variant="outlined" startIcon={<DeleteIcon />}>
Delete
</Button> : null}
<IconButton component={Link} to={"/projects/" + projectId}>
<ArrowForwardIcon /> <ArrowForwardIcon />
</IconButton> </IconButton>
<IconButton
onClick={(id) => {
// deleteHandle(userId);
}}
>
{(title !== "Личные дела") ?
<DeleteIcon /> : null}
</IconButton>
</CardActions> </CardActions>
</Card> </Card>
</Grid> </Grid>
......
import { Card, CardActions, CardContent, Grid, IconButton, Tooltip } from "@mui/material"; import { Card, CardContent, Grid, IconButton, Tooltip } from "@mui/material";
import { Link, useParams } from "react-router-dom"; import { useParams } from "react-router-dom";
import ArrowForwardIcon from "@mui/icons-material/ArrowForward"; import { useDispatch } 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"; import { deleteMember } from "../../../store/actions/projectsActions";
const ProjectMembersItem = ({ displayName, roleProject, id, roleProjectOfAuthor, userId, members, authorOfProject }) => { const ProjectMembersItem = ({ displayName, roleProject, id, roleProjectOfAuthor, userId, members, authorOfProject }) => {
console.log(displayName) console.log(displayName)
const dispatch = useDispatch(); const dispatch = useDispatch();
const user = useSelector(state => state.users)
let params = useParams() let params = useParams()
console.log(members) console.log(members)
console.log(userId) console.log(userId)
const { projects, project } = useSelector(state => state.projects);
const deleteHandle = (userId, projectId) => { const deleteHandle = (userId, projectId) => {
if (members.length > 1) {
dispatch(deleteMember(userId, params.id)) dispatch(deleteMember(userId, params.id))
} else {
alert("Нельзя удалить автора проекта")
}
}; };
return <> return <>
......
...@@ -13,7 +13,7 @@ const ProjectsList = ({projects}) => { ...@@ -13,7 +13,7 @@ const ProjectsList = ({projects}) => {
createdAt={project.createdAt} createdAt={project.createdAt}
dateDue={project.dateDue} dateDue={project.dateDue}
admin={project.admin} admin={project.admin}
id={project.id} projectId={project.id}
key={project.id} key={project.id}
/> />
})} })}
......
...@@ -8,6 +8,7 @@ import { fetchUsers } from "../../store/actions/usersActions"; ...@@ -8,6 +8,7 @@ import { fetchUsers } from "../../store/actions/usersActions";
import ProjectMembersList from "../../components/ProjectComponents/ProjectMembersList/ProjectMembersList"; import ProjectMembersList from "../../components/ProjectComponents/ProjectMembersList/ProjectMembersList";
import NewMember from "../NewMember/NewMember"; import NewMember from "../NewMember/NewMember";
const FullProject = () => { const FullProject = () => {
const { projects, project } = useSelector(state => state.projects); const { projects, project } = useSelector(state => state.projects);
...@@ -34,7 +35,7 @@ const FullProject = () => { ...@@ -34,7 +35,7 @@ const FullProject = () => {
return <> return <>
<Grid item xs={12} sm={12} md={6} lg={4}> <Grid item xs={12} sm={12} md={6} lg={4}>
<Card> <Card>
<h2>Проект - {project?.project?.title}</h2> <h2>Проект - {project?.project?.title} </h2>
<CardContent> <CardContent>
<strong> <strong>
<br></br> <br></br>
...@@ -54,13 +55,11 @@ const FullProject = () => { ...@@ -54,13 +55,11 @@ const FullProject = () => {
</strong> </strong>
<strong> <strong>
<br></br> <br></br>
<div style={{display: 'flex', direction: 'column'}}> <div style={{ display: 'flex', direction: 'column' }}>
Участники проекта: {(project?.project?.members[0]?.user.displayName === user.displayName) ? <NewMember members={project?.project?.members} /> : null} Участники проекта: {(project?.project?.members[0]?.user.displayName === user.displayName) ? <NewMember members={project?.project?.members} /> : null}
</div> </div>
<ProjectMembersList users={users} project={project} members={project?.project?.members} roleProjectOfAuthor={project?.project?.members[0]?.roleProject} authorOfProject={project?.project?.members[0]?.user.displayName}/> <ProjectMembersList users={users} project={project} members={project?.project?.members} roleProjectOfAuthor={project?.project?.members[0]?.roleProject} authorOfProject={project?.project?.members[0]?.user.displayName} />
</strong> </strong>
<strong> <strong>
<br></br> <br></br>
......
...@@ -12,3 +12,7 @@ export const DELETE_MEMBER_SUCCESS = "DELETE_MEMBER_SUCCESS"; ...@@ -12,3 +12,7 @@ export const DELETE_MEMBER_SUCCESS = "DELETE_MEMBER_SUCCESS";
export const DELETE_MEMBER_FAILURE = "DELETE_MEMBER_FAILURE"; export const DELETE_MEMBER_FAILURE = "DELETE_MEMBER_FAILURE";
export const FETCH_ALL_USER_PROJECTS_SUCCESS = "FETCH_ALL_USER_PROJECTS_SUCCESS"; export const FETCH_ALL_USER_PROJECTS_SUCCESS = "FETCH_ALL_USER_PROJECTS_SUCCESS";
export const DELETE_PROJECT_REQUEST = "DELETE_PROJECT_REQUEST";
export const DELETE_PROJECT_SUCCESS = "DELETE_PROJECT_SUCCESS";
export const DELETE_PROJECT_FAILURE = "DELETE_PROJECT_FAILURE";
\ No newline at end of file
import axios from "../../axiosPlanner"; import axios from "../../axiosPlanner";
import { CREATE_MEMBER_SUCCESS, CREATE_PROJECT_SUCCESS, DELETE_MEMBER_FAILURE, DELETE_MEMBER_REQUEST, DELETE_MEMBER_SUCCESS, FETCH_ALL_USER_PROJECTS_SUCCESS, FETCH_MEMBERS_ERROR, FETCH_MEMBERS_REQUEST, FETCH_MEMBERS_SUCCESS, FETCH_PROJECTS_ERROR, FETCH_PROJECTS_REQUEST, FETCH_PROJECTS_SUCCESS, FETCH_PROJECT_SUCCESS } from "../actionTypes/projectsActionTypes"; import { CREATE_MEMBER_SUCCESS, CREATE_PROJECT_SUCCESS, DELETE_MEMBER_FAILURE, DELETE_MEMBER_REQUEST, DELETE_MEMBER_SUCCESS, DELETE_PROJECT_FAILURE, DELETE_PROJECT_REQUEST, DELETE_PROJECT_SUCCESS, FETCH_ALL_USER_PROJECTS_SUCCESS, FETCH_PROJECTS_ERROR, FETCH_PROJECTS_REQUEST, FETCH_PROJECTS_SUCCESS, FETCH_PROJECT_SUCCESS } from "../actionTypes/projectsActionTypes";
import { showNotification } from "./commonActions"; import { showNotification } from "./commonActions";
const fetchProjectsRequest = () => { const fetchProjectsRequest = () => {
return {type: FETCH_PROJECTS_REQUEST} return { type: FETCH_PROJECTS_REQUEST }
}; };
const fetchProjectsSuccess = (projects) => { const fetchProjectsSuccess = (projects) => {
return {type: FETCH_PROJECTS_SUCCESS, projects}; return { type: FETCH_PROJECTS_SUCCESS, projects };
}; };
const fetchProjectsError = (error) => { const fetchProjectsError = (error) => {
return {type: FETCH_PROJECTS_ERROR, error}; return { type: FETCH_PROJECTS_ERROR, error };
} }
const fetchProjectSuccess = (project) => { const fetchProjectSuccess = (project) => {
return {type: FETCH_PROJECT_SUCCESS, project}; return { type: FETCH_PROJECT_SUCCESS, project };
}; };
const createProjectSuccess = () => { const createProjectSuccess = () => {
return {type: CREATE_PROJECT_SUCCESS}; return { type: CREATE_PROJECT_SUCCESS };
}; };
const createMemberSuccess = (member) => { const createMemberSuccess = (member) => {
return {type: CREATE_MEMBER_SUCCESS, member}; return { type: CREATE_MEMBER_SUCCESS, member };
}; };
const deleteMemberRequest = () => { const deleteMemberRequest = () => {
return {type: DELETE_MEMBER_REQUEST} return { type: DELETE_MEMBER_REQUEST }
}; };
const deleteMemberSuccess = () => { const deleteMemberSuccess = () => {
return {type: DELETE_MEMBER_SUCCESS} return { type: DELETE_MEMBER_SUCCESS }
}; };
const deleteMemberFailure = (error) => { const deleteMemberFailure = (error) => {
return {type: DELETE_MEMBER_FAILURE, error} return { type: DELETE_MEMBER_FAILURE, error }
}; };
export const deleteMember = (memberId, projectId) => { const deleteProjectRequest = () => {
return { type: DELETE_PROJECT_REQUEST }
};
const deleteProjectSuccess = () => {
return { type: DELETE_PROJECT_SUCCESS }
};
const deleteProjectFailure = (error) => {
return { type: DELETE_PROJECT_FAILURE, error }
};
export const deleteMember = (memberId, projectId) => {
return async (dispatch) => { return async (dispatch) => {
dispatch(deleteMemberRequest()); dispatch(deleteMemberRequest());
try { try {
const response = await axios.delete(`/projects/remove-user/${memberId}`, { data: { projectId: projectId}}); const response = await axios.delete(`/projects/remove-user/${memberId}`, { data: { projectId: projectId } });
console.log("deleteMember ", response.data) console.log("deleteMember ", response.data)
dispatch(deleteMemberSuccess()) dispatch(deleteMemberSuccess())
dispatch(fetchProject(projectId)) dispatch(fetchProject(projectId))
...@@ -48,15 +59,28 @@ const deleteMemberRequest = () => { ...@@ -48,15 +59,28 @@ const deleteMemberRequest = () => {
dispatch(deleteMemberFailure(error.response.data)); dispatch(deleteMemberFailure(error.response.data));
} }
} }
} }
export const deleteProject = (projectId, projects) => {
return async (dispatch) => {
dispatch(deleteProjectRequest());
try {
const response = await axios.delete('/projects', { data: { projectId: projectId } });
console.log("deleteMember ", response.data)
dispatch(deleteProjectSuccess())
dispatch(fetchProjects(projects))
} catch (error) {
dispatch(deleteProjectFailure(error.response.data));
}
}
}
export const fetchProjects = () => { export const fetchProjects = () => {
return async dispatch => { return async dispatch => {
dispatch(fetchProjectsRequest()); dispatch(fetchProjectsRequest());
try { try {
const response = await axios.get("/projects/my"); const response = await axios.get("/projects/my");
dispatch(fetchProjectsSuccess(response.data)); dispatch(fetchProjectsSuccess(response.data));
} catch(e) { } catch (e) {
dispatch(fetchProjectsError(e)); dispatch(fetchProjectsError(e));
} }
}; };
...@@ -94,7 +118,7 @@ export const createMember = (memberData, navigate) => { ...@@ -94,7 +118,7 @@ export const createMember = (memberData, navigate) => {
return async (dispatch) => { return async (dispatch) => {
try { try {
console.log(memberData) console.log(memberData)
const response = await axios.post("/projects/add-user", memberData); await axios.post("/projects/add-user", memberData);
dispatch(createMemberSuccess()); dispatch(createMemberSuccess());
console.log(memberData) console.log(memberData)
navigate("/projects/") navigate("/projects/")
...@@ -107,7 +131,7 @@ export const createMember = (memberData, navigate) => { ...@@ -107,7 +131,7 @@ export const createMember = (memberData, navigate) => {
} }
const fetchAllUserProjectsSuccess = (projects) => { const fetchAllUserProjectsSuccess = (projects) => {
return {type: FETCH_ALL_USER_PROJECTS_SUCCESS, projects}; return { type: FETCH_ALL_USER_PROJECTS_SUCCESS, projects };
}; };
export const fetchAllUserProjects = () => { export const fetchAllUserProjects = () => {
......
import {DELETE_MEMBER_FAILURE, DELETE_MEMBER_REQUEST, DELETE_MEMBER_SUCCESS, FETCH_ALL_USER_PROJECTS_SUCCESS, FETCH_PROJECTS_ERROR, FETCH_PROJECTS_REQUEST, FETCH_PROJECTS_SUCCESS, FETCH_PROJECT_SUCCESS } from "../actionTypes/projectsActionTypes"; import {DELETE_MEMBER_FAILURE, DELETE_MEMBER_REQUEST, DELETE_MEMBER_SUCCESS, DELETE_PROJECT_FAILURE, DELETE_PROJECT_REQUEST, DELETE_PROJECT_SUCCESS, FETCH_ALL_USER_PROJECTS_SUCCESS, FETCH_PROJECTS_ERROR, FETCH_PROJECTS_REQUEST, FETCH_PROJECTS_SUCCESS, FETCH_PROJECT_SUCCESS } from "../actionTypes/projectsActionTypes";
const initialState = { const initialState = {
allUserProjects: [], allUserProjects: [],
...@@ -24,6 +24,12 @@ const initialState = { ...@@ -24,6 +24,12 @@ const initialState = {
return {...state, loading: true}; return {...state, loading: true};
case DELETE_MEMBER_FAILURE: case DELETE_MEMBER_FAILURE:
return {...state, loading: false, error: action.error}; return {...state, loading: false, error: action.error};
case DELETE_PROJECT_SUCCESS:
return {...state, loading: false};
case DELETE_PROJECT_REQUEST:
return {...state, loading: true};
case DELETE_PROJECT_FAILURE:
return {...state, loading: false, error: action.error};
case FETCH_ALL_USER_PROJECTS_SUCCESS: case FETCH_ALL_USER_PROJECTS_SUCCESS:
return {...state, loading: false, allUserProjects: action.projects} return {...state, loading: false, allUserProjects: action.projects}
default: default:
......
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