Commit c83389aa authored by Ermolaev Timur's avatar Ermolaev Timur

#142 Вывел список проектов без логики

parent 3e820415
import { Button, Card, CardActions, CardContent, Grid, IconButton } from "@mui/material"; import { Button, Card, CardActions, CardContent, Grid, IconButton, Typography } 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, fetchProject } from "../../../../../store/actions/projectsActions"; import { deleteProject, fetchProject } from "../../../../../store/actions/projectsActions";
import { useEffect } from "react"; import { memo, useEffect, useMemo } from "react";
import { Box } from "@mui/system";
import DeleteButton from "../../../../UI/DeleteButton/DeleteButton";
import ArrowIncrementButton from "../../../../UI/ArrowIncrementButton/ArrowIncrementButton";
const ProjectItem = ({ title, tasks, projectId, onClickProjectHandler }) => { const styleBlock = {
const user = useSelector(state => state.users.user); border: '2px solid black',
const dispatch = useDispatch(); borderRadius: '5px',
width: '100%',
padding: '15px',
}
console.log(user) const styleText = {
fontSize: '15px',
fontWeight: '600',
}
const deleteHandle = (projectId) => { const ProjectItem = ({ title, members, onClickProjectHandler }) => {
console.log("project id", projectId)
dispatch(deleteProject(projectId))
};
const fullInfo = (projectId) => {
console.log("full project info", projectId)
dispatch(fetchProject(projectId))
};
const { user } = useSelector(state => state.users);
const currentRoleInProject = useMemo(() => {
return <> return members.find((member) => member.user.id === user.id)?.roleProject
<Grid item xs={12} sm={12} md={6} lg={4} onClick={onClickProjectHandler}> }, [members, user.id])
<Card>
<CardContent onClick={() => {fullInfo(projectId)}} >
<strong>
<br></br>
Название проекта: {title}
</strong>
<strong>
<br></br>
{/* Задачи: {tasks} */}
</strong>
</CardContent>
<CardActions>
{(title !== "Личные дела") ? <Button onClick={() => {
deleteHandle(projectId);
}} variant="outlined" startIcon={<DeleteIcon />}>
Delete
</Button> : null}
</CardActions> return <>
</Card> <Grid item container xs={12} onClick={onClickProjectHandler} sx={styleBlock} justifyContent={'space-between'} alignItems={'center'}>
<Grid item>
<Typography sx={styleText}>
Проект: {title}
</Typography>
<Typography sx={styleText}>
Роль в проекте: {currentRoleInProject}
</Typography>
</Grid>
<Grid item>
<DeleteButton />
<ArrowIncrementButton />
</Grid>
</Grid> </Grid>
</> </>
}; };
export default ProjectItem; export default memo(ProjectItem);
import {Grid} from "@mui/material"; import {Grid} from "@mui/material";
import { memo } from "react";
import ProjectItem from "./ProjectItem/ProjectItem"; import ProjectItem from "./ProjectItem/ProjectItem";
const ProjectsList = ({projects, onClickProjectHandler}) => { const ProjectsList = ({projects, onClickProjectHandler}) => {
return ( return (
<Grid item container direction="column" spacing={1}> <Grid item container gap={3}>
{projects?.map(project => { {projects?.map(project => {
return <ProjectItem return <ProjectItem
title={project.title} title={project.title}
createdAt={project.createdAt} members={project.members}
projectId={project.id}
key={project.id} key={project.id}
onClickProjectHandler={()=>{onClickProjectHandler(project)}} onClickProjectHandler={()=>{onClickProjectHandler(project)}}
/> />
...@@ -17,4 +17,4 @@ const ProjectsList = ({projects, onClickProjectHandler}) => { ...@@ -17,4 +17,4 @@ const ProjectsList = ({projects, onClickProjectHandler}) => {
); );
}; };
export default ProjectsList; export default memo(ProjectsList);
\ No newline at end of file \ No newline at end of file
import { Grid, Typography, Button, Card, CardContent } from "@mui/material"; import { Grid, Typography, Button, Card, CardContent } from "@mui/material";
import { memo } from "react";
import ProjectsList from "./ProjectsList/ProjectsList"; import ProjectsList from "./ProjectsList/ProjectsList";
const ProjectsWrapper = ({onClickProjectHandler, projects}) => { const style = {
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
marginBottom: '10px'
}
const ProjectsWrapper = ({ onClickProjectHandler, projects }) => {
return <> return <>
<Grid item xs={4}> <Grid item xs={4}>
<Typography variant="h4"> <Typography variant="h2" sx={style}>
Проекты Проекты
<Button variant="outlined">Создать</Button>
</Typography> </Typography>
<Typography> <ProjectsList projects={projects} onClickProjectHandler={onClickProjectHandler} />
<ProjectsList projects={projects} onClickProjectHandler={onClickProjectHandler} />
</Typography>
</Grid> </Grid>
</> </>
}; };
export default ProjectsWrapper; export default memo(ProjectsWrapper);
\ No newline at end of file \ No newline at end of file
...@@ -6,7 +6,6 @@ const arrowClass = { ...@@ -6,7 +6,6 @@ const arrowClass = {
transition: '0.5s', transition: '0.5s',
"&:hover": { "&:hover": {
background: 'rgb(48, 154, 252, 0.65)',
transition: '0.5s', transition: '0.5s',
transform: 'scale(1.2)' transform: 'scale(1.2)'
} }
......
...@@ -6,7 +6,6 @@ const arrowClass = { ...@@ -6,7 +6,6 @@ const arrowClass = {
transition: '0.5s', transition: '0.5s',
"&:hover": { "&:hover": {
background: 'rgb(48, 154, 252, 0.65)',
transition: '0.5s', transition: '0.5s',
transform: 'scale(1.2)' transform: 'scale(1.2)'
} }
......
import DeleteIcon from "@mui/icons-material/Delete";
import { memo } from 'react';
const arrowClass = {
cursor: 'pointer',
transition: '0.5s',
"&:hover": {
transition: '0.5s',
transform: 'scale(1.2)'
}
}
function DeleteButton({onClick}) {
return (
<>
<DeleteIcon
sx={arrowClass}
onClick={onClick}
/>
</> );
}
export default memo(DeleteButton);
\ No newline at end of file
...@@ -30,7 +30,7 @@ const FullProject = ({projectId}) => { ...@@ -30,7 +30,7 @@ const FullProject = ({projectId}) => {
dispatch(fetchProject(params.id)) dispatch(fetchProject(params.id))
} }
dispatch(fetchUsers()) dispatch(fetchUsers())
}, [params.id, dispatch]); }, [params.id, dispatch, projectId]);
const members = useMemo(() => { const members = useMemo(() => {
return project?.project?.members || [] return project?.project?.members || []
......
...@@ -10,9 +10,8 @@ import ProjectsWrapper from "../../components/ProjectsComponents/ProjectsWrapper ...@@ -10,9 +10,8 @@ import ProjectsWrapper from "../../components/ProjectsComponents/ProjectsWrapper
const Projects = () => { const Projects = () => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const { projects, project, loading } = useSelector(state => state.projects.projects); const { projects, project, loading } = useSelector(state => state.projects.projects);
const members = useSelector(state => state.projects.projects)
const [currentProject, setCurrentProject] = useState(null) const [currentProject, setCurrentProject] = useState(null)
console.log(projects)
useEffect(() => { useEffect(() => {
dispatch(fetchProjects()) dispatch(fetchProjects())
}, [dispatch]); }, [dispatch]);
...@@ -30,9 +29,9 @@ const Projects = () => { ...@@ -30,9 +29,9 @@ const Projects = () => {
direction="row" direction="row"
justifyContent="space-between" justifyContent="space-between"
> >
<Grid item xs={4}>
<ProjectsWrapper projects={projects} onClickProjectHandler={onClickProjectHandler}/> <ProjectsWrapper projects={projects} onClickProjectHandler={onClickProjectHandler}/>
</Grid>
<Grid item xs={7} > <Grid item xs={7} >
{currentProject ? <FullProject projectId={currentProject?.id}/> : null} {currentProject ? <FullProject projectId={currentProject?.id}/> : null}
</Grid> </Grid>
......
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