From 510258fef1fcba1579a5d7d88cea39b45be5613b Mon Sep 17 00:00:00 2001
From: Yoan VALLET <ext.sopra.yvallet@grandlyon.com>
Date: Thu, 4 Mar 2021 17:30:49 +0100
Subject: [PATCH] fix: state issue

---
 src/components/Action/ActionBegin.tsx              | 12 ++++++------
 src/components/Action/ActionChoose.tsx             |  6 ++----
 src/components/Action/ActionModal.tsx              |  3 +--
 src/components/Challenge/StarsContainer.tsx        |  2 +-
 src/components/Duel/DuelOngoing.tsx                |  4 ++--
 src/components/Exploration/ExplorationFinished.tsx |  4 ++--
 6 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/src/components/Action/ActionBegin.tsx b/src/components/Action/ActionBegin.tsx
index 1ba661ffb..3c528d2ae 100644
--- a/src/components/Action/ActionBegin.tsx
+++ b/src/components/Action/ActionBegin.tsx
@@ -44,10 +44,10 @@ const ActionBegin: React.FC<ActionBeginProps> = ({
 
   useEffect(() => {
     let subscribed = true
-    if (action) {
-      if (subscribed) setCurrentAction(action)
-    } else {
-      const getSingleAction = async () => {
+    const getAction = async () => {
+      if (action) {
+        if (subscribed) setCurrentAction(action)
+      } else {
         const actionService = new ActionService(client)
         let actions: Ecogesture[] = []
         if (isProfileTypeCompleted) {
@@ -59,12 +59,12 @@ const ActionBegin: React.FC<ActionBeginProps> = ({
           setCurrentAction(actions[0])
         }
       }
-      getSingleAction()
     }
+    getAction()
     return () => {
       subscribed = false
     }
-  }, [client, isProfileTypeCompleted, fluidTypes, action])
+  }, [client, isProfileTypeCompleted, fluidTypes, action, currentAction])
 
   useEffect(() => {
     if (currentAction) {
diff --git a/src/components/Action/ActionChoose.tsx b/src/components/Action/ActionChoose.tsx
index 0bac975a9..09f328f2f 100644
--- a/src/components/Action/ActionChoose.tsx
+++ b/src/components/Action/ActionChoose.tsx
@@ -14,11 +14,9 @@ const ActionChoose: React.FC<ActionChooseProps> = ({
 
   return (
     <div className="action-choose">
-      {!selectedAction && !showList ? (
-        <ActionBegin setShowList={setShowList} userChallenge={userChallenge} />
-      ) : selectedAction && !showList ? (
+      {!showList ? (
         <ActionBegin
-          action={selectedAction}
+          action={selectedAction ? selectedAction : undefined}
           setShowList={setShowList}
           userChallenge={userChallenge}
         />
diff --git a/src/components/Action/ActionModal.tsx b/src/components/Action/ActionModal.tsx
index f4dad1ff0..c90239f3c 100644
--- a/src/components/Action/ActionModal.tsx
+++ b/src/components/Action/ActionModal.tsx
@@ -36,8 +36,7 @@ const ActionModal: React.FC<ActionModalProps> = ({
       action
     )
     dispatch(updateUserChallengeList(updatedChallenge))
-    handleCloseClick()
-  }, [action, client, dispatch, userChallenge, handleCloseClick])
+  }, [action, client, dispatch, userChallenge])
 
   return (
     <Modal border={false} handleCloseClick={handleCloseClick}>
diff --git a/src/components/Challenge/StarsContainer.tsx b/src/components/Challenge/StarsContainer.tsx
index 9ec983f71..2559ff83a 100644
--- a/src/components/Challenge/StarsContainer.tsx
+++ b/src/components/Challenge/StarsContainer.tsx
@@ -13,6 +13,7 @@ const StarsContainer: React.FC<StarsContainerProps> = ({
   isQuizBegin,
 }: StarsContainerProps) => {
   const [elements] = useState<string[]>([])
+
   useEffect(() => {
     const renderStars = () => {
       //To be removed when action and explorations will be done
@@ -24,7 +25,6 @@ const StarsContainer: React.FC<StarsContainerProps> = ({
         else if (i >= result) elements.push(starIcon)
       }
     }
-
     renderStars()
   }, [result, elements])
 
diff --git a/src/components/Duel/DuelOngoing.tsx b/src/components/Duel/DuelOngoing.tsx
index aa4ad6841..d7f6d6f2a 100644
--- a/src/components/Duel/DuelOngoing.tsx
+++ b/src/components/Duel/DuelOngoing.tsx
@@ -9,7 +9,7 @@ import {
   unlockNextUserChallenge,
   updateUserChallengeList,
 } from 'store/challenge/challenge.actions'
-import { toogleChallengeNotification } from 'store/global/global.actions'
+import { toogleChallengeDuelNotification } from 'store/global/global.actions'
 import { formatNumberValues } from 'utils/utils'
 
 import { UserDuel, UserChallenge } from 'models'
@@ -61,7 +61,7 @@ const DuelOngoing: React.FC<DuelOngoingProps> = ({
     )
     dispatch(updateUserChallengeList(updatedChallenge))
     dispatch(unlockNextUserChallenge(updatedChallenge))
-    dispatch(toogleChallengeNotification(false))
+    dispatch(toogleChallengeDuelNotification(false))
     history.push('/challenges')
   }, [client, dispatch, userChallenge, history, winChallenge])
 
diff --git a/src/components/Exploration/ExplorationFinished.tsx b/src/components/Exploration/ExplorationFinished.tsx
index 5ca43d11b..5ce36eb3d 100644
--- a/src/components/Exploration/ExplorationFinished.tsx
+++ b/src/components/Exploration/ExplorationFinished.tsx
@@ -38,8 +38,8 @@ const ExplorationFinished: React.FC<ExplorationFinishedProps> = ({
     }
   }, [client, dispatch, userChallenge])
 
-  const goBack = useCallback(() => {
-    checkNotificationToEnd()
+  const goBack = useCallback(async () => {
+    await checkNotificationToEnd()
     history.goBack()
   }, [history, checkNotificationToEnd])
 
-- 
GitLab