guild_front/src/pages/ViewReport/ViewReport.js

176 lines
8.2 KiB
JavaScript
Raw Normal View History

2023-01-23 14:59:57 +03:00
import React, {useEffect, useState} from 'react'
2023-02-27 16:50:32 +03:00
import {Link, Navigate} from "react-router-dom";
2023-01-23 23:51:18 +03:00
import {useSelector} from "react-redux";
import {getReportDate} from "../../redux/reportSlice";
2023-01-23 14:59:57 +03:00
2023-01-24 19:11:24 +03:00
import {Loader} from "../../components/Loader/Loader"
2023-01-23 14:59:57 +03:00
import {ProfileHeader} from "../../components/ProfileHeader/ProfileHeader";
2023-02-27 16:50:32 +03:00
import {ProfileBreadcrumbs} from "../../components/ProfileBreadcrumbs/ProfileBreadcrumbs"
2023-01-23 14:59:57 +03:00
import {Footer} from "../../components/Footer/Footer";
2023-02-17 15:19:49 +03:00
import {apiRequest} from "../../api/request";
2023-03-01 00:28:58 +03:00
import {getCorrectDate, getCreatedDate, hourOfNum} from '../../components/Calendar/calendarHelper'
2023-01-23 14:59:57 +03:00
2023-04-18 13:58:36 +03:00
import arrow from "../../images/right-arrow.png";
import arrowSwitchDate from "../../images/arrowViewReport.png";
2023-01-23 14:59:57 +03:00
import './viewReport.scss'
2023-04-19 20:22:06 +03:00
import { Navigation } from '../../components/Navigation/Navigation';
2023-01-23 14:59:57 +03:00
export const ViewReport = () => {
2023-02-27 16:50:32 +03:00
if(localStorage.getItem('role_status') === '18') {
return <Navigate to="/profile" replace/>
}
2023-01-23 23:51:18 +03:00
const reportDate = useSelector(getReportDate);
2023-01-23 14:59:57 +03:00
const [taskText, setTaskText] = useState([]);
const [difficulties, setDifficulties] = useState([]);
const [tomorrowTask, setTomorrowTask] = useState([]);
2023-01-23 14:59:57 +03:00
const [totalHours, setTotalHours] = useState(0);
const [reportDay] = useState(new Date (getCreatedDate(reportDate)));
const [currentDay] = useState(new Date ());
const [loader, setLoader] = useState(false);
2023-01-23 23:51:18 +03:00
function getReportFromDate(day) {
setLoader(true);
setTaskText([]);
setDifficulties([]);
setTomorrowTask([]);
2023-01-23 23:51:18 +03:00
apiRequest(`reports/find-by-date?user_card_id=${localStorage.getItem('cardId')}&date=${day}`)
2023-01-23 14:59:57 +03:00
.then(res => {
let spendTime = 0;
2023-01-23 14:59:57 +03:00
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
};
2023-01-23 14:59:57 +03:00
if(task.hours_spent) {
spendTime += Number(task.hours_spent)
}
setTaskText(prevArray => [...prevArray, taskInfo])
})
}
setTotalHours(spendTime);
2023-01-24 19:11:24 +03:00
setLoader(false)
2023-01-23 14:59:57 +03:00
})
2023-01-23 23:51:18 +03:00
}
function nextDay() {
reportDay.setDate(reportDay.getDate() + 1);
getReportFromDate(getCreatedDate(reportDay))
}
function previousDay() {
reportDay.setDate(reportDay.getDate() - 1);
getReportFromDate(getCreatedDate(reportDay))
}
useEffect(() => {
getReportFromDate(getCreatedDate(reportDate))
2023-01-23 14:59:57 +03:00
}, []);
return (
<div className='viewReport'>
<ProfileHeader/>
2023-04-19 20:22:06 +03:00
<Navigation />
2023-01-23 14:59:57 +03:00
<div className='container'>
<div className='viewReport__info'>
2023-02-27 16:50:32 +03:00
<ProfileBreadcrumbs links={[{name: 'Главная', link: '/profile'},
{name: 'Ваша отчетность', link: '/profile/calendar'},
{name: 'Просмотр отчета за день', link: '/profile/view'}]}
/>
2023-01-23 14:59:57 +03:00
<h2 className='viewReport__title'>Ваши отчеты - <span>просмотр отчета за день</span></h2>
<Link className='viewReport__back' to={`/profile/calendar`}>
<img src={arrow} alt='arrow'/><p>Вернуться</p>
</Link>
<div className='viewReport__bar'>
2023-02-17 15:19:49 +03:00
<h3 className='viewReport__bar__date'>{getCorrectDate(reportDay)}</h3>
2023-03-01 00:28:58 +03:00
<p className='viewReport__bar__hours'>Вами потрачено на работу : <span>{totalHours} {hourOfNum(totalHours)}</span></p>
2023-01-23 14:59:57 +03:00
{/*<div className='viewReport__bar__progressBar'>*/}
{/* <span></span>*/}
{/*</div>*/}
{/*<p className='viewReport__bar__total'>122 часа из 160</p>*/}
</div>
</div>
<div className='viewReport__switchDate'>
2023-01-23 23:51:18 +03:00
<div className='viewReport__switchDate__prev switchDate' onClick={() => previousDay()}>
2023-01-24 19:22:16 +03:00
<img src={arrowSwitchDate} alt='arrow'/>
2023-01-23 14:59:57 +03:00
</div>
2023-02-17 15:19:49 +03:00
<p>{getCorrectDate(reportDay)}</p>
2023-01-24 00:08:42 +03:00
<div className={`viewReport__switchDate__next switchDate ${getCreatedDate(currentDay) === getCreatedDate(reportDay) ? 'disable' : ''}`} onClick={() => nextDay()}>
2023-01-24 19:22:16 +03:00
<img src={arrowSwitchDate} alt='arrow'/>
2023-01-23 14:59:57 +03:00
</div>
</div>
2023-01-24 19:11:24 +03:00
{loader &&
<Loader width={75} height={75}/>
}
{Boolean(taskText.length) &&
2023-01-23 14:59:57 +03:00
<div className='viewReport__content'>
<div className='table__container'>
<table className='viewReport__done'>
<thead>
<tr>
<th><p>Какие задачи были выполнены?</p></th>
<th><p>Время</p></th>
</tr>
</thead>
<tbody>
{taskText.length && taskText.map((task, index) => {
2023-01-23 14:59:57 +03:00
return <tr key={task.id}>
<td>
<p>{index + 1}. {task.task}</p>
2023-01-23 14:59:57 +03:00
</td>
<td>
<div className='viewReport__done__hours__item'>
<span>{task.hours}</span>
2023-03-01 00:28:58 +03:00
<p className='hours'>{hourOfNum(task.hours)} на задачу</p>
2023-01-23 14:59:57 +03:00
</div>
</td>
</tr>
})}
<tr>
<td></td>
2023-03-13 23:33:12 +03:00
<td><span>Всего: {totalHours} {hourOfNum(totalHours)}</span></td>
2023-01-23 14:59:57 +03:00
</tr>
</tbody>
</table>
</div>
2023-01-23 23:51:18 +03:00
{Boolean(difficulties.length) &&
<div className='viewReport__item'>
<h3>Какие сложности возникли?</h3>
{difficulties.map((item, index) => {
return <p key={index}>{item}</p>
}
)}
</div>
}
{Boolean(tomorrowTask.length) &&
<div className='viewReport__item'>
<h3>Что планируется сделать завтра?</h3>
{tomorrowTask.map((item, index) => {
return <p key={index}>{item}</p>
}
)}
</div>
}
2023-01-23 14:59:57 +03:00
</div>
2023-01-24 19:11:24 +03:00
}
{!Boolean(taskText.length) && !loader &&
2023-01-23 14:59:57 +03:00
<div className='viewReport__noTask'>
<p>В этот день вы <span>не заполняли</span> отчет</p>
</div>
}
<Footer />
</div>
</div>
)
};