2022-12-26 15:12:01 +03:00
|
|
|
import React, { useEffect, useState } from 'react'
|
|
|
|
import {useDispatch, useSelector} from 'react-redux'
|
|
|
|
import { getProfileInfo } from '../../redux/outstaffingSlice'
|
|
|
|
import { setReportDate } from '../../redux/reportSlice';
|
|
|
|
import arrow from "../../images/right-arrow.png";
|
|
|
|
import { Link } from 'react-router-dom'
|
|
|
|
import moment from "moment";
|
|
|
|
import rectangle from '../../images/rectangle_secondPage.png'
|
|
|
|
import {currentMonth, getReports} from '../Calendar/calendarHelper'
|
|
|
|
import {ProfileCalendarComponent} from "./ProfileCalendarComponent";
|
2023-01-13 15:53:07 +03:00
|
|
|
import { ProfileHeader } from "../Profile/ProfileHeader";
|
2022-12-26 15:12:01 +03:00
|
|
|
import { Footer } from '../Footer/Footer'
|
|
|
|
|
|
|
|
import './profileCalendar.scss'
|
2023-01-16 15:24:08 +03:00
|
|
|
import {useRequest} from "../../hooks/useRequest";
|
2022-12-26 15:12:01 +03:00
|
|
|
export const ProfileCalendar = () => {
|
|
|
|
const dispatch = useDispatch();
|
2023-01-16 15:24:08 +03:00
|
|
|
const profileInfo = useSelector(getProfileInfo);
|
|
|
|
const [month, setMonth] = useState('');
|
|
|
|
const [reports, setReports] = useState([]);
|
|
|
|
const [totalHours, setTotalHours] = useState(0);
|
|
|
|
const [requestDates, setRequestDates] = useState('');
|
|
|
|
|
|
|
|
const {apiRequest} = useRequest();
|
2022-12-26 15:12:01 +03:00
|
|
|
|
|
|
|
useEffect(() => {
|
2023-01-16 19:12:44 +03:00
|
|
|
setRequestDates(getReports(moment()))
|
2023-01-16 15:24:08 +03:00
|
|
|
});
|
2022-12-26 15:12:01 +03:00
|
|
|
|
|
|
|
useEffect(async () => {
|
|
|
|
if (!requestDates) {
|
|
|
|
return
|
|
|
|
}
|
2023-01-16 15:24:08 +03:00
|
|
|
apiRequest(`/reports/reports-by-date?${requestDates}&user_id=${localStorage.getItem('id')}`)
|
|
|
|
.then((reports) => {
|
|
|
|
let spendTime = 0;
|
|
|
|
reports.map((report) => {
|
|
|
|
if (report.spendTime) {
|
|
|
|
spendTime += Number(report.spendTime)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
setTotalHours(spendTime);
|
|
|
|
setReports(reports)
|
2022-12-26 15:12:01 +03:00
|
|
|
})
|
2023-01-16 15:24:08 +03:00
|
|
|
}, [requestDates]);
|
2022-12-26 15:12:01 +03:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setMonth(currentMonth)
|
2023-01-16 15:24:08 +03:00
|
|
|
}, [month]);
|
2022-12-26 15:12:01 +03:00
|
|
|
|
|
|
|
return (
|
2023-01-16 16:28:56 +03:00
|
|
|
<div className='profile__calendar'>
|
2023-01-13 15:53:07 +03:00
|
|
|
<ProfileHeader/>
|
|
|
|
<div className='container'>
|
|
|
|
<h2 className='summary__title'>Ваши отчеты</h2>
|
|
|
|
<div className='summary__info'>
|
|
|
|
<div className='summary__person'>
|
|
|
|
<img src={profileInfo.photo} className='summary__avatar' alt='avatar'/>
|
|
|
|
<p className='summary__name'>{profileInfo.fio} {profileInfo.specification}</p>
|
2022-12-26 15:12:01 +03:00
|
|
|
</div>
|
2023-01-13 15:53:07 +03:00
|
|
|
<Link to='/profile/report'>
|
|
|
|
<button className="calendar__btn">Заполнить отчет за день</button>
|
|
|
|
</Link>
|
2022-12-26 15:12:01 +03:00
|
|
|
</div>
|
2023-01-13 15:53:07 +03:00
|
|
|
<div className='row'>
|
|
|
|
<div className='col-12 col-xl-12'>
|
|
|
|
<ProfileCalendarComponent reportsDates={reports} />
|
|
|
|
<p className='calendar__hours'>
|
|
|
|
{month} : <span> {totalHours} часов </span>
|
|
|
|
</p>
|
|
|
|
</div>
|
2022-12-26 15:12:01 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<Footer />
|
2023-01-13 15:53:07 +03:00
|
|
|
</div>
|
2022-12-26 15:12:01 +03:00
|
|
|
)
|
|
|
|
};
|