guild_front/src/pages/ProjectTracker/ProjectTracker.js

456 lines
17 KiB
JavaScript
Raw Normal View History

2023-05-03 16:47:20 +03:00
import React, { useEffect, useRef, useState } from "react";
2023-05-04 18:38:56 +03:00
import { Link, useParams } from "react-router-dom";
2023-05-03 16:47:20 +03:00
import { ProfileHeader } from "../../components/ProfileHeader/ProfileHeader";
import { ProfileBreadcrumbs } from "../../components/ProfileBreadcrumbs/ProfileBreadcrumbs";
2023-06-12 23:30:18 +03:00
import { Footer } from "@components/Common/Footer/Footer";
2023-05-04 18:38:56 +03:00
import { Navigation } from "../../components/Navigation/Navigation";
2023-06-12 23:30:18 +03:00
import { Loader } from "@components/Common/Loader/Loader";
import { urlForLocal } from '../../utils/helper'
2023-05-03 16:47:20 +03:00
import { useDispatch, useSelector } from "react-redux";
2023-05-04 18:38:56 +03:00
import { apiRequest } from "../../api/request";
2023-05-03 16:47:20 +03:00
import {
getProjectBoard,
2023-05-05 00:50:48 +03:00
getBoarderLoader,
2023-05-03 16:47:20 +03:00
modalToggle,
moveProjectTask,
setProjectBoardFetch,
setToggleTab,
2023-05-05 16:10:25 +03:00
activeLoader,
2023-05-16 00:24:52 +03:00
setColumnName,
setColumnId,
2023-06-09 03:19:09 +03:00
setColumnPriority,
deletePersonOnProject,
filterCreatedByMe,
filteredParticipateTasks
2023-05-03 16:47:20 +03:00
} from "../../redux/projectsTrackerSlice";
import ModalTicket from "../../components/UI/ModalTicket/ModalTicket";
2023-06-12 23:30:18 +03:00
import TrackerModal from "../../components/Modal/TrackerModal/TrackerModal";
2023-05-03 16:47:20 +03:00
2023-06-12 23:30:18 +03:00
import project from "../../assets/icons/trackerProject.svg";
import tasks from "../../assets/icons/trackerTasks.svg";
import archive from "../../assets/icons/archiveTracker.svg";
import commentsBoard from "../../assets/icons/commentsBoard.svg";
import filesBoard from "../../assets/icons/filesBoard.svg";
import arrow from "../../assets/icons/arrows/arrowCalendar.png";
import del from "../../assets/icons/delete.svg";
import edit from "../../assets/icons/edit.svg";
import close from "../../assets/icons/close.png"
import accept from "../../assets/images/accept.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-05-03 16:47:20 +03:00
const [modalAdd, setModalAdd] = useState(false);
const [modalActiveTicket, setModalActiveTicket] = useState(false);
const [selectedTicket, setSelectedTicket] = useState({});
2023-05-23 23:02:39 +03:00
const [personListOpen, setPersonListOpen] = useState(false)
2023-06-09 03:19:09 +03:00
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(() => {
if (Object.keys(projectBoard).length) {
projectBoard.columns.forEach((column) => {
setOpenColumnSelect((prevState) => ({
...prevState,
[column.id]: false,
}));
setWrapperHover((prevState) => ({ ...prevState, [column.id]: false }));
});
2023-05-02 18:51:19 +03:00
}
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 };
setTimeout(() => {
e.target.classList.add("tasks__board__item__hide");
}, 0);
}
function dragEndHandler(e) {
2023-05-04 18:38:56 +03:00
setWrapperHover((prevState) => ({
[prevState]: false,
}));
2023-05-03 16:47:20 +03:00
e.target.classList.remove("tasks__board__item__hide");
}
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
}
function dragDropHandler(e, columnId) {
e.preventDefault();
if (startWrapperIndexTest.current.index === columnId) {
return;
}
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
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-05-17 02:51:31 +03:00
setPriorityTask(length + 1)
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) {
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,
priority: i
}
priorityColumns.push(currentColumn)
}
apiRequest("/project-column/set-priority", {
method: "POST",
data: {
project_id: projectBoard.id,
data: JSON.stringify(priorityColumns)
}
}).then(() => {
dispatch(setProjectBoardFetch(projectBoard.id));
})
} 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,
user_id: userId
},
2023-06-12 22:14:45 +03:00
}).then(() => {
2023-05-23 23:02:39 +03:00
dispatch(deletePersonOnProject(userId))
});
}
2023-06-09 03:19:09 +03:00
function filterParticipateTasks() {
if (!checkBoxParticipateTasks) {
dispatch(filteredParticipateTasks(Number(localStorage.getItem('id'))))
} else {
dispatch(setProjectBoardFetch(projectId.id))
setCheckBoxParticipateTasks(false)
setCheckBoxMyTasks(false)
}
setCheckBoxParticipateTasks(!checkBoxParticipateTasks)
}
function filterMyTask() {
if (!checkBoxMyTasks) {
dispatch(filterCreatedByMe(Number(localStorage.getItem('id'))))
} else {
dispatch(setProjectBoardFetch(projectId.id))
setCheckBoxParticipateTasks(false)
setCheckBoxMyTasks(false)
}
setCheckBoxMyTasks(!checkBoxMyTasks)
}
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-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">
<h4>Проект : {projectBoard.name}</h4>
2023-05-03 16:47:20 +03:00
2023-05-05 16:10:25 +03:00
<div className="tasks__head__add">
<span
2023-05-05 00:50:48 +03:00
onClick={() => {
dispatch(modalToggle("createColumn"));
setModalAdd(true);
}}
2023-05-05 16:10:25 +03:00
>
+
</span>
<p>добавить колонку</p>
</div>
<div className="tasks__head__persons">
2023-05-16 00:24:52 +03:00
<span className="countPersons">{projectBoard.projectUsers?.length}</span>
2023-05-05 16:10:25 +03:00
<span
2023-05-05 00:50:48 +03:00
className="addPerson"
onClick={() => {
2023-05-23 23:02:39 +03:00
setPersonListOpen(true)
2023-05-05 00:50:48 +03:00
}}
2023-05-05 16:10:25 +03:00
>
+
</span>
<p>добавить участника</p>
2023-05-23 23:02:39 +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' src={urlForLocal(person.user.avatar)} 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>
</div>
}
2023-05-05 16:10:25 +03:00
</div>
2023-06-09 03:19:09 +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">
{checkBoxParticipateTasks &&
<img src={accept} alt='accept' />
}
</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">
{checkBoxMyTasks &&
<img src={accept} alt='accept' />
}
</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-05-16 00:24:52 +03:00
{Boolean(modalActiveTicket) && <ModalTicket
active={modalActiveTicket}
setActive={setModalActiveTicket}
task={selectedTicket}
projectId={projectBoard.id}
projectName={projectBoard.name}
2023-05-24 01:20:53 +03:00
projectUsers={projectBoard.projectUsers}
2023-05-16 00:24:52 +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)}
onDragEnter={(e) => dragEnterHandler(column.id)}
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-05-17 02:51:31 +03:00
onClick={() => selectedTabTask(column.id, column.tasks.length)}
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-05-16 00:24:52 +03:00
dispatch(setColumnName(column.title))
dispatch(setColumnId(column.id))
2023-06-09 03:19:09 +03:00
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
)}
{column.tasks.map((task, index) => {
return (
2023-05-05 00:50:48 +03:00
<div
2023-05-05 16:10:25 +03:00
key={task.id}
className="tasks__board__item"
draggable={true}
onDragStart={(e) =>
dragStartHandler(e, task, column.id)
}
onDragEnd={(e) => dragEndHandler(e)}
onClick={(e) => openTicket(e, task)}
2023-05-05 00:50:48 +03:00
>
<div className="tasks__board__item__title">
<p>{task.title}</p>
2023-05-03 16:47:20 +03:00
</div>
2023-05-05 00:50:48 +03:00
<p className="tasks__board__item__description">
{task.description}
</p>
<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>
);
};