Commit eafabf99 authored by Ibadullina Inabat's avatar Ibadullina Inabat

реализовано удаление проекта

parent 81461d91
......@@ -80,7 +80,7 @@ export const authAuthorOrExecutorOfDateTimeTask = async(req: Request,res: Respon
req.body={...req.body,executorStatus:false}
req.body={...req.body,authorStatus:false}
dateTimeTaskId = req.body.dateTimeTaskId
if (req.body?.dateTimeTaskId) {
if (req.body?.dateTimeTaskId) {
dateTimeTaskId = req.body.dateTimeTaskId
} else if (req.params?.dateTimeTaskId){
dateTimeTaskId = req.params.dateTimeTaskId
......
......@@ -92,8 +92,8 @@ router.get("/:id",async (req:Request, res:Response): Promise<Response> => {
})
/** Delete project by project ID*/
router.delete('/:projectId',authAdminProject,async (req: Request, res: Response):Promise<Response>=>{
const projectId = req.params.projectId;
router.delete('/',authAdminProject,async (req: Request, res: Response):Promise<Response>=>{
const {projectId} = req.body;
await myDataSource
.createQueryBuilder()
.delete()
......
......@@ -5,14 +5,15 @@ import { useDispatch, useSelector } from "react-redux";
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 dispatch = useDispatch();
console.log(id)
console.log(user)
const deleteHandle = (id) => {
dispatch(deleteProject(id))
const deleteHandle = (projectId) => {
console.log("project id", projectId)
dispatch(deleteProject(projectId))
};
return <>
......@@ -29,15 +30,15 @@ const ProjectItem = ({ title, tasks, id }) => {
</strong>
</CardContent>
<CardActions>
{<Button onClick={(id) => {
deleteHandle(id);
}} variant="outlined" startIcon={<DeleteIcon />}>
Delete
</Button>}
<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 />
</IconButton>
</CardActions>
</Card>
</Grid>
......
import { Card, CardActions, CardContent, Grid, IconButton, Tooltip } from "@mui/material";
import { Link, useParams } from "react-router-dom";
import ArrowForwardIcon from "@mui/icons-material/ArrowForward";
import { useDispatch, useSelector } from "react-redux";
import { Card, CardContent, Grid, IconButton, Tooltip } from "@mui/material";
import { useParams } from "react-router-dom";
import { useDispatch } from "react-redux";
import DeleteIcon from "@mui/icons-material/Delete";
import { deleteMember } from "../../../store/actions/projectsActions";
const ProjectMembersItem = ({ displayName, roleProject, id, roleProjectOfAuthor, userId, members, authorOfProject }) => {
console.log(displayName)
const dispatch = useDispatch();
const user = useSelector(state => state.users)
let params = useParams()
console.log(members)
console.log(userId)
const { projects, project } = useSelector(state => state.projects);
const deleteHandle = (userId, projectId) => {
dispatch(deleteMember(userId, params.id))
};
dispatch(deleteMember(userId, params.id))
};
return <>
<Grid item xs={12} sm={12} md={6} lg={4}>
......@@ -39,7 +36,7 @@ const ProjectMembersItem = ({ displayName, roleProject, id, roleProjectOfAuthor,
onClick={(id) => {
deleteHandle(userId);
}}
> {(displayName !== authorOfProject) ? <DeleteIcon style={{ marginTop: "-5px" }} /> : null}
> {(displayName !== authorOfProject) ? <DeleteIcon style={{ marginTop: "-5px" }} /> : null}
</IconButton>
</Tooltip>
</strong>) : null}
......
......@@ -13,7 +13,7 @@ const ProjectsList = ({projects}) => {
createdAt={project.createdAt}
dateDue={project.dateDue}
admin={project.admin}
id={project.id}
projectId={project.id}
key={project.id}
/>
})}
......
import { Button, Card, CardActions, CardContent, Grid, IconButton } from "@mui/material";
import { Card, CardActions, CardContent, Grid } from "@mui/material";
import { useParams } from "react-router-dom";
import { useSelector, useDispatch } from "react-redux";
import { useEffect } from "react";
......
import axios from "../../axiosPlanner";
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_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";
const fetchProjectsRequest = () => {
return {type: FETCH_PROJECTS_REQUEST}
return { type: FETCH_PROJECTS_REQUEST }
};
const fetchProjectsSuccess = (projects) => {
return {type: FETCH_PROJECTS_SUCCESS, projects};
return { type: FETCH_PROJECTS_SUCCESS, projects };
};
const fetchProjectsError = (error) => {
return {type: FETCH_PROJECTS_ERROR, error};
return { type: FETCH_PROJECTS_ERROR, error };
}
const fetchProjectSuccess = (project) => {
return {type: FETCH_PROJECT_SUCCESS, project};
return { type: FETCH_PROJECT_SUCCESS, project };
};
const createProjectSuccess = () => {
return {type: CREATE_PROJECT_SUCCESS};
return { type: CREATE_PROJECT_SUCCESS };
};
const createMemberSuccess = (member) => {
return {type: CREATE_MEMBER_SUCCESS, member};
return { type: CREATE_MEMBER_SUCCESS, member };
};
const deleteMemberRequest = () => {
return {type: DELETE_MEMBER_REQUEST}
};
const deleteMemberSuccess = () => {
return {type: DELETE_MEMBER_SUCCESS}
};
const deleteMemberFailure = (error) => {
return {type: DELETE_MEMBER_FAILURE, error}
};
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 { type: DELETE_MEMBER_REQUEST }
};
const deleteMemberSuccess = () => {
return { type: DELETE_MEMBER_SUCCESS }
};
const deleteMemberFailure = (error) => {
return { type: DELETE_MEMBER_FAILURE, error }
};
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) => {
dispatch(deleteMemberRequest());
try {
const response = await axios.delete(`/projects/remove-user/${memberId}`, { data: { projectId: projectId}});
console.log("deleteMember ", response.data)
dispatch(deleteMemberSuccess())
dispatch(fetchProject(projectId))
const response = await axios.delete(`/projects/remove-user/${memberId}`, { data: { projectId: projectId } });
console.log("deleteMember ", response.data)
dispatch(deleteMemberSuccess())
dispatch(fetchProject(projectId))
} catch (error) {
dispatch(deleteMemberFailure(error.response.data));
dispatch(deleteMemberFailure(error.response.data));
}
}
}
}
export const deleteProject = (projectId, projects) => {
export const deleteProject = (projectId, projects) => {
return async (dispatch) => {
dispatch(deleteProjectRequest());
try {
const response = await axios.delete(`/projects/${projectId}`);
console.log("deleteMember ", response.data)
dispatch(deleteProjectSuccess())
dispatch(fetchProjects(projects))
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));
dispatch(deleteProjectFailure(error.response.data));
}
}
}
}
export const fetchProjects = () => {
return async dispatch => {
dispatch(fetchProjectsRequest());
try {
const response = await axios.get("/projects/my");
dispatch(fetchProjectsSuccess(response.data));
} catch(e) {
} catch (e) {
dispatch(fetchProjectsError(e));
}
};
......@@ -102,10 +102,10 @@ export const fetchProject = (id) => {
export const createProject = (projectData, navigate) => {
return async (dispatch) => {
try {
const response = await axios.post("/projects", projectData);
const response = await axios.post("/projects", projectData);
dispatch(createProjectSuccess());
console.log(response.data)
navigate("/projects/" + response.data.project.id)
navigate("/projects/" + response.data.project.id)
dispatch(showNotification("Проект успешно создан"))
} catch (e) {
console.log(e);
......@@ -118,10 +118,10 @@ export const createMember = (memberData, navigate) => {
return async (dispatch) => {
try {
console.log(memberData)
const response = await axios.post("/projects/add-user", memberData);
await axios.post("/projects/add-user", memberData);
dispatch(createMemberSuccess());
console.log(memberData)
navigate("/projects/")
navigate("/projects/")
dispatch(showNotification("Участник успешно добавлен"))
} catch (e) {
console.log(e);
......@@ -131,7 +131,7 @@ export const createMember = (memberData, navigate) => {
}
const fetchAllUserProjectsSuccess = (projects) => {
return {type: FETCH_ALL_USER_PROJECTS_SUCCESS, projects};
return { type: FETCH_ALL_USER_PROJECTS_SUCCESS, projects };
};
export const fetchAllUserProjects = () => {
......
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