Merge pull request #37 from apuc/quiz-error-msg

Quiz error msg
This commit is contained in:
kavalar 2022-10-20 13:02:23 +03:00 committed by GitHub
commit 1651968337
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 106 additions and 22011 deletions

21983
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -28,6 +28,7 @@ const ReportForm = () => {
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 {

View File

@ -26,6 +26,8 @@ export const HeaderQuiz = ({header}) => {
}, [dispatch]) }, [dispatch])
return ( return (
<div>
{ userInfo?.status === 500 ? <div className="error-msg">{userInfo.message}</div> :
<div className="header-quiz"> <div className="header-quiz">
<div className="header-quiz__container"> <div className="header-quiz__container">
{!userInfo ? <h2>Loading...</h2> : {!userInfo ? <h2>Loading...</h2> :
@ -42,5 +44,7 @@ export const HeaderQuiz = ({header}) => {
} }
</div> </div>
</div> </div>
}
</div>
) )
} }

View File

@ -72,6 +72,14 @@ $maxWidthContainer: 1123;
line-height: math.div(30, 25); line-height: math.div(30, 25);
} }
//============================================= //=============================================
.error-msg {
text-align: center;
font-size: 25px;
color: red;
font-weight: 500;
}
.header-quiz{ .header-quiz{
@include adaptiv-value("padding-top", 48, 30, 1); @include adaptiv-value("padding-top", 48, 30, 1);
@include adaptiv-value("padding-bottom", 85, 30, 1); @include adaptiv-value("padding-bottom", 85, 30, 1);