import React, {useState} from 'react' import {useSelector} from 'react-redux' import {Link} from 'react-router-dom' import {Loader} from '../Loader/Loader' import {currentMonthAndDay} from '../Calendar/calendarHelper' import {Footer} from "../Footer/Footer"; import {ProfileHeader} from "../ProfileHeader/ProfileHeader"; import {useRequest} from "../../hooks/useRequest"; import {getReportDate} from '../../redux/reportSlice' import calendarIcon from '../../images/calendar_icon.png' import ellipse from '../../images/ellipse.png' import remove from '../../images/remove.png' import addIcon from '../../images/addIcon.png' import arrow from "../../images/right-arrow.png"; import './reportForm.scss' const getCreatedDate = (day) => { if (day) { return `${new Date(day).getFullYear()}-${new Date(day).getMonth() + 1}-${new Date(day).getDate()}` } else { 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}` } }; const ReportForm = () => { const reportDate = useSelector(getReportDate); const {apiRequest} = useRequest(); const [isFetching, setIsFetching] = useState(false); const [reportSuccess, setReportSuccess] = useState(false); const [inputs, setInputs] = useState([{task: '', hours_spent: '', minutes_spent: 0}]); const [troublesInputValue, setTroublesInputValue] = useState(''); const [scheduledInputValue, setScheduledInputValue] = useState(''); const addInput = () => { setInputs((prev) => [...prev, {task: '', hours_spent: '', minutes_spent: 0}]) }; const totalHours = inputs.reduce((a, b) => a + b.hours_spent, 0); const deleteInput = (indexRemove) => { if (indexRemove !== 0) { setInputs((prev) => prev.filter((el, index) => index !== indexRemove)) } }; const handler = () => { apiRequest('/reports/create', { method: 'POST', body: { tasks: inputs, difficulties: troublesInputValue, tomorrow: scheduledInputValue, created_at: getCreatedDate(reportDate), status: 1, }, }).then((res) => { if (res.status === 200) { setReportSuccess(true); setTimeout(() => setReportSuccess(false), 2000) } setInputs(() => []); setTroublesInputValue(''); setScheduledInputValue(''); setIsFetching(false); setInputs(() => [{task: '', hours_spent: '', minutes_spent: 0}]); }) }; return (

Ваши отчеты - добавить отчет

Вернуться

Добавление отчета за день

Дата заполнения отчета:

{/*{currentMonthAndDayReportPage()}*/} {reportDate ? currentMonthAndDay(reportDate) : getCreatedDate()}
Какие задачи были выполнены?

Краткое описание задачи

Количество часов

{inputs.map((input, index) => { return (
{index + 1}.
setInputs(inputs.map((input, inputIndex) => { return index === inputIndex ? { ...input, task: e.target.value } : input }))}/>
setInputs(inputs.map((input, inputIndex) => { return index === inputIndex ? { ...input, hours_spent: Number(e.target.value) } : input }))}/>
deleteInput(index)} src={remove} alt=''/>
) })}
Добавить еще
Какие сложности возникли?
setTroublesInputValue(e.target.value)}/>
Что планируется сделать завтра?
setScheduledInputValue(e.target.value)}/>

Всего за день : {totalHours} часов

{reportSuccess &&

Отчет отправлен

}
) }; export default ReportForm