import React, { useEffect, useRef, useState } from "react"; import { useDispatch, useSelector } from "react-redux"; import { Link, useParams } from "react-router-dom"; import { activeLoader, deletePersonOnProject, filterCreatedByMe, filteredExecutorTasks, filteredParticipateTasks, getBoarderLoader, getProjectBoard, modalToggle, movePositionProjectTask, moveProjectTask, setColumnId, setColumnName, setColumnPriority, setProjectBoardFetch, setToggleTab, } from "@redux/projectsTrackerSlice"; import { urlForLocal } from "@utils/helper"; import { caseOfNum } from "@utils/helper"; import { apiRequest } from "@api/request"; import BaseButton from "@components/Common/BaseButton/BaseButton"; import { Footer } from "@components/Common/Footer/Footer"; import { Loader } from "@components/Common/Loader/Loader"; import ModalTicket from "@components/Modal/Tracker/ModalTicket/ModalTicket"; import TrackerModal from "@components/Modal/Tracker/TrackerModal/TrackerModal"; 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 arrowDown from "assets/icons/arrows/selectArrow.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"; import trackerNoTasks from "assets/icons/trackerNoTasks.svg" export const ProjectTracker = () => { const dispatch = useDispatch(); const projectId = useParams(); const [openColumnSelect, setOpenColumnSelect] = useState({}); const [selectedTab, setSelectedTab] = useState(0); const [priorityTask, setPriorityTask] = useState(0); const [wrapperHover, setWrapperHover] = useState({}); const [taskHover, setTaskHover] = useState({}); const [modalAdd, setModalAdd] = useState(false); const [modalActiveTicket, setModalActiveTicket] = useState(false); const [selectedTicket, setSelectedTicket] = useState({}); const [personListOpen, setPersonListOpen] = useState(false); const [checkBoxParticipateTasks, setCheckBoxParticipateTasks] = useState(false); const [filteredNoTasks, setFilteredNoTasks] = useState(false) const [checkBoxMyTasks, setCheckBoxMyTasks] = useState(false); const [selectedExecutor, setSelectedExecutor] = useState(null); const [selectExecutorOpen, setSelectedExecutorOpen] = useState(false); const startWrapperIndexTest = useRef({}); const projectBoard = useSelector(getProjectBoard); const loader = useSelector(getBoarderLoader); useEffect(() => { dispatch(activeLoader()); dispatch(setProjectBoardFetch(projectId.id)); }, []); useEffect(() => { const tasksHover = {}; const columnHover = {}; let columnsTasksEmpty = true if (Object.keys(projectBoard).length) { projectBoard.columns.forEach((column) => { if (column.tasks.length) columnsTasksEmpty = false setOpenColumnSelect((prevState) => ({ ...prevState, [column.id]: false, })); columnHover[column.id] = false; column.tasks.forEach((task) => (tasksHover[task.id] = false)); }); } if (columnsTasksEmpty && (checkBoxMyTasks || selectedExecutor || checkBoxParticipateTasks)) { setFilteredNoTasks(true) } else { setFilteredNoTasks(false) } setWrapperHover(columnHover); setTaskHover(tasksHover); }, [projectBoard]); function dragStartHandler(e, task, columnId) { startWrapperIndexTest.current = { task: task, index: columnId }; } function dragOverTaskHandler(e, task) { e.preventDefault(); if (startWrapperIndexTest.current.task.id === task.id) { return; } setTaskHover((prevState) => ({ [prevState]: false, [task.id]: true })); } function dragLeaveTaskHandler() { setTaskHover((prevState) => ({ [prevState]: false })); } function dragEndTaskHandler() { setTaskHover((prevState) => ({ [prevState]: false })); setWrapperHover((prevState) => ({ [prevState]: false, })); } function dragDropTaskHandler(e, task, column) { e.preventDefault(); if (task.id === startWrapperIndexTest.current.task.id) { return; } const finishTask = column.tasks.indexOf(task); dispatch( movePositionProjectTask({ startTask: startWrapperIndexTest.current.task, finishTask: task, finishIndex: finishTask, }) ); } function dragOverHandler(e) { e.preventDefault(); } function dragEnterHandler(columnId) { if (columnId === startWrapperIndexTest.current.index) { return; } setWrapperHover((prevState) => ({ [prevState]: false, [columnId]: true, })); } function dragDropHandler(e, columnId) { e.preventDefault(); setWrapperHover((prevState) => ({ [prevState]: false, })); if ( startWrapperIndexTest.current.index === columnId || e.target.className.includes("__item") ) { return; } if (columnId !== startWrapperIndexTest.current.index) { dispatch( moveProjectTask({ startWrapperIndex: startWrapperIndexTest.current, columnId, }) ); } } function selectedTabTask(columnId, length) { setSelectedTab(columnId); dispatch(modalToggle("createTiketProject")); setModalAdd(true); setPriorityTask(length); } function openTicket(e, task) { setSelectedTicket(task); setModalActiveTicket(true); } function deleteColumn(column) { const priorityColumns = []; apiRequest("/project-column/update-column", { method: "PUT", data: { column_id: column.id, project_id: projectBoard.id, status: 0, }, }).then(() => { 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)); } }); } function deletePerson(userId) { apiRequest("/project/del-user", { method: "DELETE", data: { project_id: projectBoard.id, user_id: userId, }, }).then(() => { dispatch(deletePersonOnProject(userId)); }); } function filterParticipateTasks() { if (!checkBoxParticipateTasks) { dispatch(filteredParticipateTasks(Number(localStorage.getItem("id")))); } else { dispatch(setProjectBoardFetch(projectId.id)); setCheckBoxParticipateTasks(false); setCheckBoxMyTasks(false); setSelectedExecutor(null); } setCheckBoxParticipateTasks(!checkBoxParticipateTasks); } function filterMyTask() { if (!checkBoxMyTasks) { dispatch(filterCreatedByMe(Number(localStorage.getItem("id")))); } else { dispatch(setProjectBoardFetch(projectId.id)); setCheckBoxParticipateTasks(false); setCheckBoxMyTasks(false); setSelectedExecutor(null); } setCheckBoxMyTasks(!checkBoxMyTasks); } function executorFilter(user) { dispatch(filteredExecutorTasks(user.user_id)); setSelectedExecutor(user); } function deleteSelectedExecutorFilter() { setSelectedExecutor(null); setCheckBoxParticipateTasks(false); setCheckBoxMyTasks(false); dispatch(setProjectBoardFetch(projectId.id)); } return (

Управление проектами с трекером

dispatch(setToggleTab(1))} > img

