guild_front/src/pages/ProjectTracker/ProjectTracker.js

595 lines
22 KiB
JavaScript
Raw Normal View History

2023-05-03 16:47:20 +03:00
import React, { useEffect, useRef, useState } from "react";
2023-06-22 14:53:35 +03:00
import { useDispatch, useSelector } from "react-redux";
2023-05-04 18:38:56 +03:00
import { Link, useParams } from "react-router-dom";
2023-05-03 16:47:20 +03:00
import {
2023-06-22 14:53:35 +03:00
activeLoader,
deletePersonOnProject,
filterCreatedByMe,
filteredParticipateTasks,
2023-05-05 00:50:48 +03:00
getBoarderLoader,
2023-06-22 14:53:35 +03:00
getProjectBoard,
2023-05-03 16:47:20 +03:00
modalToggle,
2023-06-22 14:53:35 +03:00
movePositionProjectTask,
2023-05-03 16:47:20 +03:00
moveProjectTask,
2023-05-16 00:24:52 +03:00
setColumnId,
2023-06-22 14:53:35 +03:00
setColumnName,
2023-06-09 03:19:09 +03:00
setColumnPriority,
2023-06-22 14:53:35 +03:00
setProjectBoardFetch,
setToggleTab,
} from "@redux/projectsTrackerSlice";
import { urlForLocal } from "@utils/helper";
import { apiRequest } from "@api/request";
2023-06-22 19:18:41 +03:00
import BaseButton from "@components/Common/BaseButton/BaseButton";
2023-06-22 14:53:35 +03:00
import { Footer } from "@components/Common/Footer/Footer";
import { Loader } from "@components/Common/Loader/Loader";
import ModalTicket from "@components/Modal/Tracker/ModalTicket/ModalTicket";
2023-06-22 19:18:41 +03:00
import TrackerModal from "@components/Modal/Tracker/TrackerModal/TrackerModal";
2023-06-26 12:10:49 +03:00
// import TrackerModal from "@components/Modal/TrackerModal/TrackerModal";
2023-06-22 14:53:35 +03:00
import { Navigation } from "@components/Navigation/Navigation";
import { ProfileBreadcrumbs } from "@components/ProfileBreadcrumbs/ProfileBreadcrumbs";
import { ProfileHeader } from "@components/ProfileHeader/ProfileHeader";
import archive from "assets/icons/archiveTracker.svg";
import arrow from "assets/icons/arrows/arrowCalendar.png";
import close from "assets/icons/close.png";
import commentsBoard from "assets/icons/commentsBoard.svg";
import del from "assets/icons/delete.svg";
import edit from "assets/icons/edit.svg";
import filesBoard from "assets/icons/filesBoard.svg";
import project from "assets/icons/trackerProject.svg";
import tasks from "assets/icons/trackerTasks.svg";
import accept from "assets/images/accept.png";
import avatarMok from "assets/images/avatarMok.png";
2023-05-03 16:47:20 +03:00
export const ProjectTracker = () => {
const dispatch = useDispatch();
2023-05-04 18:38:56 +03:00
const projectId = useParams();
2023-05-03 16:47:20 +03:00
2023-05-04 18:38:56 +03:00
const [openColumnSelect, setOpenColumnSelect] = useState({});
const [selectedTab, setSelectedTab] = useState(0);
2023-05-17 02:51:31 +03:00
const [priorityTask, setPriorityTask] = useState(0);
2023-05-04 18:38:56 +03:00
const [wrapperHover, setWrapperHover] = useState({});
2023-06-22 14:53:35 +03:00
const [taskHover, setTaskHover] = useState({});
2023-05-03 16:47:20 +03:00
const [modalAdd, setModalAdd] = useState(false);
const [modalActiveTicket, setModalActiveTicket] = useState(false);
const [selectedTicket, setSelectedTicket] = useState({});
2023-06-22 14:53:35 +03:00
const [personListOpen, setPersonListOpen] = useState(false);
const [checkBoxParticipateTasks, setCheckBoxParticipateTasks] =
useState(false);
const [checkBoxMyTasks, setCheckBoxMyTasks] = useState(false);
2023-05-03 16:47:20 +03:00
const startWrapperIndexTest = useRef({});
const projectBoard = useSelector(getProjectBoard);
2023-05-05 16:10:25 +03:00
const loader = useSelector(getBoarderLoader);
2023-05-03 16:47:20 +03:00
2023-05-04 18:38:56 +03:00
useEffect(() => {
2023-05-05 16:10:25 +03:00
dispatch(activeLoader());
2023-05-04 18:38:56 +03:00
dispatch(setProjectBoardFetch(projectId.id));
}, []);
2023-05-02 18:51:19 +03:00
2023-05-04 18:38:56 +03:00
useEffect(() => {
2023-06-22 14:53:35 +03:00
const tasksHover = {};
const columnHover = {};
2023-05-04 18:38:56 +03:00
if (Object.keys(projectBoard).length) {
projectBoard.columns.forEach((column) => {
setOpenColumnSelect((prevState) => ({
...prevState,
[column.id]: false,
}));
2023-06-22 14:53:35 +03:00
columnHover[column.id] = false;
column.tasks.forEach((task) => (tasksHover[task.id] = false));
2023-05-04 18:38:56 +03:00
});
2023-05-02 18:51:19 +03:00
}
2023-06-22 14:53:35 +03:00
setWrapperHover(columnHover);
setTaskHover(tasksHover);
2023-05-04 18:38:56 +03:00
}, [projectBoard]);
2023-05-02 18:51:19 +03:00
2023-05-03 16:47:20 +03:00
function dragStartHandler(e, task, columnId) {
startWrapperIndexTest.current = { task: task, index: columnId };
}
2023-06-15 21:46:52 +03:00
function dragOverTaskHandler(e, task) {
2023-06-22 14:53:35 +03:00
e.preventDefault();
2023-06-15 21:46:52 +03:00
if (startWrapperIndexTest.current.task.id === task.id) {
2023-06-22 14:53:35 +03:00
return;
2023-06-15 21:46:52 +03:00
}
2023-06-22 14:53:35 +03:00
setTaskHover((prevState) => ({ [prevState]: false, [task.id]: true }));
2023-06-15 21:46:52 +03:00
}
2023-06-22 14:53:35 +03:00
function dragLeaveTaskHandler() {
setTaskHover((prevState) => ({ [prevState]: false }));
2023-06-15 21:46:52 +03:00
}
function dragEndTaskHandler() {
2023-06-22 14:53:35 +03:00
setTaskHover((prevState) => ({ [prevState]: false }));
2023-05-04 18:38:56 +03:00
setWrapperHover((prevState) => ({
[prevState]: false,
}));
2023-06-15 21:46:52 +03:00
}
function dragDropTaskHandler(e, task, column) {
2023-06-22 14:53:35 +03:00
e.preventDefault();
2023-06-15 21:46:52 +03:00
if (task.id === startWrapperIndexTest.current.task.id) {
2023-06-22 14:53:35 +03:00
return;
2023-06-15 21:46:52 +03:00
}
2023-06-22 14:53:35 +03:00
const finishTask = column.tasks.indexOf(task);
dispatch(
movePositionProjectTask({
startTask: startWrapperIndexTest.current.task,
finishTask: task,
finishIndex: finishTask,
})
);
2023-05-03 16:47:20 +03:00
}
function dragOverHandler(e) {
e.preventDefault();
}
function dragEnterHandler(columnId) {
if (columnId === startWrapperIndexTest.current.index) {
return;
}
2023-05-02 18:51:19 +03:00
2023-05-04 18:38:56 +03:00
setWrapperHover((prevState) => ({
[prevState]: false,
[columnId]: true,
}));
2023-05-03 16:47:20 +03:00
}
2023-06-15 21:46:52 +03:00
2023-05-03 16:47:20 +03:00
function dragDropHandler(e, columnId) {
e.preventDefault();
2023-05-02 18:51:19 +03:00
2023-05-04 18:38:56 +03:00
setWrapperHover((prevState) => ({
[prevState]: false,
}));
2023-05-03 16:47:20 +03:00
2023-06-22 14:53:35 +03:00
if (
startWrapperIndexTest.current.index === columnId ||
e.target.className.includes("__item")
) {
2023-06-15 21:46:52 +03:00
return;
}
2023-05-03 16:47:20 +03:00
if (columnId !== startWrapperIndexTest.current.index) {
dispatch(
moveProjectTask({
startWrapperIndex: startWrapperIndexTest.current,
columnId,
})
);
}
}
2023-05-17 02:51:31 +03:00
function selectedTabTask(columnId, length) {
2023-05-03 16:47:20 +03:00
setSelectedTab(columnId);
dispatch(modalToggle("createTiketProject"));
setModalAdd(true);
2023-06-22 14:53:35 +03:00
setPriorityTask(length);
2023-05-03 16:47:20 +03:00
}
function openTicket(e, task) {
setSelectedTicket(task);
setModalActiveTicket(true);
}
2023-06-09 03:19:09 +03:00
function deleteColumn(column) {
2023-06-22 14:53:35 +03:00
const priorityColumns = [];
2023-05-04 18:38:56 +03:00
apiRequest("/project-column/update-column", {
method: "PUT",
data: {
2023-06-09 03:19:09 +03:00
column_id: column.id,
2023-05-04 18:38:56 +03:00
project_id: projectBoard.id,
status: 0,
},
2023-06-12 22:14:45 +03:00
}).then(() => {
2023-06-09 03:19:09 +03:00
if (column.priority < projectBoard.columns.length) {
for (let i = column.priority; i < projectBoard.columns.length; i++) {
const currentColumn = {
column_id: projectBoard.columns[i].id,
2023-06-22 14:53:35 +03:00
priority: i,
};
priorityColumns.push(currentColumn);
2023-06-09 03:19:09 +03:00
}
apiRequest("/project-column/set-priority", {
method: "POST",
data: {
project_id: projectBoard.id,
2023-06-22 14:53:35 +03:00
data: JSON.stringify(priorityColumns),
},
2023-06-09 03:19:09 +03:00
}).then(() => {
dispatch(setProjectBoardFetch(projectBoard.id));
2023-06-22 14:53:35 +03:00
});
2023-06-09 03:19:09 +03:00
} else {
dispatch(setProjectBoardFetch(projectBoard.id));
}
2023-05-04 18:38:56 +03:00
});
}
2023-05-02 18:51:19 +03:00
2023-05-23 23:02:39 +03:00
function deletePerson(userId) {
apiRequest("/project/del-user", {
method: "DELETE",
data: {
project_id: projectBoard.id,
2023-06-22 14:53:35 +03:00
user_id: userId,
2023-05-23 23:02:39 +03:00
},
2023-06-12 22:14:45 +03:00
}).then(() => {
2023-06-22 14:53:35 +03:00
dispatch(deletePersonOnProject(userId));
2023-05-23 23:02:39 +03:00
});
}
2023-06-09 03:19:09 +03:00
function filterParticipateTasks() {
if (!checkBoxParticipateTasks) {
2023-06-22 14:53:35 +03:00
dispatch(filteredParticipateTasks(Number(localStorage.getItem("id"))));
2023-06-09 03:19:09 +03:00
} else {
2023-06-22 14:53:35 +03:00
dispatch(setProjectBoardFetch(projectId.id));
setCheckBoxParticipateTasks(false);
setCheckBoxMyTasks(false);
2023-06-09 03:19:09 +03:00
}
2023-06-22 14:53:35 +03:00
setCheckBoxParticipateTasks(!checkBoxParticipateTasks);
2023-06-09 03:19:09 +03:00
}
function filterMyTask() {
if (!checkBoxMyTasks) {
2023-06-22 14:53:35 +03:00
dispatch(filterCreatedByMe(Number(localStorage.getItem("id"))));
2023-06-09 03:19:09 +03:00
} else {
2023-06-22 14:53:35 +03:00
dispatch(setProjectBoardFetch(projectId.id));
setCheckBoxParticipateTasks(false);
setCheckBoxMyTasks(false);
2023-06-09 03:19:09 +03:00
}
2023-06-22 14:53:35 +03:00
setCheckBoxMyTasks(!checkBoxMyTasks);
2023-06-09 03:19:09 +03:00
}
2023-05-03 16:47:20 +03:00
return (
<div className="tracker">
<ProfileHeader />
<Navigation />
<div className="container">
<div className="tracker__content">
<ProfileBreadcrumbs
links={[
{ name: "Главная", link: "/profile" },
{ name: "Трекер", link: "/profile/tracker" },
]}
/>
<h2 className="tracker__title">Управление проектами с трекером</h2>
</div>
</div>
<div className="tracker__tabs">
<div className="tracker__tabs__head">
<Link
to="/profile/tracker"
className="tab active-tab tab"
onClick={() => dispatch(setToggleTab(1))}
>
<img src={project} alt="img" />
<p>Проекты </p>
</Link>
<Link
to="/profile/tracker"
className="tab"
onClick={() => dispatch(setToggleTab(2))}
>
<img src={tasks} alt="img" />
<p>Все мои задачи</p>
</Link>
<Link
to="/profile/tracker"
className="tab"
onClick={() => dispatch(setToggleTab(3))}
>
<img src={archive} alt="img" />
<p>Архив</p>
</Link>
</div>
<div className="tracker__tabs__content">
2023-05-10 12:23:35 +03:00
<TrackerModal
active={modalAdd}
setActive={setModalAdd}
selectedTab={selectedTab}
2023-05-17 02:51:31 +03:00
priorityTask={priorityTask}
2023-06-27 18:35:44 +03:00
projectUsers={projectBoard.projectUsers}
2023-05-10 12:23:35 +03:00
/>
2023-05-05 16:10:25 +03:00
{loader && <Loader style="green" />}
{!loader && (
<div className="tracker__tabs__content__tasks tasks active__content">
<div className="tasks__head">
<div className="tasks__head__wrapper">
2023-06-26 12:10:49 +03:00
<h5>Проект : {projectBoard.name}</h5>
2023-05-03 16:47:20 +03:00
2023-05-05 16:10:25 +03:00
<div className="tasks__head__add">
2023-06-22 19:18:41 +03:00
<BaseButton
2023-05-05 00:50:48 +03:00
onClick={() => {
dispatch(modalToggle("createColumn"));
setModalAdd(true);
}}
2023-06-22 19:18:41 +03:00
styles={"button-add-column"}
2023-05-05 16:10:25 +03:00
>
+
2023-06-22 19:18:41 +03:00
</BaseButton>
{/* <span
onClick={() => {
dispatch(modalToggle("createColumn"));
setModalAdd(true);
}}
>
+
</span> */}
2023-05-05 16:10:25 +03:00
<p>добавить колонку</p>
</div>
<div className="tasks__head__persons">
2023-06-29 02:26:49 +03:00
{projectBoard.projectUsers?.length > 3 &&
2023-06-22 14:53:35 +03:00
<span className="countPersons">
2023-06-29 02:26:49 +03:00
+1...
2023-06-22 14:53:35 +03:00
</span>
2023-06-29 02:26:49 +03:00
}
<div className="projectPersons">
{projectBoard.projectUsers?.length &&
projectBoard.projectUsers
.slice(
0,
projectBoard.length > 3 ? 3 : projectBoard.length
)
.map((person) => {
return (
<img
key={person.user_id}
src={
person.user?.avatar
? urlForLocal(person.user.avatar)
: avatarMok
}
alt="avatar"
/>
);
})}
</div>
2023-05-05 16:10:25 +03:00
<span
2023-05-05 00:50:48 +03:00
className="addPerson"
onClick={() => {
2023-06-22 14:53:35 +03:00
setPersonListOpen(true);
2023-05-05 00:50:48 +03:00
}}
2023-05-05 16:10:25 +03:00
>
+
</span>
<p>добавить участника</p>
2023-06-22 14:53:35 +03:00
{personListOpen && (
<div className="persons__list">
<img
className="persons__list__close"
src={close}
alt="close"
onClick={() => setPersonListOpen(false)}
/>
<div className="persons__list__count">
<span>{projectBoard.projectUsers?.length}</span>
участник
</div>
<div className="persons__list__info">
В проекте - <span>{projectBoard.name}</span>
</div>
<div className="persons__list__items">
{projectBoard.projectUsers?.map((person) => {
return (
<div
className="persons__list__item"
key={person.user_id}
>
<img
className="avatar"
2023-06-29 02:26:49 +03:00
src={
person.user?.avatar
? urlForLocal(person.user.avatar)
: avatarMok
}
2023-06-22 14:53:35 +03:00
alt="avatar"
/>
<span>{person.user.fio}</span>
<img
className="delete"
src={close}
alt="delete"
onClick={() => deletePerson(person.user_id)}
/>
</div>
);
})}
</div>
<div
className="persons__list__add"
onClick={() => {
dispatch(modalToggle("addWorker"));
setModalAdd(true);
setPersonListOpen(false);
}}
>
<span className="addPerson">+</span>
<p>Добавить участников</p>
</div>
2023-05-23 23:02:39 +03:00
</div>
2023-06-22 14:53:35 +03:00
)}
2023-05-05 16:10:25 +03:00
</div>
2023-06-22 14:53:35 +03:00
<div
className="tasks__head__checkBox"
onClick={filterParticipateTasks}
>
2023-05-05 16:10:25 +03:00
<span>Участвую</span>
2023-06-09 03:19:09 +03:00
<div className="tasks__head__checkBox__box">
2023-06-22 14:53:35 +03:00
{checkBoxParticipateTasks && (
<img src={accept} alt="accept" />
)}
2023-06-09 03:19:09 +03:00
</div>
2023-05-05 16:10:25 +03:00
</div>
2023-06-09 03:19:09 +03:00
<div className="tasks__head__checkBox" onClick={filterMyTask}>
2023-05-05 16:10:25 +03:00
<span>Мои</span>
2023-06-09 03:19:09 +03:00
<div className="tasks__head__checkBox__box">
2023-06-22 14:53:35 +03:00
{checkBoxMyTasks && <img src={accept} alt="accept" />}
2023-06-09 03:19:09 +03:00
</div>
2023-05-05 16:10:25 +03:00
</div>
<Link to="/profile/tracker" className="tasks__head__back">
<p>Вернуться на проекты</p>
<img src={arrow} alt="arrow" />
</Link>
2023-05-03 16:47:20 +03:00
</div>
</div>
2023-06-22 14:53:35 +03:00
{Boolean(modalActiveTicket) && (
<ModalTicket
2023-05-16 00:24:52 +03:00
active={modalActiveTicket}
setActive={setModalActiveTicket}
task={selectedTicket}
projectId={projectBoard.id}
projectName={projectBoard.name}
2023-05-24 01:20:53 +03:00
projectUsers={projectBoard.projectUsers}
2023-06-22 14:53:35 +03:00
/>
)}
2023-05-03 16:47:20 +03:00
2023-05-05 16:10:25 +03:00
<div className="tasks__container">
{Boolean(projectBoard?.columns) &&
Boolean(projectBoard.columns.length) &&
projectBoard.columns.map((column) => {
return (
<div
2023-05-05 00:50:48 +03:00
key={column.id}
onDragOver={(e) => dragOverHandler(e)}
2023-06-22 14:53:35 +03:00
onDragEnter={() => dragEnterHandler(column.id)}
2023-05-05 00:50:48 +03:00
onDrop={(e) => dragDropHandler(e, column.id)}
className={`tasks__board ${
2023-05-05 16:10:25 +03:00
wrapperHover[column.id] ? "tasks__board__hover" : ""
2023-05-05 00:50:48 +03:00
}`}
2023-05-05 16:10:25 +03:00
>
<div className="board__head">
<span>{column.title}</span>
<div>
<span
2023-05-05 00:50:48 +03:00
className="add"
2023-06-22 14:53:35 +03:00
onClick={() =>
2023-06-29 02:26:49 +03:00
selectedTabTask(column.id, projectBoard?.columns ? projectBoard?.columns[0].tasks.at(-1).priority + 1 : 1)
2023-06-22 14:53:35 +03:00
}
2023-05-05 16:10:25 +03:00
>
+
</span>
<span
2023-05-05 00:50:48 +03:00
onClick={() => {
setOpenColumnSelect((prevState) => ({
...prevState,
[column.id]: true,
}));
}}
className="more"
2023-05-05 16:10:25 +03:00
>
...
</span>
</div>
2023-05-03 16:47:20 +03:00
</div>
2023-05-05 16:10:25 +03:00
{openColumnSelect[column.id] && (
2023-05-05 00:50:48 +03:00
<div className="column__select">
<div
2023-05-05 16:10:25 +03:00
className="column__select__item"
onClick={() => {
setOpenColumnSelect((prevState) => ({
...prevState,
[column.id]: false,
}));
dispatch(modalToggle("editColumn"));
2023-06-22 14:53:35 +03:00
dispatch(setColumnName(column.title));
dispatch(setColumnId(column.id));
dispatch(setColumnPriority(column.priority));
2023-05-05 16:10:25 +03:00
setModalAdd(true);
}}
2023-05-05 00:50:48 +03:00
>
<img src={edit} alt="edit" />
<span>Изменить</span>
</div>
<div
2023-05-05 16:10:25 +03:00
className="column__select__item"
2023-06-09 03:19:09 +03:00
onClick={() => deleteColumn(column)}
2023-05-05 00:50:48 +03:00
>
<img src={del} alt="delete" />
<span>Удалить</span>
</div>
2023-05-04 18:38:56 +03:00
</div>
2023-05-05 16:10:25 +03:00
)}
2023-06-15 21:46:52 +03:00
{column.tasks.map((task) => {
2023-05-05 16:10:25 +03:00
return (
2023-05-05 00:50:48 +03:00
<div
2023-05-05 16:10:25 +03:00
key={task.id}
2023-06-15 21:46:52 +03:00
className={`tasks__board__item ${
2023-06-22 14:53:35 +03:00
taskHover[task.id] ? "task__hover" : ""
2023-06-15 21:46:52 +03:00
}`}
2023-05-05 16:10:25 +03:00
draggable={true}
2023-06-22 14:53:35 +03:00
onDragStart={(e) =>
dragStartHandler(e, task, column.id)
}
2023-06-15 21:46:52 +03:00
onDragOver={(e) => dragOverTaskHandler(e, task)}
onDragLeave={(e) => dragLeaveTaskHandler(e)}
2023-06-22 14:53:35 +03:00
onDragEnd={() => dragEndTaskHandler()}
onDrop={(e) =>
dragDropTaskHandler(e, task, column)
}
2023-05-05 16:10:25 +03:00
onClick={(e) => openTicket(e, task)}
2023-05-05 00:50:48 +03:00
>
<div className="tasks__board__item__title">
2023-06-22 14:53:35 +03:00
<p className="task__board__item__title">
{task.title}
</p>
2023-05-03 16:47:20 +03:00
</div>
2023-06-26 13:24:20 +03:00
<p
dangerouslySetInnerHTML={{
__html: task.description,
}}
className="tasks__board__item__description"
></p>
<div className="tasks__board__item__executor">
<span>
{task.executor?.fio
? task.executor?.fio
: "Исполнитель не назначен"}
</span>
{task.executor?.avatar && (
<img
src={
task.executor?.avatar
? urlForLocal(task.executor?.avatar)
: avatarMok
}
alt="avatar"
/>
)}
</div>
2023-05-05 00:50:48 +03:00
<div className="tasks__board__item__info">
<div className="tasks__board__item__info__more">
<img src={commentsBoard} alt="commentsImg" />
2023-05-17 02:51:31 +03:00
<span>{task.comment_count} коментариев</span>
2023-05-05 00:50:48 +03:00
</div>
<div className="tasks__board__item__info__more">
<img src={filesBoard} alt="filesImg" />
<span>{task.files} файлов</span>
</div>
2023-05-03 16:47:20 +03:00
</div>
</div>
2023-05-05 16:10:25 +03:00
);
})}
</div>
);
})}
{Boolean(projectBoard?.columns) &&
!Boolean(projectBoard.columns.length) && (
<div className="tasks__board__noItems">
В проекте нет задач.
2023-05-03 16:47:20 +03:00
</div>
2023-05-05 16:10:25 +03:00
)}
2023-05-05 00:50:48 +03:00
</div>
2023-05-03 16:47:20 +03:00
</div>
2023-05-05 16:10:25 +03:00
)}
2023-05-03 16:47:20 +03:00
</div>
</div>
<Footer />
</div>
);
};