reports create, refactoring

This commit is contained in:
kurpfish
2021-11-30 16:00:58 +02:00
parent 76c46067ef
commit 4629bc74a9
61 changed files with 26047 additions and 3865 deletions

View File

@ -1,93 +1,175 @@
import React, { useState } from 'react';
import style from './ReportForm.module.css';
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 { currentMonthAndDayReportPage } from '../Calendar/calendarHelper';
import InputsComponent from '../InputsComponent/InputsComponent';
import React, { useState } from 'react'
import { useSelector, useDispatch } from 'react-redux'
import { fetchPost } from '../../server/server'
import { useHistory, useParams, Redirect } from 'react-router-dom'
import { Loader } from '../Loader/Loader'
import { auth } from '../../redux/outstaffingSlice'
import { getRole } from '../../redux/roleSlice'
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 { currentMonthAndDayReportPage } from '../Calendar/calendarHelper'
import './reportForm.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}`
}
const ReportForm = () => {
const [inputs, setInputs] = useState([1]);
const dispatch = useDispatch()
const history = useHistory()
const role = useSelector(getRole)
const [isFetching, setIsFetching] = useState(false)
const [inputs, setInputs] = useState([ { task: '', hours_spent: '', minutes_spent: 0 } ]);
const [troublesInputValue, setTroublesInputValue] = useState('');
const [scheduledInputValue, setScheduledInputValue] = useState('');
const addInput = () => {
const lastElement = inputs[inputs.length - 1];
setInputs((prev) => [...prev, { task: '', hours_spent: '', minutes_spent: 0 }])
}
setInputs((prev) => [...prev, lastElement + 1]);
};
const deleteInput = (id) => {
if (id !== 1) {
setInputs((prev) => prev.filter((el) => el !== id));
const deleteInput = (indexRemove) => {
if (indexRemove !== 1) {
setInputs((prev) => prev.filter((el, index) => index !== indexRemove))
}
};
}
return (
<section className="reportForm">
<div className="row">
<div className="col-xl-12">
<div className={style.reportForm__block}>
<div className={style.reportForm__blockTitle}>
<h2>Добавить отчет</h2>
<h3>Дата заполнения отчета:</h3>
</div>
<div className={style.reportForm__blockImg}>
<img className={style.calendarIcon} src={calendarIcon} alt="" />
{currentMonthAndDayReportPage()}
</div>
<div className={style.reportForm__tasks}>
<img src={ellipse} alt="" />
<span>Какие задачи были выполнены?</span>
</div>
<section className='report-form'>
<div className='row'>
<div className='col-xl-12'>
<div className='report-form__block'>
<div className='report-form__block-title'>
<h2>Добавить отчет</h2>
<h3>Дата заполнения отчета:</h3>
</div>
<div className='report-form__block-img'>
<img
className='report-form__calendar-icon'
src={calendarIcon}
alt=''
/>
{currentMonthAndDayReportPage()}
</div>
<div className='report-form__task-list'>
<img src={ellipse} alt='' />
<span>Какие задачи были выполнены?</span>
</div>
</div>
</div>
</div>
<div className="row">
<div className="col-8">
<div className={style.reportForm__text}>
<p className={style.text1}>Краткое описание задачи</p>
<p className={style.text2}>Количество часов</p>
</div>
<InputsComponent deleteInput={deleteInput} inputsArr={inputs} remove={remove} />
<div className={style.reportForm__formAdd}>
<img onClick={addInput} src={addIcon} alt="" />
<span>Добавить еще </span>
</div>
<div className='row'>
<div className='col-8'>
<div className='report-form__task-header'>
<p className='report-form__task-title--description'>
Краткое описание задачи
</p>
<p className='report-form__task-title--hours'>Количество часов</p>
</div>
<div className="col-4"></div>
</div>
<div className="row">
<div className="col-12">
<div className={style.reportForm__inptuBox}>
<div className={style.reportForm__tasks}>
<img src={ellipse} alt="" />
<span>Какие сложности возникли?</span>
</div>
<input type="text" />
<div className={style.reportForm__tasks}>
<img src={ellipse} alt="" />
<span>Что планируется сделать завтра?</span>
</div>
<input type="text" />
</div>
{inputs.map((input, index) => {
return (
<form id={'input'} key={`input__${index}`} className='report-form__task-form'>
<div className='report-form__task-number'>
{index+1}.
</div>
<div className='report-form__task-input report-form__task-input--description'>
<input name='text' type='text' onChange={ e => setInputs(inputs.map( (input, inputIndex) => {
return index === inputIndex
? {
...input,
task: e.target.value
}
: input
}))} />
</div>
<div className='report-form__task-input report-form__task-input--hours'>
<input name='number' type='number' min='1' onChange={ e => setInputs(inputs.map( (input, inputIndex) => {
return index === inputIndex
? {
...input,
hours_spent: Number(e.target.value)
}
: input
}))} />
</div>
<div className='report-form__task-remove'>
<img onClick={() => deleteInput(index)} src={remove} alt='' />
</div>
</form>
)
})}
<div className='report-form__form-add'>
<img onClick={addInput} src={addIcon} alt='' />
<span>Добавить еще </span>
</div>
</div>
<div className="row">
<div className="col-12">
<div className={style.reportForm__footer}>
<button className={style.reportForm__footer__btn} type="submit">
Отправить
</button>
<p className={style.reportForm__footer__text}>
Всего за день : <span>60 часов</span>
</p>
<div className='col-4'></div>
</div>
<div className='row'>
<div className='col-12'>
<div className='report-form__input-box'>
<div className='report-form__troubles'>
<img src={ellipse} alt='' />
<span>Какие сложности возникли?</span>
</div>
<input type='text' value={troublesInputValue} onChange={e => setTroublesInputValue(e.target.value)} />
<div className='report-form__scheduled'>
<img src={ellipse} alt='' />
<span>Что планируется сделать завтра?</span>
</div>
<input type='text' value={scheduledInputValue} onChange={e => setScheduledInputValue(e.target.value)} />
</div>
</div>
</div>
<div className='row'>
<div className='col-12'>
<div className='report-form__footer'>
<button className='report-form__footer-btn' onClick={() => {
fetchPost({
link: `${process.env.REACT_APP_API_URL}/api/reports/create`,
history,
role,
body: {
tasks: inputs,
difficulties: troublesInputValue,
tomorrow: scheduledInputValue,
created_at: getCreatedDate(),
status: 1,
},
logout: () => dispatch(auth(false))
}).then((res) =>
res.json().then((resJSON) => {
setInputs( () => [] )
setTroublesInputValue('');
setScheduledInputValue('');
setIsFetching(false)
setInputs(() => [ { task: '', hours_spent: '', minutes_spent: 0 } ]);
})
)
}}>
{isFetching ? <Loader /> : 'Отправить'}
</button>
<p className='report-form__footer-text'>
Всего за день : <span>60 часов</span>
</p>
</div>
</div>
</div>
</section>
);
};
)
}
export default ReportForm;
export default ReportForm

