Skip to content
Snippets Groups Projects
Commit cbc63d54 authored by Guilhem CARRON's avatar Guilhem CARRON
Browse files

Fix explanation modal overlap

parent 5e4a7d00
No related branches found
No related tags found
1 merge request!360Fix explanation modal overlap
import React, { Dispatch, SetStateAction, useEffect, useState } from 'react' import React, { Dispatch, SetStateAction, useCallback, useState } from 'react'
import './quizQuestion.scss' import './quizQuestion.scss'
import CloseIcon from 'assets/icons/ico/close.svg' import CloseIcon from 'assets/icons/ico/close.svg'
import StyledIconButton from 'components/CommonKit/IconButton/StyledIconButton' import StyledIconButton from 'components/CommonKit/IconButton/StyledIconButton'
...@@ -34,7 +34,6 @@ const QuizQuestionContent: React.FC<QuizQuestionContent> = ({ ...@@ -34,7 +34,6 @@ const QuizQuestionContent: React.FC<QuizQuestionContent> = ({
const [questionIndex, setQuestionIndex] = useState<number>( const [questionIndex, setQuestionIndex] = useState<number>(
questionIndexLocked questionIndexLocked
) )
const [enableNextQuest, setEnableNextQuest] = useState<boolean>(false)
const client: Client = useClient() const client: Client = useClient()
const dispatch = useDispatch() const dispatch = useDispatch()
...@@ -67,23 +66,24 @@ const QuizQuestionContent: React.FC<QuizQuestionContent> = ({ ...@@ -67,23 +66,24 @@ const QuizQuestionContent: React.FC<QuizQuestionContent> = ({
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => { const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setUserChoice(e.target.value) setUserChoice(e.target.value)
} }
const goNextQuestion = useCallback(() => {
const goNextQuestion = async () => { setUserChoice('')
setEnableNextQuest(true)
setOpenModal(false) setOpenModal(false)
if (questionIndex === userChallenge.quiz.questions.length - 1) { if (questionIndex === userChallenge.quiz.questions.length - 1) {
setIsCustomQuest(true) setIsCustomQuest(true)
} }
} if (questionIndex !== userChallenge.quiz.questions.length - 1) {
useEffect(() => { setQuestionIndex(questionIndex + 1)
if (enableNextQuest) {
if (questionIndex !== userChallenge.quiz.questions.length - 1) {
setQuestionIndex(questionIndex + 1)
}
setEnableNextQuest(false)
setUserChoice('')
} }
}, [enableNextQuest, questionIndex, userChallenge, userChoice]) }, [
questionIndex,
setIsCustomQuest,
setQuestionIndex,
setUserChoice,
setOpenModal,
userChallenge.quiz.questions.length,
])
return ( return (
<div className="quiz-container"> <div className="quiz-container">
<div className="question-container"> <div className="question-container">
...@@ -127,13 +127,15 @@ const QuizQuestionContent: React.FC<QuizQuestionContent> = ({ ...@@ -127,13 +127,15 @@ const QuizQuestionContent: React.FC<QuizQuestionContent> = ({
{t('quiz.button_validate')} {t('quiz.button_validate')}
</Button> </Button>
)} )}
<QuizExplanationModal {openModal && (
open={openModal} <QuizExplanationModal
answerIndex={answerIndex} open={openModal}
question={userChallenge.quiz.questions[questionIndex]} answerIndex={answerIndex}
goNext={goNextQuestion} question={userChallenge.quiz.questions[questionIndex]}
handleCloseClick={() => setOpenModal(false)} goNext={goNextQuestion}
/> handleCloseClick={() => setOpenModal(false)}
/>
)}
</div> </div>
) )
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment