import React, {useEffect, useState} from 'react' import {Link, Navigate} from "react-router-dom"; import {useSelector} from "react-redux"; import {getReportDate} from "../../redux/reportSlice"; import {Loader} from "../../components/Loader/Loader" import {ProfileHeader} from "../../components/ProfileHeader/ProfileHeader"; import {ProfileBreadcrumbs} from "../../components/ProfileBreadcrumbs/ProfileBreadcrumbs" import {Footer} from "../../components/Footer/Footer"; import {apiRequest} from "../../api/request"; import {getCorrectDate, getCreatedDate, hourOfNum} from '../../components/Calendar/calendarHelper' import arrow from "../../images/right-arrow.png"; import arrowSwitchDate from "../../images/arrowViewReport.png"; import './viewReport.scss' import { Navigation } from '../../components/Navigation/Navigation'; export const ViewReport = () => { if(localStorage.getItem('role_status') === '18') { return } const reportDate = useSelector(getReportDate); const [taskText, setTaskText] = useState([]); const [difficulties, setDifficulties] = useState([]); const [tomorrowTask, setTomorrowTask] = useState([]); const [totalHours, setTotalHours] = useState(0); const [reportDay] = useState(new Date (getCreatedDate(reportDate))); const [currentDay] = useState(new Date ()); const [loader, setLoader] = useState(false); function getReportFromDate(day) { setLoader(true); setTaskText([]); setDifficulties([]); setTomorrowTask([]); apiRequest(`reports/find-by-date?user_card_id=${localStorage.getItem('cardId')}&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 }; if(task.hours_spent) { spendTime += Number(task.hours_spent) } setTaskText(prevArray => [...prevArray, taskInfo]) }) } setTotalHours(spendTime); setLoader(false) }) } function nextDay() { reportDay.setDate(reportDay.getDate() + 1); getReportFromDate(getCreatedDate(reportDay)) } function previousDay() { reportDay.setDate(reportDay.getDate() - 1); getReportFromDate(getCreatedDate(reportDay)) } useEffect(() => { getReportFromDate(getCreatedDate(reportDate)) }, []); return (

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

arrow

Вернуться

{getCorrectDate(reportDay)}

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

{/*
*/} {/* */} {/*
*/} {/*

122 часа из 160

*/}
previousDay()}> arrow

{getCorrectDate(reportDay)}

nextDay()}> arrow
{loader && } {Boolean(taskText.length) &&
{taskText.length && taskText.map((task, index) => { return })}

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

Время

{index + 1}. {task.task}

{task.hours}

{hourOfNum(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 &&

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

}
) };