View File

@ -1,172 +0,0 @@
.reportForm__blockTitle {
margin-top: 76px;
}
.reportForm__blockTitle > h2 {
color: #282828;
font-family: 'GT Eesti Pro Display';
font-size: 3.3em;
font-weight: 700;
font-style: normal;
letter-spacing: normal;
line-height: 48.74px;
text-align: left;
}
.reportForm__blockTitle > h3 {
font-family: 'GT Eesti Pro Display';
font-size: 2.1em;
font-weight: 400;
font-style: normal;
letter-spacing: normal;
line-height: 30px;
text-align: left;
margin-top: 52px;
margin-bottom: 35px;
}
.reportForm__blockImg {
width: 280px;
height: 42px;
box-shadow: 0 0 59px rgba(44, 44, 44, 0.05);
border-radius: 5px;
border: 1px solid #398208;
background-color: #ffffff;
display: flex;
align-items: center;
font-family: 'GT Eesti Pro Display';
font-size: 13px;
font-weight: 700;
font-style: normal;
letter-spacing: normal;
line-height: normal;
text-align: left;
}
.reportForm__blockImg > img {
margin-left: 20px;
margin-right: 20px;
}
.reportForm__tasks {
margin-top: 40px;
display: flex;
align-items: center;
}
.reportForm__tasks > img {
width: 6px;
height: 6px;
margin-left: 12px;
margin-right: 12px;
}
.reportForm__tasks > span {
color: #18586e;
font-family: 'GT Eesti Pro Display';
font-size: 2em;
font-weight: 500;
font-style: normal;
letter-spacing: normal;
line-height: 16.81px;
text-align: left;
}
.reportForm__text {
display: flex;
justify-content: space-between;
margin-top: 40px;
}
.reportForm__text > p {
font-family: 'GT Eesti Pro Display';
font-size: 1.3em;
font-weight: 100;
font-style: normal;
letter-spacing: normal;
line-height: normal;
text-align: left;
margin-bottom: 26px;
}
.text1 {
margin-left: 20px;
}
.text2 {
margin-right: 86px;
}
.reportForm__formAdd {
margin-left: 28px;
}
.reportForm__formAdd > span {
font-family: 'GT Eesti Pro Display';
font-size: 1.3em;
font-weight: 100;
font-style: normal;
letter-spacing: normal;
line-height: normal;
text-align: left;
margin-left: 20px;
}
.reportForm__inptuBox > input {
margin-left: 10px;
margin-top: 30px;
margin-bottom: 40px;
width: 460px;
height: 42px;
box-shadow: 0 0 59px rgba(44, 44, 44, 0.05);
border-radius: 5px;
border: 1px solid #c4c4c4;
background-color: #ffffff;
font-size: 1.8em;
padding-left: 20px;
padding-right: 20px;
outline: none;
}
.reportForm__footer {
display: flex;
align-items: center;
}
.reportForm__footer__btn {
width: 166px;
height: 62px;
box-shadow: 6px 5px 20px rgba(82, 151, 34, 0.21);
border-radius: 31px;
background-color: #ffffff;
background-image: linear-gradient(to top, #6aaf5c 0%, #52b709 100%),
linear-gradient(
36deg,
rgba(255, 255, 255, 0) 0%,
rgba(255, 255, 255, 0.16) 47%,
rgba(255, 255, 255, 0.17) 50%,
rgba(255, 255, 255, 0) 100%
);
color: #ffffff;
font-family: 'Muller';
font-size: 1.6em;
letter-spacing: normal;
text-align: center;
border: none;
}
.reportForm__footer__text {
font-family: 'GT Eesti Pro Display';
font-size: 1.9em;
font-weight: 600;
font-style: normal;
letter-spacing: normal;
line-height: 22.38px;
text-align: left;
margin-left: 40px;
margin-bottom: 0;
}
.reportForm__footer__text > span {
font-weight: 100;
}

View File

@ -0,0 +1,310 @@
.report-form {
&__block-title {
margin-top: 76px;
h2 {
color: #282828;
font-family: 'GT Eesti Pro Display';
font-size: 3.3em;
font-weight: 700;
font-style: normal;
letter-spacing: normal;
line-height: 48.74px;
text-align: left;
}
h3 {
font-family: 'GT Eesti Pro Display';
font-size: 2.1em;
font-weight: 400;
font-style: normal;
letter-spacing: normal;
line-height: 30px;
text-align: left;
margin-top: 52px;
margin-bottom: 35px;
}
}
&__block-img {
width: 280px;
height: 42px;
box-shadow: 0 0 59px rgba(44, 44, 44, 0.05);
border-radius: 5px;
border: 1px solid #398208;
background-color: #ffffff;
display: flex;
align-items: center;
font-family: 'GT Eesti Pro Display';
font-size: 13px;
font-weight: 700;
font-style: normal;
letter-spacing: normal;
line-height: normal;
text-align: left;
img {
margin-left: 20px;
margin-right: 20px;
}
}
&__task {
&-number {
height: 14px;
color: #282828;
font-family: "GT Eesti Pro Display";
font-size: 20px;
font-weight: 700;
font-style: normal;
letter-spacing: normal;
line-height: 48.74px;
width: 40px;
}
&-list {
margin-top: 40px;
display: flex;
align-items: center;
& > span {
color: #18586e;
font-family: 'GT Eesti Pro Display';
font-size: 2em;
font-weight: 500;
font-style: normal;
letter-spacing: normal;
line-height: 16.81px;
text-align: left;
}
img {
width: 6px;
height: 6px;
margin-left: 12px;
margin-right: 12px;
}
}
&-header {
display: flex;
justify-content: flex-start;
margin-top: 40px;
margin-left: 50px;
p {
font-family: 'GT Eesti Pro Display';
font-size: 1.3em;
font-weight: 100;
font-style: normal;
letter-spacing: normal;
line-height: normal;
text-align: left;
margin-bottom: 26px;
}
}
&-title {
&--description {
margin-left: 20px;
}
&--hours {
margin-left: 330px;
}
}
&-remove {
margin-left: 20px;
display: flex;
align-items: center;
}
&-form {
display: flex;
margin-left: 20px;
margin-bottom: 28px;
}
&-input {
display: flex;
flex-direction: column;
margin-left: 20px;
&--description {
input {
width: 460px;
height: 42px;
box-shadow: 0 0 59px rgba(44, 44, 44, 0.05);
border-radius: 5px;
border: 1px solid #c4c4c4;
background-color: #ffffff;
outline: none;
font-size: 1.8em;
padding-left: 20px;
padding-right: 20px;
}
}
&--hours {
input {
width: 141px;
height: 42px;
box-shadow: 0 0 59px rgba(44, 44, 44, 0.05);
border-radius: 5px;
border: 1px solid #c4c4c4;
background-color: #ffffff;
outline: none;
font-size: 1.8em;
text-align: center;
}
}
}
}
&__form-add {
margin-left: 28px;
span {
font-family: 'GT Eesti Pro Display';
font-size: 1.3em;
font-weight: 100;
font-style: normal;
letter-spacing: normal;
line-height: normal;
text-align: left;
margin-left: 20px;
}
}
&__input-box {
input {
margin-left: 10px;
margin-top: 30px;
margin-bottom: 20px;
width: 460px;
height: 42px;
box-shadow: 0 0 59px rgba(44, 44, 44, 0.05);
border-radius: 5px;
border: 1px solid #c4c4c4;
background-color: #ffffff;
font-size: 1.8em;
padding-left: 20px;
padding-right: 20px;
outline: none;
}
}
&__tasks,
&__troubles,
&__scheduled {
margin-top: 40px;
display: flex;
align-items: center;
span {
color: #18586e;
font-family: 'GT Eesti Pro Display';
font-size: 2em;
font-weight: 500;
font-style: normal;
letter-spacing: normal;
line-height: 16.81px;
text-align: left;
}
img {
width: 6px;
height: 6px;
margin-left: 12px;
margin-right: 12px;
}
}
&__footer {
display: flex;
align-items: center;
margin-top: 20px;
&-btn {
width: 166px;
height: 62px;
box-shadow: 6px 5px 20px rgba(82, 151, 34, 0.21);
border-radius: 31px;
background-color: #ffffff;
background-image: linear-gradient(to top, #6aaf5c 0%, #52b709 100%),
linear-gradient(
36deg,
rgba(255, 255, 255, 0) 0%,
rgba(255, 255, 255, 0.16) 47%,
rgba(255, 255, 255, 0.17) 50%,
rgba(255, 255, 255, 0) 100%
);
color: #ffffff;
font-family: 'Muller';
font-size: 1.6em;
letter-spacing: normal;
text-align: center;
border: none;
}
&-text {
font-family: 'GT Eesti Pro Display';
font-size: 1.9em;
font-weight: 600;
font-style: normal;
letter-spacing: normal;
line-height: 22.38px;
text-align: left;
margin-left: 40px;
margin-bottom: 0;
span {
font-weight: 100;
}
}
}
&__form {
position: relative;
display: flex;
justify-content: space-between;
margin-left: 14px;
margin-bottom: 28px;
span {
font-family: 'GT Eesti Pro Display';
font-size: 2em;
font-weight: 700;
font-style: normal;
letter-spacing: normal;
text-align: left;
position: absolute;
left: 0;
bottom: 7px;
}
img {
margin-top: 5px;
width: 23px;
height: 23px;
}
}
}
@media (max-width: 575.98px) {
.report-form {
&__task {
&-input {
&--description {
max-width: 460px;
}
&--hours {
max-width: 141px;
}
}
}
}
}