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";
const ProjectItem = ({ title, tasks, projectId, onClickProjectHandler }) => { import DeleteButton from "../../../../UI/DeleteButton/DeleteButton";
const user = useSelector(state => state.users.user); import ArrowIncrementButton from "../../../../UI/ArrowIncrementButton/ArrowIncrementButton";
const dispatch = useDispatch();
const styleBlock = {
console.log(user) border: '2px solid black',
borderRadius: '5px',
const deleteHandle = (projectId) => { width: '100%',
console.log("project id", projectId) padding: '15px',
dispatch(deleteProject(projectId)) }
};
const fullInfo = (projectId) => { const styleText = {
console.log("full project info", projectId) fontSize: '15px',
dispatch(fetchProject(projectId)) fontWeight: '600',
}; }
const ProjectItem = ({ title, members, onClickProjectHandler }) => {
const { user } = useSelector(state => state.users);
const currentRoleInProject = useMemo(() => {
return members.find((member) => member.user.id === user.id)?.roleProject
}, [members, user.id])
return <> return <>
<Grid item xs={12} sm={12} md={6} lg={4} onClick={onClickProjectHandler}> <Grid item container xs={12} onClick={onClickProjectHandler} sx={styleBlock} justifyContent={'space-between'} alignItems={'center'}>
<Card> <Grid item>
<CardContent onClick={() => {fullInfo(projectId)}} > <Typography sx={styleText}>
<strong> Проект: {title}
<br></br> </Typography>
Название проекта: {title} <Typography sx={styleText}>
</strong> Роль в проекте: {currentRoleInProject}
<strong> </Typography>
<br></br> </Grid>
{/* Задачи: {tasks} */} <Grid item>
</strong> <DeleteButton />
</CardContent> <ArrowIncrementButton />
<CardActions> </Grid>
{(title !== "Личные дела") ? <Button onClick={() => {
deleteHandle(projectId);
}} variant="outlined" startIcon={<DeleteIcon />}>
Delete
</Button> : null}
</CardActions>
</Card>
</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