Проекты

dispatch(setToggleTab(2))} > img

Все мои задачи

dispatch(setToggleTab(3))} > img

Архив

{loader && } {!loader && (
Проект : {projectBoard.name}
{ dispatch(modalToggle("createColumn")); setModalAdd(true); }} styles={"button-add-column"} > + {/* { dispatch(modalToggle("createColumn")); setModalAdd(true); }} > + */}

добавить колонку

{projectBoard.projectUsers?.length > 3 && ( +1... )}
{projectBoard.projectUsers?.length && projectBoard.projectUsers.slice(0, 3).map((person) => { return ( avatar ); })}
{ setPersonListOpen(true); }} > +

добавить участника

{personListOpen && (
close setPersonListOpen(false)} />
{projectBoard.projectUsers?.length} участник
В проекте -

“{projectBoard.name}”

{projectBoard.projectUsers?.map((person) => { return (
avatar {person.user.fio} delete deletePerson(person.user_id)} />
); })}
{ dispatch(modalToggle("addWorker")); setModalAdd(true); setPersonListOpen(false); }} > +

Добавить участников

)}
Участвую
{checkBoxParticipateTasks && ( accept )}
Мои
{checkBoxMyTasks && accept}
{selectedExecutor ? (

{selectedExecutor.user.fio}

avatar delete
) : (
setSelectedExecutorOpen(!selectExecutorOpen) } >

Выберите исполнитель

arrow {selectExecutorOpen && (
{projectBoard.projectUsers.map((user) => { return (
executorFilter(user)} >

{user.user?.fio}

avatar
); })}
)}
)}

Вернуться на проекты

arrow
{Boolean(modalActiveTicket) && ( )}
{Boolean(projectBoard?.columns) && !filteredNoTasks && Boolean(projectBoard.columns.length) && projectBoard.columns.map((column) => { return (
dragOverHandler(e)} onDragEnter={() => dragEnterHandler(column.id)} onDrop={(e) => dragDropHandler(e, column.id)} className={`tasks__board ${ wrapperHover[column.id] ? "tasks__board__hover" : "" }`} >
{column.title}
selectedTabTask( column.id, projectBoard?.columns ? projectBoard?.columns[0].tasks.at(-1) .priority + 1 : 1 ) } > + { setOpenColumnSelect((prevState) => ({ ...prevState, [column.id]: true, })); }} className="more" > ...
{openColumnSelect[column.id] && (
{ setOpenColumnSelect((prevState) => ({ ...prevState, [column.id]: false, })); dispatch(modalToggle("editColumn")); dispatch(setColumnName(column.title)); dispatch(setColumnId(column.id)); dispatch(setColumnPriority(column.priority)); setModalAdd(true); }} > edit Изменить
deleteColumn(column)} > delete Удалить
)} {column.tasks.map((task) => { return (
dragStartHandler(e, task, column.id) } onDragOver={(e) => dragOverTaskHandler(e, task)} onDragLeave={(e) => dragLeaveTaskHandler(e)} onDragEnd={() => dragEndTaskHandler()} onDrop={(e) => dragDropTaskHandler(e, task, column) } onClick={(e) => openTicket(e, task)} >

{task.title}

{task.executor?.fio ? task.executor?.fio : "Исполнитель не назначен"} {task.executor?.avatar && ( avatar )}
commentsImg {task.comment_count}{" "} {caseOfNum(task.comment_count, "comments")}
filesImg {task.files ? task.files : 0}{" "} {caseOfNum(0, "files")}
); })}
); })} {Boolean(projectBoard?.columns) && !Boolean(projectBoard.columns.length) && (
В проекте нет задач.
)} {filteredNoTasks &&
noTasks

Пока нет подходящих задач

Ставьте задачи, следите за прогрессом, ведите учёт рабочего времени

}
)}
); };