2022-12-26 15:12:01 +03:00
|
|
|
import React, { useEffect, useState } from 'react'
|
2023-01-16 21:11:46 +03:00
|
|
|
import {useDispatch, useSelector} from 'react-redux'
|
2023-01-16 19:57:55 +03:00
|
|
|
|
2023-01-24 19:11:24 +03:00
|
|
|
import {currentMonth, getReports} from '../Calendar/calendarHelper'
|
2022-12-26 15:12:01 +03:00
|
|
|
import { Link } from 'react-router-dom'
|
|
|
|
import moment from "moment";
|
2023-01-16 19:57:55 +03:00
|
|
|
|
2022-12-26 15:12:01 +03:00
|
|
|
import {ProfileCalendarComponent} from "./ProfileCalendarComponent";
|
2023-01-24 19:11:24 +03:00
|
|
|
import {Loader} from "../Loader/Loader";
|
2023-01-16 19:57:55 +03:00
|
|
|
import {ProfileHeader} from "../ProfileHeader/ProfileHeader";
|
2023-01-24 19:11:24 +03:00
|
|
|
import { Footer } from '../Footer/Footer'
|
2022-12-26 15:12:01 +03:00
|
|
|
|
2023-01-20 16:20:06 +03:00
|
|
|
import {urlForLocal} from "../../helper";
|
|
|
|
|
|
|
|
import {apiRequest} from "../../api/request";
|
2023-01-16 19:57:55 +03:00
|
|
|
import { getProfileInfo } from '../../redux/outstaffingSlice'
|
2023-02-09 20:46:02 +03:00
|
|
|
import {getRequestDates, setReportDate, setRequestDate} from "../../redux/reportSlice";
|
2023-01-16 19:57:55 +03:00
|
|
|
|
2023-02-09 20:46:02 +03:00
|
|
|
import 'moment/locale/ru'
|
2023-01-16 19:57:55 +03:00
|
|
|
import './profileCalendar.scss'
|
2023-01-16 21:11:46 +03:00
|
|
|
|
2023-01-20 16:20:06 +03:00
|
|
|
|
2022-12-26 15:12:01 +03:00
|
|
|
export const ProfileCalendar = () => {
|
2023-01-16 21:11:46 +03:00
|
|
|
const dispatch = useDispatch();
|
2023-02-09 20:46:02 +03:00
|
|
|
const profileInfo = useSelector(getProfileInfo)
|
|
|
|
const requestDates = useSelector(getRequestDates)
|
2023-01-16 15:24:08 +03:00
|
|
|
const [month, setMonth] = useState('');
|
2023-02-09 20:46:02 +03:00
|
|
|
const [value, setValue] = useState(moment())
|
2023-01-16 15:24:08 +03:00
|
|
|
const [reports, setReports] = useState([]);
|
|
|
|
const [totalHours, setTotalHours] = useState(0);
|
2023-02-09 20:46:02 +03:00
|
|
|
const [loader, setLoader] = useState(true)
|
2023-01-16 15:24:08 +03:00
|
|
|
|
2023-02-09 20:46:02 +03:00
|
|
|
function setValueHandler (value) {
|
|
|
|
setValue(value)
|
|
|
|
}
|
2022-12-26 15:12:01 +03:00
|
|
|
|
|
|
|
useEffect(() => {
|
2023-02-09 20:46:02 +03:00
|
|
|
dispatch(setRequestDate(getReports(moment())))
|
2023-01-20 16:20:06 +03:00
|
|
|
},[]);
|
2022-12-26 15:12:01 +03:00
|
|
|
|
2023-01-20 16:20:06 +03:00
|
|
|
useEffect( () => {
|
2023-01-24 19:11:24 +03:00
|
|
|
setLoader(true)
|
2022-12-26 15:12:01 +03:00
|
|
|
if (!requestDates) {
|
|
|
|
return
|
|
|
|
}
|
2023-01-23 14:59:57 +03:00
|
|
|
apiRequest(`/reports/reports-by-date?${requestDates}&user_card_id=${localStorage.getItem('cardId')}`)
|
2023-01-16 15:24:08 +03:00
|
|
|
.then((reports) => {
|
|
|
|
let spendTime = 0;
|
2023-01-23 14:59:57 +03:00
|
|
|
for (const report of reports) {
|
|
|
|
report.task.map((task) => {
|
|
|
|
if(task.hours_spent) {
|
|
|
|
spendTime += Number(task.hours_spent)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2023-01-16 15:24:08 +03:00
|
|
|
setTotalHours(spendTime);
|
|
|
|
setReports(reports)
|
2023-01-24 19:11:24 +03:00
|
|
|
setLoader(false)
|
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'>
|
2023-01-20 16:20:06 +03:00
|
|
|
<img src={urlForLocal(profileInfo.photo)} className='summary__avatar' alt='avatar'/>
|
2023-01-13 15:53:07 +03:00
|
|
|
<p className='summary__name'>{profileInfo.fio} {profileInfo.specification}</p>
|
2022-12-26 15:12:01 +03:00
|
|
|
</div>
|
2023-01-16 20:38:33 +03:00
|
|
|
<Link to='/report'>
|
2023-01-16 21:11:46 +03:00
|
|
|
<button className="calendar__btn" onClick={() => {
|
|
|
|
dispatch(setReportDate(''))
|
|
|
|
}}>Заполнить отчет за день</button>
|
2023-01-13 15:53:07 +03:00
|
|
|
</Link>
|
2022-12-26 15:12:01 +03:00
|
|
|
</div>
|
2023-01-24 19:11:24 +03:00
|
|
|
{loader ?
|
|
|
|
<Loader height={80} width={80} />
|
|
|
|
:
|
|
|
|
<div className='row'>
|
|
|
|
<div className='col-12 col-xl-12'>
|
2023-02-09 20:46:02 +03:00
|
|
|
<ProfileCalendarComponent setValueHandler={setValueHandler} value={value} reports={reports} />
|
2023-01-24 19:11:24 +03:00
|
|
|
<p className='calendar__hours'>
|
|
|
|
{month} : <span> {totalHours} часов </span>
|
|
|
|
</p>
|
|
|
|
</div>
|
2023-01-13 15:53:07 +03:00
|
|
|
</div>
|
2023-01-24 19:11:24 +03:00
|
|
|
}
|
2022-12-26 15:12:01 +03:00
|
|
|
</div>
|
|
|
|
<Footer />
|
2023-01-13 15:53:07 +03:00
|
|
|
</div>
|
2022-12-26 15:12:01 +03:00
|
|
|
)
|
|
|
|
};
|