guild_front/src/components/ProjectTiket/ProjectTiket.jsx

116 lines
3.1 KiB
React
Raw Normal View History

2023-04-14 15:52:21 +03:00
import React, { useEffect, useState } from "react";
2023-05-03 22:06:19 +03:00
import { useDispatch } from "react-redux";
import { Link } from "react-router-dom";
2023-05-30 10:10:34 +03:00
import { deleteProject, modalToggle } from "@redux/projectsTrackerSlice";
2023-04-14 15:52:21 +03:00
2023-05-31 08:36:15 +03:00
import { apiRequest } from "@api/request";
2023-05-30 10:54:47 +03:00
import { ModalSelect } from "@components/Modal/ModalSelect/ModalSelect";
2023-06-22 19:18:41 +03:00
import TrackerModal from "@components/Modal/Tracker/TrackerModal/TrackerModal";
2023-05-30 10:10:34 +03:00
import archiveSet from "assets/icons/archive.svg";
import del from "assets/icons/delete.svg";
import edit from "assets/icons/edit.svg";
2023-05-31 08:36:15 +03:00
import link from "assets/icons/link.svg";
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-05-03 22:06:19 +03:00
const [modalSelect, setModalSelect] = useState(false);
const [modalAdd, setModalAdd] = 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"))
) {
2023-05-03 22:06:19 +03:00
setModalSelect(false);
2023-04-14 15:52:21 +03:00
}
}
2023-04-28 18:29:13 +03:00
function removeProject() {
2023-05-03 22:06:19 +03:00
apiRequest("/project/update", {
method: "PUT",
2023-04-28 18:29:13 +03:00
data: {
project_id: project.id,
2023-05-05 00:50:48 +03:00
status: 10,
2023-05-03 22:06:19 +03:00
},
2023-05-31 11:24:46 +03:00
}).then(() => {
2023-05-03 22:06:19 +03:00
dispatch(deleteProject(project));
});
2023-04-28 18:29:13 +03:00
}
function copyProjectLink() {
navigator.clipboard.writeText(
`https://itguild.info/tracker/project/${project.id}`
);
}
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-03 22:06:19 +03:00
<span className="count">
{project.columns.reduce(
(accumulator, currentValue) =>
accumulator + currentValue.tasks.length,
0
)}
</span>
<span className="menu-settings" onClick={() => setModalSelect(true)}>
2023-04-14 15:52:21 +03:00
...
</span>
</div>
2023-05-05 16:10:25 +03:00
<TrackerModal
2023-05-03 22:06:19 +03:00
active={modalAdd}
setActive={setModalAdd}
defautlInput={project.name}
2023-05-08 00:41:39 +03:00
projectId={project.id}
2023-05-05 16:10:25 +03:00
></TrackerModal>
2023-05-03 22:06:19 +03:00
<ModalSelect active={modalSelect}>
2023-04-14 15:52:21 +03:00
<div className="project__settings-menu">
2023-05-03 22:06:19 +03:00
<div
onClick={() => {
dispatch(modalToggle("editProject"));
setModalAdd(true);
setModalSelect(false);
}}
>
2023-04-14 15:52:21 +03:00
<img src={edit}></img>
<p>редактировать</p>
</div>
<div>
<img src={link}></img>
<p onClick={copyProjectLink}>ссылка на проект</p>
2023-04-14 15:52:21 +03:00
</div>
<div>
<img src={archiveSet}></img>
<p>в архив</p>
</div>
2023-05-03 22:06:19 +03:00
<div onClick={removeProject}>
2023-04-14 15:52:21 +03:00
<img src={del}></img>
<p>удалить</p>
</div>
</div>
2023-05-03 22:06:19 +03:00
</ModalSelect>
2023-04-14 15:52:21 +03:00
</div>
);
};
export default ProjectTiket;