import React, {useEffect, useState} from 'react' import {Link} from "react-router-dom"; import {useRequest} from "../../hooks/useRequest"; import {ProfileHeader} from "../../components/ProfileHeader/ProfileHeader"; import {Footer} from "../../components/Footer/Footer"; import arrow from "../../images/right-arrow.png"; import arrowSwitchDate from "../../images/arrowViewReport.svg"; import './viewReport.scss' const getCreatedDate = () => { const date = new Date(); const dd = String(date.getDate()).padStart(2, '0'); const mm = String(date.getMonth() + 1).padStart(2, '0'); const yyyy = date.getFullYear(); return `${yyyy}-${mm}-${dd}` }; export const ViewReport = () => { const {apiRequest} = useRequest(); const [taskText, setTaskText] = useState([]); const [difficulties, setDifficulties] = useState([]) const [tomorrowTask, setTomorrowTask] = useState([]) const [totalHours, setTotalHours] = useState(0); useEffect(() => { setTaskText([]) setDifficulties([]) setTomorrowTask([]) apiRequest(`reports/find-by-date?user_card_id=${localStorage.getItem('cardId')}&date=2023-01-22`) .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) }) }, []); return (

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

arrow

Вернуться

{getCreatedDate()}

Вами потрачено на работу : {totalHours} часов

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

122 часа из 160

*/}
arrow

{getCreatedDate()}

arrow
{taskText.length ?
{taskText.length && taskText.map((task) => { return })}

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

Время

{task.task}

{task.hours}

часа на задачу

Всего: {totalHours} часов

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

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

{item}

} )}

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

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

{item}

} )}
:

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

}
) };