import React, { useEffect, useState } from "react"; import { useDispatch, useSelector } from "react-redux"; import { setAllProjects, getProjects, setToggleTab, getToggleTab, modalToggle, } from "../../redux/projectsTrackerSlice"; 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"; import TrackerModal from "../../components/UI/TrackerModal/TrackerModal"; import ProjectTiket from "../../components/ProjectTiket/ProjectTiket"; import { urlForLocal } from "../../helper"; import { getCorrectDate } from "../../components/Calendar/calendarHelper"; import { Loader } from "../../components/Loader/Loader"; 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"; 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

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

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

)} {Boolean(projects.length) && !loader && (

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

)}

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

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

{task.description}

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}

{task.description}

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}

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

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

)}
); };