From 88e3cb7c194ea5a968993f04db332f43df363fbf Mon Sep 17 00:00:00 2001
From: Pierre Ecarlat <pecarlat@grandlyon.com>
Date: Tue, 10 Dec 2024 15:37:01 +0000
Subject: [PATCH] fix: Attempt improvement exploration challenge

---
 .../ChallengeCardOnGoing.tsx                  | 24 ++++++++++++-------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/components/Challenge/ChallengeCardOnGoing/ChallengeCardOnGoing.tsx b/src/components/Challenge/ChallengeCardOnGoing/ChallengeCardOnGoing.tsx
index aea83c8f9..db6690f7c 100644
--- a/src/components/Challenge/ChallengeCardOnGoing/ChallengeCardOnGoing.tsx
+++ b/src/components/Challenge/ChallengeCardOnGoing/ChallengeCardOnGoing.tsx
@@ -86,17 +86,15 @@ const ChallengeCardOnGoing = ({
       )
       dispatch(updateUserChallengeList(updatedChallenge))
     }
-    if (userChallenge.progress.quizProgress !== 5) navigate('/challenges/quiz')
+    if (!quizFinished) navigate('/challenges/quiz')
   }
 
   const goExploration = () => {
-    if (userChallenge.progress.explorationProgress !== 5)
-      navigate('/challenges/exploration')
+    if (!explorationFinished) navigate('/challenges/exploration')
   }
 
   const goAction = () => {
-    if (userChallenge.progress.actionProgress !== 5)
-      navigate('/challenges/action')
+    if (!actionFinished) navigate('/challenges/action')
   }
 
   useEffect(() => {
@@ -124,9 +122,9 @@ const ChallengeCardOnGoing = ({
     const unlockDuel = async () => {
       if (
         userChallenge.duel.state === UserDuelState.LOCKED &&
-        userChallenge.progress.actionProgress === 5 &&
-        userChallenge.progress.quizProgress === 5 &&
-        userChallenge.progress.explorationProgress === 5
+        quizFinished &&
+        explorationFinished &&
+        actionFinished
       ) {
         const updatedChallenge = await challengeService.updateUserChallenge(
           {
@@ -147,7 +145,15 @@ const ChallengeCardOnGoing = ({
     return () => {
       subscribed = false
     }
-  }, [currentDataload, userChallenge, dispatch, challengeService])
+  }, [
+    currentDataload,
+    userChallenge,
+    dispatch,
+    challengeService,
+    quizFinished,
+    explorationFinished,
+    actionFinished,
+  ])
 
   const quizButton = () => (
     <Button
-- 
GitLab