Commit 264d311a authored by Ermolaev Timur's avatar Ermolaev Timur

#142 Реализовал удаление, добавил валидации

parent 1cde5da1
...@@ -2,6 +2,7 @@ import { Button } from "@mui/material"; ...@@ -2,6 +2,7 @@ import { Button } from "@mui/material";
import { Box } from "@mui/system"; import { Box } from "@mui/system";
import { memo } from "react"; import { memo } from "react";
import FormElement from "../../UI/Form/FormElement/FormElement" import FormElement from "../../UI/Form/FormElement/FormElement"
import { isValidate } from "./helpers";
const NewProjectModalContent = ({ inputChangeHandler, projectTitle, createNewProjectHandler, handleClose }) => { const NewProjectModalContent = ({ inputChangeHandler, projectTitle, createNewProjectHandler, handleClose }) => {
...@@ -20,6 +21,7 @@ const NewProjectModalContent = ({ inputChangeHandler, projectTitle, createNewPro ...@@ -20,6 +21,7 @@ const NewProjectModalContent = ({ inputChangeHandler, projectTitle, createNewPro
color="primary" color="primary"
variant="outlined" variant="outlined"
onClick={()=>{createNewProjectHandler()}} onClick={()=>{createNewProjectHandler()}}
disabled={!isValidate(projectTitle)}
> >
Создать Создать
</Button> </Button>
......
export const isValidate = (title) => {
if (!title) return false
return true
}
\ No newline at end of file
import {Grid, Typography } from "@mui/material"; import {Box, Grid, Typography } from "@mui/material";
import { useSelector } from "react-redux"; import { useSelector } from "react-redux";
import { memo, useMemo } from "react"; import { memo, useMemo } from "react";
import DeleteButton from "../../../../UI/DeleteButton/DeleteButton"; import DeleteButton from "../../../../UI/DeleteButton/DeleteButton";
...@@ -7,9 +7,11 @@ import ArrowIncrementButton from "../../../../UI/ArrowIncrementButton/ArrowIncre ...@@ -7,9 +7,11 @@ import ArrowIncrementButton from "../../../../UI/ArrowIncrementButton/ArrowIncre
const styleBlock = { const styleBlock = {
border: '2px solid black', border: '2px solid black',
borderRadius: '5px', borderRadius: '5px',
width: '100%', width: '92%',
padding: '15px', padding: '10px',
height: '10%', display: 'flex',
justifyContent: 'space-between',
alignItems: 'center'
} }
const styleText = { const styleText = {
...@@ -17,7 +19,7 @@ const styleText = { ...@@ -17,7 +19,7 @@ const styleText = {
fontWeight: '600', fontWeight: '600',
} }
const ProjectItem = ({ title, members, onClickProjectHandler, onClickGoToSpecificProjectHandler }) => { const ProjectItem = ({ title, members, onClickProjectHandler, onClickGoToSpecificProjectHandler, deleteProjectHandler }) => {
const { user } = useSelector(state => state.users); const { user } = useSelector(state => state.users);
const currentRoleInProject = useMemo(() => { const currentRoleInProject = useMemo(() => {
...@@ -25,20 +27,20 @@ const ProjectItem = ({ title, members, onClickProjectHandler, onClickGoToSpecifi ...@@ -25,20 +27,20 @@ const ProjectItem = ({ title, members, onClickProjectHandler, onClickGoToSpecifi
}, [members, user.id]) }, [members, user.id])
return <> return <>
<Grid item container xs={12} onClick={onClickProjectHandler} sx={styleBlock} justifyContent={'space-between'} alignItems={'center'}> <Box onClick={onClickProjectHandler} sx={styleBlock}>
<Grid item> <Box>
<Typography sx={styleText}> <Typography sx={styleText}>
Проект: {title} Проект: {title}
</Typography> </Typography>
<Typography sx={styleText}> <Typography sx={styleText}>
Роль в проекте: {currentRoleInProject} Роль в проекте: {currentRoleInProject}
</Typography> </Typography>
</Grid> </Box>
<Grid item> <Box>
<DeleteButton /> {currentRoleInProject === 'admin' ? <DeleteButton onClick={deleteProjectHandler}/> : null}
<ArrowIncrementButton onClick={onClickGoToSpecificProjectHandler}/> <ArrowIncrementButton onClick={onClickGoToSpecificProjectHandler}/>
</Grid> </Box>
</Grid> </Box>
</> </>
}; };
......
import {Grid} from "@mui/material"; import {Box} from "@mui/material";
import { memo } from "react"; import { memo } from "react";
import ProjectItem from "./ProjectItem/ProjectItem"; import ProjectItem from "./ProjectItem/ProjectItem";
const ProjectsList = ({projects, onClickProjectHandler, onClickGoToSpecificProjectHandler}) => { const style = {height: '79vh', overflow: 'auto', overflowX: 'hidden', display: 'flex', flexDirection: 'column', gap: '10px'}
const ProjectsList = ({projects, onClickProjectHandler, onClickGoToSpecificProjectHandler, deleteProjectHandler}) => {
return ( return (
<Grid item container gap={3} sx={{ height: '79vh', overflow: 'auto', overflowX: 'hidden'}}> <Box sx={style}>
{projects?.map(project => { {projects?.map(project => {
return <ProjectItem return <ProjectItem
title={project.title} title={project.title}
...@@ -12,9 +14,10 @@ const ProjectsList = ({projects, onClickProjectHandler, onClickGoToSpecificProje ...@@ -12,9 +14,10 @@ const ProjectsList = ({projects, onClickProjectHandler, onClickGoToSpecificProje
key={project.id} key={project.id}
onClickProjectHandler={()=>{onClickProjectHandler(project)}} onClickProjectHandler={()=>{onClickProjectHandler(project)}}
onClickGoToSpecificProjectHandler={(e)=>{onClickGoToSpecificProjectHandler(e, project.id)}} onClickGoToSpecificProjectHandler={(e)=>{onClickGoToSpecificProjectHandler(e, project.id)}}
deleteProjectHandler={(e)=>{deleteProjectHandler(e, project.id)}}
/> />
})} })}
</Grid> </Box>
); );
}; };
......
...@@ -10,7 +10,7 @@ const style = { ...@@ -10,7 +10,7 @@ const style = {
marginBottom: '10px', marginBottom: '10px',
} }
const ProjectsWrapper = ({ onClickProjectHandler, projects, onClickGoToSpecificProjectHandler, handleOpen }) => { const ProjectsWrapper = ({ onClickProjectHandler, projects, onClickGoToSpecificProjectHandler, handleOpen, deleteProjectHandler }) => {
return <> return <>
...@@ -24,6 +24,7 @@ const ProjectsWrapper = ({ onClickProjectHandler, projects, onClickGoToSpecificP ...@@ -24,6 +24,7 @@ const ProjectsWrapper = ({ onClickProjectHandler, projects, onClickGoToSpecificP
projects={projects} projects={projects}
onClickProjectHandler={onClickProjectHandler} onClickProjectHandler={onClickProjectHandler}
onClickGoToSpecificProjectHandler={onClickGoToSpecificProjectHandler} onClickGoToSpecificProjectHandler={onClickGoToSpecificProjectHandler}
deleteProjectHandler={deleteProjectHandler}
/> />
</Grid> </Grid>
......
import { Grid } from "@mui/material"; import { Grid } from "@mui/material";
import { useCallback, useEffect, useState } from "react"; import { useCallback, useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux"; import { useDispatch, useSelector } from "react-redux";
import { createProject, fetchProjects } from "../../store/actions/projectsActions"; import { createProject, deleteProject, fetchProjects } from "../../store/actions/projectsActions";
import FullProject from "../FullProject/FullProject"; import FullProject from "../FullProject/FullProject";
import ProjectsWrapper from "../../components/ProjectsComponents/ProjectsWrapper/ProjectsWrapper"; import ProjectsWrapper from "../../components/ProjectsComponents/ProjectsWrapper/ProjectsWrapper";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
...@@ -37,10 +37,14 @@ const Projects = () => { ...@@ -37,10 +37,14 @@ const Projects = () => {
}, [navigate]) }, [navigate])
const createNewProjectHandler = useCallback(() => { const createNewProjectHandler = useCallback(() => {
console.log({ title: projectTitle, user: user.id })
dispatch(createProject({ title: projectTitle, user: user.id }, navigate)) dispatch(createProject({ title: projectTitle, user: user.id }, navigate))
}, [dispatch, projectTitle, user.id, navigate]) }, [dispatch, projectTitle, user.id, navigate])
const deleteProjectHandler = useCallback((e, projectId) => {
e.stopPropagation();
dispatch(deleteProject(projectId))
}, [dispatch])
const handleOpen = useCallback(async () => { const handleOpen = useCallback(async () => {
setModal(true) setModal(true)
}, []) }, [])
...@@ -60,6 +64,7 @@ const Projects = () => { ...@@ -60,6 +64,7 @@ const Projects = () => {
onClickProjectHandler={onClickProjectHandler} onClickProjectHandler={onClickProjectHandler}
onClickGoToSpecificProjectHandler={onClickGoToSpecificProjectHandler} onClickGoToSpecificProjectHandler={onClickGoToSpecificProjectHandler}
handleOpen={handleOpen} handleOpen={handleOpen}
deleteProjectHandler={deleteProjectHandler}
/> />
<Grid item xs={7} > <Grid item xs={7} >
......
...@@ -60,14 +60,13 @@ export const deleteMember = (memberId, projectId) => { ...@@ -60,14 +60,13 @@ export const deleteMember = (memberId, projectId) => {
} }
} }
export const deleteProject = (projectId, projects) => { export const deleteProject = (projectId) => {
return async (dispatch) => { return async (dispatch) => {
dispatch(deleteProjectRequest()); dispatch(deleteProjectRequest());
try { try {
const response = await axios.delete('/projects', { data: { projectId: projectId } }); const response = await axios.delete('/projects', { data: { projectId: projectId } });
console.log("deleteMember ", response.data)
dispatch(deleteProjectSuccess()) dispatch(deleteProjectSuccess())
dispatch(fetchProjects(projects)) dispatch(fetchProjects())
} catch (error) { } catch (error) {
dispatch(deleteProjectFailure(error.response.data)); dispatch(deleteProjectFailure(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