guild_front/src/components/ProjectTiket/ProjectTiket.js

89 lines
2.5 KiB
JavaScript
Raw Normal View History

2023-04-14 15:52:21 +03:00
import React, { useEffect, useState } from "react";
2023-05-02 18:51:19 +03:00
import {Link} from "react-router-dom";
2023-04-14 15:52:21 +03:00
import ModalSettings from "../UI/ModalSettings/ModalSettings";
import link from "../../images/link.svg";
import archiveSet from "../../images/archive.svg";
import del from "../../images/delete.svg";
import edit from "../../images/edit.svg";
2023-04-28 18:29:13 +03:00
import {apiRequest} from "../../api/request";
2023-04-28 14:56:59 +03:00
import {useDispatch} from "react-redux";
2023-05-02 18:51:19 +03:00
import { deleteProject } from "../../redux/projectsTrackerSlice";
2023-04-28 14:56:59 +03:00
2023-04-14 15:52:21 +03:00
import "./projectTiket.scss";
2023-05-02 18:51:19 +03:00
export const ProjectTiket = ({ project, index }) => {
2023-04-14 15:52:21 +03:00
const [modalSettings, setModalSettings] = useState(false);
2023-04-28 14:56:59 +03:00
const dispatch = useDispatch();
2023-04-14 15:52:21 +03:00
useEffect(() => {
initListeners();
}, []);
function initListeners() {
document.addEventListener("click", closeByClickingOut);
}
function closeByClickingOut(event) {
const path = event.path || (event.composedPath && event.composedPath());
if (
event &&
!path.find((item) => item.classList && item.classList.contains("project"))
) {
setModalSettings(false);
}
}
2023-04-28 18:29:13 +03:00
function removeProject() {
apiRequest('/project/update', {
method: 'PUT',
data: {
project_id: project.id,
status: 0
}
}).then((res) => {
dispatch(deleteProject(project))
})
}
2023-04-14 15:52:21 +03:00
return (
<div className="project" key={index}>
2023-05-02 18:51:19 +03:00
<Link to={`/tracker/project/${project.id}`}>{project.name}</Link>
2023-04-14 15:52:21 +03:00
<div className="project__info">
<p>Открытые задачи</p>
2023-05-02 18:51:19 +03:00
<span className="count">{project.columns.reduce((accumulator, currentValue) => accumulator + currentValue.tasks.length, 0)}</span>
2023-04-28 14:56:59 +03:00
{/*<span className="add">{project.columns.length ? '+' : ''}</span>*/}
2023-04-14 15:52:21 +03:00
<span className="menu-settings" onClick={() => setModalSettings(true)}>
...
</span>
</div>
<ModalSettings active={modalSettings}>
<div className="project__settings-menu">
2023-05-02 18:51:19 +03:00
<div>
2023-04-14 15:52:21 +03:00
<img src={edit}></img>
<p>редактировать</p>
</div>
<div>
<img src={link}></img>
<p>ссылка на проект</p>
</div>
<div>
<img src={archiveSet}></img>
<p>в архив</p>
</div>
2023-04-28 18:29:13 +03:00
<div
onClick={removeProject}>
2023-04-14 15:52:21 +03:00
<img src={del}></img>
<p>удалить</p>
</div>
</div>
</ModalSettings>
</div>
);
};
export default ProjectTiket;