diff --git a/src/components/quiz.tsx b/src/components/quiz.tsx index acdc1ed..09e2390 100644 --- a/src/components/quiz.tsx +++ b/src/components/quiz.tsx @@ -52,39 +52,40 @@ export function Quiz() { const [currentIndex, setCurrentIndex] = React.useState(0); const currentQuestion = questions[currentIndex]; - const visitorIsRejected = questions.some((q) => q.response?.isRejection); + const isRejected = questions.some((q) => q.response?.isRejection); + const isAccepted = questions.every((q) => q.status === "complete"); function handleOptionClick(option: Option) { - setQuestions((prevQuestions) => { + setQuestions((prevQuestions) => // Update the current question with its response and "complete" status // and set the next question as "upcoming" - const updatedQuestions: QuizQuestion[] = prevQuestions.map((q, i) => { + prevQuestions.map((q, i) => { if (i === currentIndex) { return { ...q, response: option, status: "complete", }; - // Mark the next question as "current" only if it's not been completed - } else if (i === currentIndex + 1 && q.status !== "complete") { + } else if (i === currentIndex + 1 && q.status === "upcoming") { return { ...q, status: "current", }; } return q; - }); + }), + ); - return updatedQuestions; - }); - setCurrentIndex(currentIndex + 1); + if (currentIndex < questions.length - 1) { + setCurrentIndex(currentIndex + 1); + } } return (
- {visitorIsRejected ? ( + {isRejected ? (

You're not eligible for treatment

- ) : currentIndex === questions.length ? ( + ) : isAccepted ? (

You're eligible for treatment

) : currentQuestion ? (