This commit is contained in:
Николай Полтщук 2022-10-19 15:41:11 +03:00
parent 853f4d4e74
commit b4e5ca9140
3 changed files with 45 additions and 21962 deletions

21983
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -26,8 +26,9 @@ const ReportForm = () => {
const dispatch = useDispatch() const dispatch = useDispatch()
const history = useHistory() const history = useHistory()
const role = useSelector(getRole) const role = useSelector(getRole)
const [isFetching, setIsFetching] = useState(false) const [isFetching, setIsFetching] = useState(false)
const [reportSuccess, setReportSuccess] = useState(false)
const [inputs, setInputs] = useState([ { task: '', hours_spent: '', minutes_spent: 0 } ]); const [inputs, setInputs] = useState([ { task: '', hours_spent: '', minutes_spent: 0 } ]);
const [troublesInputValue, setTroublesInputValue] = useState(''); const [troublesInputValue, setTroublesInputValue] = useState('');
@ -37,8 +38,10 @@ const ReportForm = () => {
setInputs((prev) => [...prev, { task: '', hours_spent: '', minutes_spent: 0 }]) setInputs((prev) => [...prev, { task: '', hours_spent: '', minutes_spent: 0 }])
} }
const totalHours = inputs.reduce((a,b) => a + b.hours_spent, 0)
const deleteInput = (indexRemove) => { const deleteInput = (indexRemove) => {
if (indexRemove !== 1) { if (indexRemove !== 0) {
setInputs((prev) => prev.filter((el, index) => index !== indexRemove)) setInputs((prev) => prev.filter((el, index) => index !== indexRemove))
} }
} }
@ -152,6 +155,10 @@ const ReportForm = () => {
logout: () => dispatch(auth(false)) logout: () => dispatch(auth(false))
}).then((res) => }).then((res) =>
res.json().then((resJSON) => { res.json().then((resJSON) => {
if(res.status === 200) {
setReportSuccess(true)
setTimeout(()=> setReportSuccess(false),2000)
}
setInputs( () => [] ) setInputs( () => [] )
setTroublesInputValue(''); setTroublesInputValue('');
setScheduledInputValue(''); setScheduledInputValue('');
@ -163,8 +170,11 @@ const ReportForm = () => {
{isFetching ? <Loader /> : 'Отправить'} {isFetching ? <Loader /> : 'Отправить'}
</button> </button>
<p className='report-form__footer-text'> <p className='report-form__footer-text'>
Всего за день : <span>60 часов</span> Всего за день : <span>{totalHours} часов</span>
</p> </p>
{reportSuccess &&
<p className='report-form__footer-done'>Отчет отправлен</p>
}
</div> </div>
</div> </div>
</div> </div>

View File

@ -264,6 +264,14 @@
font-weight: 100; font-weight: 100;
} }
} }
&-done {
margin-bottom: 0;
font-size: 18px;
color: green;
font-weight: 500;
margin-left: 20px;
}
} }
&__form { &__form {