guild_front/src/pages/Tracker/Tracker.js

362 lines
13 KiB
JavaScript
Raw Normal View History

import React, { useEffect, useState } from "react";
2023-03-23 21:18:48 +03:00
import { useDispatch, useSelector } from "react-redux";
2023-05-25 16:42:37 +03:00
import {
setAllProjects,
getProjects,
setToggleTab,
getToggleTab,
modalToggle,
} from "../../redux/projectsTrackerSlice";
2023-03-23 21:18:48 +03:00
2023-05-25 16:42:37 +03:00
import { ProfileHeader } from "../../components/ProfileHeader/ProfileHeader";
import { ProfileBreadcrumbs } from "../../components/ProfileBreadcrumbs/ProfileBreadcrumbs";
import { Footer } from "../../components/Footer/Footer";
import { apiRequest } from "../../api/request";
import { Navigation } from "../../components/Navigation/Navigation";
2023-05-05 16:10:25 +03:00
import TrackerModal from "../../components/UI/TrackerModal/TrackerModal";
2023-04-14 15:52:21 +03:00
import ProjectTiket from "../../components/ProjectTiket/ProjectTiket";
import { urlForLocal } from "../../helper";
import { getCorrectDate } from "../../components/Calendar/calendarHelper";
2023-05-05 00:50:48 +03:00
import { Loader } from "../../components/Loader/Loader";
2023-03-08 11:36:34 +03:00
2023-05-25 16:42:37 +03:00
import project from "../../assets/icons/trackerProject.svg";
import tasks from "../../assets/icons/trackerTasks.svg";
import archive from "../../assets/icons/archiveTracker.svg";
import search from "../../assets/icons/serchIcon.png";
import noProjects from "../../assets/images/noProjects.png";
2023-03-03 18:49:02 +03:00
2023-04-27 14:51:01 +03:00
import "./tracker.scss";
2023-02-17 15:19:49 +03:00
export const Tracker = () => {
2023-04-28 14:56:59 +03:00
const dispatch = useDispatch();
2023-05-02 18:51:19 +03:00
const projects = useSelector(getProjects);
const tab = useSelector(getToggleTab);
const [allTasks, setAllTasks] = useState([]);
2023-05-02 19:41:51 +03:00
const [filteredAllTasks, setFilteredAllTasks] = useState([]);
const [loader, setLoader] = useState(false);
2023-05-08 00:41:39 +03:00
const [filterCompleteTasks, setFilterCompleteTasks] = useState([]);
2023-05-25 16:42:37 +03:00
const [allCompletedTasks, setAllCompletedTasks] = useState([]);
2023-03-30 15:07:05 +03:00
2023-03-22 21:48:06 +03:00
const [modalCreateProject, setModalCreateProject] = useState(false);
2023-04-27 14:51:01 +03:00
useEffect(() => {
setLoader(true);
apiRequest(
`/project/project-list?user_id=${localStorage.getItem(
"id"
)}&expand=columns`
).then((el) => {
dispatch(setAllProjects(el.projects));
setLoader(false);
2023-05-15 21:09:31 +03:00
// setAllCompletedTasks(el.projects.filter((project) => {
// if (project.status === 10 && project.columns.length) {
// return project
// }
// }).map((project) => { return project.columns}).reduce((acu, curr) => {
// curr.forEach((item) => {
// acu.push(...item.tasks)
// })
// return acu
// }, []))
});
apiRequest(
`/task/get-user-tasks?user_id=${localStorage.getItem("id")}`
).then((el) => {
2023-05-25 16:42:37 +03:00
const allTasks = el.filter((item) => item.status !== 0);
const completedTasks = el.filter((item) => item.status === 0);
2023-05-15 21:09:31 +03:00
setAllTasks(allTasks);
setFilteredAllTasks(allTasks);
2023-05-25 16:42:37 +03:00
setAllCompletedTasks(completedTasks);
setFilterCompleteTasks(completedTasks);
});
}, []);
2023-04-27 14:51:01 +03:00
2023-03-07 19:40:52 +03:00
const toggleTabs = (index) => {
dispatch(setToggleTab(index));
2023-03-07 19:40:52 +03:00
};
2023-03-10 01:20:15 +03:00
2023-05-02 19:41:51 +03:00
function filterAllTask(e) {
setFilteredAllTasks(
allTasks.filter((item) => {
if (!e.target.value) {
return item;
}
if (
item.title.toLowerCase().startsWith(e.target.value.toLowerCase()) ||
item.description
.toLowerCase()
.startsWith(e.target.value.toLowerCase())
) {
return item;
}
})
2023-05-02 19:41:51 +03:00
);
}
2023-03-13 23:33:12 +03:00
function filterArchiveTasks(e) {
2023-05-15 21:09:31 +03:00
setFilterCompleteTasks(
2023-05-25 16:42:37 +03:00
allCompletedTasks.filter((item) => {
2023-05-15 21:09:31 +03:00
if (!e.target.value) {
return item;
}
if (
item.title.toLowerCase().startsWith(e.target.value.toLowerCase()) ||
item.description
.toLowerCase()
.startsWith(e.target.value.toLowerCase())
) {
return item;
}
})
);
2023-03-22 21:48:06 +03:00
}
2023-03-07 19:40:52 +03:00
return (
<div className="tracker">
<ProfileHeader />
2023-04-19 20:22:06 +03:00
<Navigation />
2023-03-07 19:40:52 +03:00
<div className="container">
<div className="tracker__content">
2023-04-10 21:22:22 +03:00
<ProfileBreadcrumbs
links={[
{ name: "Главная", link: "/profile" },
{ name: "Трекер", link: "/profile/tracker" },
]}
2023-03-23 16:18:57 +03:00
/>
2023-03-30 15:07:05 +03:00
<h2 className="tracker__title">Управление проектами с трекером</h2>
</div>
</div>
<div className="tracker__tabs">
<div className="tracker__tabs__head">
<div
2023-05-02 18:51:19 +03:00
className={tab === 1 ? "tab active-tab" : "tab"}
2023-04-10 21:22:22 +03:00
onClick={() => toggleTabs(1)}
2023-03-30 15:07:05 +03:00
>
<img src={project} alt="img" />
<p>Проекты </p>
</div>
<div
2023-05-02 18:51:19 +03:00
className={tab === 2 ? "tab active-tab" : "tab"}
2023-04-10 21:22:22 +03:00
onClick={() => toggleTabs(2)}
2023-03-30 15:07:05 +03:00
>
<img src={tasks} alt="img" />
<p>Все мои задачи</p>
</div>
<div
2023-05-02 18:51:19 +03:00
className={tab === 3 ? "tab active-tab" : "tab"}
2023-04-10 21:22:22 +03:00
onClick={() => toggleTabs(3)}
2023-03-30 15:07:05 +03:00
>
<img src={archive} alt="img" />
<p>Архив</p>
</div>
</div>
<div className="tracker__tabs__content">
<div
2023-04-10 21:22:22 +03:00
className={
2023-05-02 18:51:19 +03:00
tab === 1
2023-04-10 21:22:22 +03:00
? "tracker__tabs__content__projects active__content tracker__tabs__content__wrapper"
: "tracker__tabs__content__projects tracker__tabs__content__wrapper"
}
2023-03-30 15:07:05 +03:00
>
2023-05-05 16:10:25 +03:00
<TrackerModal
2023-04-10 21:22:22 +03:00
active={modalCreateProject}
setActive={setModalCreateProject}
titleProject={"Укажите название проекта:"}
2023-05-05 16:10:25 +03:00
></TrackerModal>
2023-04-13 22:10:20 +03:00
{loader && <Loader style="green" />}
2023-05-05 00:50:48 +03:00
{Boolean(projects.length) &&
!loader &&
2023-03-30 15:07:05 +03:00
projects.map((project, index) => {
return project.status !== 10 ? (
<ProjectTiket key={index} project={project}></ProjectTiket>
) : (
""
2023-03-30 15:07:05 +03:00
);
})}
{(!Boolean(projects.length) ||
!Boolean(
projects.filter((project) => project.status !== 10).length
)) &&
!loader && (
<div className="no-projects">
<div className="no-projects__createNew">
<div>
<img src={noProjects} alt="noProjectImg" />
<p>Создайте свой первый проект</p>
</div>
<button
className="createProjectBtn"
onClick={() => {
dispatch(modalToggle("createProject"));
setModalCreateProject(true);
}}
>
<span>+</span>Создать проект
</button>
2023-03-30 15:07:05 +03:00
</div>
<p className="no-projects__info">
Ставьте задачи, следите за прогрессом, ведите учёт рабочего
времени
</p>
2023-03-30 15:07:05 +03:00
</div>
)}
2023-05-05 00:50:48 +03:00
{Boolean(projects.length) && !loader && (
2023-03-30 15:07:05 +03:00
<div className="create-newProject">
2023-04-10 21:22:22 +03:00
<button
className="createProjectBtn"
onClick={() => {
dispatch(modalToggle("createProject"));
setModalCreateProject(true);
}}
2023-04-10 21:22:22 +03:00
>
2023-03-07 19:40:52 +03:00
<span>+</span>Создать проект
</button>
2023-04-10 21:22:22 +03:00
<p>
Ставьте задачи, следите за прогрессом, ведите учёт рабочего
времени
</p>
2023-03-07 19:40:52 +03:00
</div>
2023-04-10 21:22:22 +03:00
)}
2023-03-30 15:07:05 +03:00
</div>
<div
2023-04-10 21:22:22 +03:00
className={
2023-05-02 18:51:19 +03:00
tab === 2
2023-04-10 21:22:22 +03:00
? "tracker__tabs__content__allTasks taskList tasks active__content"
: "tracker__tabs__content__projects"
}
2023-03-30 15:07:05 +03:00
>
<div className="taskList__head">
<h3>Список всех задач</h3>
<div className="taskList__head__search">
<img src={search} alt="search" />
<input
2023-04-10 21:22:22 +03:00
type="text"
placeholder="Найти задачу"
2023-05-02 19:41:51 +03:00
onChange={(event) => filterAllTask(event)}
2023-03-30 15:07:05 +03:00
/>
2023-03-07 19:40:52 +03:00
</div>
2023-03-30 15:07:05 +03:00
</div>
{loader && <Loader style="green" />}
{!loader && (
2023-05-05 00:50:48 +03:00
<div className="taskList__wrapper">
{Boolean(filteredAllTasks.length) &&
filteredAllTasks.map((task) => {
return (
<div className="task" key={task.id}>
<div className="task__info">
<h5>{task.title}</h5>
<p>{task.description}</p>
</div>
<div className="task__person">
<img
src={urlForLocal(task.user.avatar)}
alt="avatar"
/>
<div className="task__project">
<p>{task.user.fio}</p>
<span>{getCorrectDate(task.created_at)}</span>
</div>
2023-05-05 00:50:48 +03:00
</div>
2023-03-30 15:07:05 +03:00
</div>
);
})}
2023-05-05 00:50:48 +03:00
</div>
)}
2023-03-30 15:07:05 +03:00
</div>
<div
2023-04-10 21:22:22 +03:00
className={
2023-05-02 18:51:19 +03:00
tab === 3
2023-04-10 21:22:22 +03:00
? "tracker__tabs__content__archive active__content"
: "tracker__tabs__content__projects"
}
2023-03-30 15:07:05 +03:00
>
<div className="archive__tasks">
<div className="archive__title">
<h3>Архив задач:</h3>
<p>{filterCompleteTasks.length} задач(а)</p>
<div className="archive__tasks__search">
<img src={search} alt="search" />
<input
2023-04-10 21:22:22 +03:00
type="text"
placeholder="Найти задачу"
onChange={(event) => filterArchiveTasks(event)}
2023-03-30 15:07:05 +03:00
/>
2023-03-13 23:33:12 +03:00
</div>
2023-03-30 15:07:05 +03:00
</div>
<div className="archive__tasksWrapper">
2023-05-16 00:24:52 +03:00
{loader && <Loader style="green" />}
2023-05-25 16:42:37 +03:00
{!loader && (
<>
{Boolean(filterCompleteTasks.length) ? (
filterCompleteTasks.map((task, index) => {
return (
<div className="archive__completeTask" key={index}>
<div className="archive__completeTask__description">
<p>{task.title}</p>
<p className="date">{task.description}</p>
</div>
<div className="archive__completeTask__info">
<img
src={urlForLocal(task.user.avatar)}
alt="avatar"
/>
<div className="archive__completeTask__info__project">
{/*<span>Проект</span>*/}
<p>{getCorrectDate(task.updated_at)}</p>
</div>
</div>
2023-03-30 15:07:05 +03:00
</div>
2023-05-25 16:42:37 +03:00
);
})
) : (
<div className="archive__noItem">
<p>В архиве задач нет</p>
2023-04-10 21:22:22 +03:00
</div>
2023-05-25 16:42:37 +03:00
)}
</>
2023-04-10 21:22:22 +03:00
)}
2023-03-30 15:07:05 +03:00
</div>
</div>
<div className="archive__projects">
<div className="archive__title">
<h3>Архив проектов:</h3>
2023-05-25 16:42:37 +03:00
<p>
{projects.filter((project) => project.status === 10).length}{" "}
проект(ов)
</p>
2023-03-30 15:07:05 +03:00
</div>
<div className="archive__tasksWrapper">
2023-05-25 16:42:37 +03:00
{Boolean(
projects.filter((project) => project.status === 10).length
) ? (
2023-05-08 00:41:39 +03:00
projects.map((project, index) => {
return project.status === 10 ? (
2023-04-10 21:22:22 +03:00
<div className="archive__completeTask" key={index}>
<div className="archive__completeTask__description">
<p>{project.name}</p>
<p className="date">{project.date}</p>
</div>
</div>
2023-05-25 16:42:37 +03:00
) : (
""
);
2023-04-10 21:22:22 +03:00
})
) : (
2023-03-30 15:07:05 +03:00
<div className="archive__noItem">
<p>В архиве проектов нет</p>
</div>
2023-04-10 21:22:22 +03:00
)}
2023-03-13 23:33:12 +03:00
</div>
2023-03-03 18:49:02 +03:00
</div>
2023-03-07 19:40:52 +03:00
</div>
2023-02-17 15:19:49 +03:00
</div>
2023-03-07 19:40:52 +03:00
</div>
<Footer />
</div>
);
2023-02-17 15:19:49 +03:00
};