import React, { useEffect, useState } from "react"; import { Link, Navigate, useParams } from "react-router-dom"; import { apiRequest } from "@api/request"; import { getCorrectDate, getCreatedDate, hourOfNum } from "@components/Calendar/calendarHelper"; import { Footer } from "@components/Common/Footer/Footer"; import { Loader } from "@components/Common/Loader/Loader"; import { Navigation } from "@components/Navigation/Navigation"; import { ProfileBreadcrumbs } from "@components/ProfileBreadcrumbs/ProfileBreadcrumbs"; import { ProfileHeader } from "@components/ProfileHeader/ProfileHeader"; import arrowSwitchDate from "assets/icons/arrows/arrowViewReport.png"; import arrow from "assets/icons/arrows/left-arrow.png"; import "./viewReport.scss"; export const ViewReport = () => { const params = useParams(); const [previousReportDay] = useState(new Date(params.date)); const [nextReportDay] = useState(new Date(params.date)); const [taskText, setTaskText] = useState([]); const [difficulties, setDifficulties] = useState([]); const [tomorrowTask, setTomorrowTask] = useState([]); const [totalHours, setTotalHours] = useState(0); const [currentDay] = useState(new Date()); const [loader, setLoader] = useState(false); function getReportFromDate(day) { setLoader(true); setTaskText([]); setDifficulties([]); setTomorrowTask([]); apiRequest( `reports/find-by-date?user_id=${params.id}&date=${day}` ).then((res) => { let spendTime = 0; for (const item of res) { if (item.difficulties) { setDifficulties((prevArray) => [...prevArray, item.difficulties]); } if (item.tomorrow) { setTomorrowTask((prevArray) => [...prevArray, item.tomorrow]); } item.task.map((task) => { const taskInfo = { hours: task.hours_spent, task: task.task, id: task.id }; spendTime += Math.floor(task.hours_spent); setTaskText((prevArray) => [...prevArray, taskInfo]); }); } setTotalHours(Math.floor(spendTime)); setLoader(false); }); previousReportDay.setDate(previousReportDay.getDate() - 1); nextReportDay.setDate(nextReportDay.getDate() + 1); } function nextDay() { getReportFromDate(getCreatedDate(nextReportDay)); previousReportDay.setDate(previousReportDay.getDate() + 2); } function previousDay() { getReportFromDate(getCreatedDate(previousReportDay)); nextReportDay.setDate(nextReportDay.getDate() - 2); } useEffect(() => { getReportFromDate(params.date); }, []); return (
{localStorage.getItem("role_status") !== "18" && <>

Ваши отчеты - просмотр отчета за день

} #

Вернуться

{/*

{getCorrectDate(dateReport.id)}

Вами потрачено на работу:{" "} {totalHours} {hourOfNum(totalHours)}

*/}
previousDay()}>
arrow

{getCorrectDate(params.date)}

nextDay()} className={`${ getCreatedDate(currentDay) === params.date ? "disable" : "" }`} >
arrow
{loader && } {Boolean(taskText.length) && (
{taskText.length && taskText.map((task, index) => { return ( ); })}

Какие задачи выполнены?

Время

{index + 1}. {task.task}

{Math.floor(task.hours)}

{hourOfNum(Math.floor(task.hours))}

Всего: {totalHours} {hourOfNum(totalHours)}
{Boolean(difficulties.length) && (

Какие сложности возникли?

{difficulties.map((item, index) => { return

{item}

; })}
)} {Boolean(tomorrowTask.length) && (

Что планируется сделать завтра?

{tomorrowTask.map((item, index) => { return

{item}

; })}
)}
)} {!Boolean(taskText.length) && !loader && (
{localStorage.getItem("role_status") === "4" ?

В этот день вы не заполняли отчет

:

Отчет за день не заполнен

}
)}
); };