import React, { useEffect, useState } from "react"; import { useDispatch, useSelector } from "react-redux"; import { getProjects, getToggleTab, modalToggle, setAllProjects, setToggleTab, } from "@redux/projectsTrackerSlice"; import { urlForLocal } from "@utils/helper"; import { apiRequest } from "@api/request"; import { getCorrectDate } from "@components/Calendar/calendarHelper"; import BaseButton from "@components/Common/BaseButton/BaseButton"; import { Footer } from "@components/Common/Footer/Footer"; import { Loader } from "@components/Common/Loader/Loader"; 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 ProjectTiket from "@components/ProjectTiket/ProjectTiket"; import archive from "assets/images/archiveIcon.png"; import search from "assets/icons/serchIcon.png"; import project from "assets/icons/trackerProject.svg"; import tasks from "assets/icons/trackerTasks.svg"; import avatarMok from "assets/images/avatarMok.png"; import noProjects from "assets/images/noProjects.png"; import "./tracker.scss"; export const Tracker = () => { const dispatch = useDispatch(); const projects = useSelector(getProjects); const tab = useSelector(getToggleTab); const [allTasks, setAllTasks] = useState([]); const [filteredAllTasks, setFilteredAllTasks] = useState([]); const [loader, setLoader] = useState(false); const [filterCompleteTasks, setFilterCompleteTasks] = useState([]); const [allCompletedTasks, setAllCompletedTasks] = useState([]); const [modalCreateProject, setModalCreateProject] = useState(false); useEffect(() => { setLoader(true); apiRequest( `/project/project-list?user_id=${localStorage.getItem( "id" )}&expand=columns` ).then((el) => { dispatch(setAllProjects(el.projects)); setLoader(false); // 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) => { const allTasks = el.filter((item) => item.status !== 0); const completedTasks = el.filter((item) => item.status === 0); setAllTasks(allTasks); setFilteredAllTasks(allTasks); setAllCompletedTasks(completedTasks); setFilterCompleteTasks(completedTasks); }); }, []); const toggleTabs = (index) => { dispatch(setToggleTab(index)); }; 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; } }) ); } function filterArchiveTasks(e) { setFilterCompleteTasks( allCompletedTasks.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; } }) ); } return (

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

toggleTabs(1)} > img

Проекты

toggleTabs(2)} > img

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

toggleTabs(3)} > img

Архив

{loader && } {Boolean(projects.length) && !loader && projects.map((project, index) => { return project.status !== 10 ? ( ) : ( "" ); })} {(!Boolean(projects.length) || !Boolean( projects.filter((project) => project.status !== 10).length )) && !loader && (
noProjectImg

Создайте свой первый проект

{ dispatch(modalToggle("createProject")); setModalCreateProject(true); }} > +Создать проект

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

)} {Boolean(projects.length) && !loader && (
{ dispatch(modalToggle("createProject")); setModalCreateProject(true); }} > +Создать проект

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

)}

Список всех задач

search filterAllTask(event)} />
{loader && } {!loader && (
{Boolean(filteredAllTasks.length) && filteredAllTasks.map((task) => { return (
{task.title}

avatar

{task.user.fio}

{getCorrectDate(task.created_at)}
); })}
)}

Архив задач:

{filterCompleteTasks.length} задач(а)

search filterArchiveTasks(event)} />
{loader && } {!loader && ( <> {Boolean(filterCompleteTasks.length) ? ( filterCompleteTasks.map((task, index) => { return (

{task.title}

avatar
{/*Проект*/}

{getCorrectDate(task.updated_at)}

); }) ) : (

В архиве задач нет

)} )}

Архив проектов:

{projects.filter((project) => project.status === 10).length}{" "} проект(ов)

{Boolean( projects.filter((project) => project.status === 10).length ) ? ( projects.map((project, index) => { return project.status === 10 ? (

{project.name}

{project.date}

) : ( "" ); }) ) : (

В архиве проектов нет

)}
); };