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

Add exploration hook on profileType + remove unused imports

parent 43f0c089
No related branches found
No related tags found
1 merge request!257Features/us358 create profile exploration
import React, { useEffect, useState } from 'react' import React, { useEffect, useState } from 'react'
import 'components/ProfileType/profileTypeFinished.scss' import 'components/ProfileType/profileTypeFinished.scss'
import { useI18n } from 'cozy-ui/transpiled/react/I18n' import { useI18n } from 'cozy-ui/transpiled/react/I18n'
import { useDispatch } from 'react-redux' import { useDispatch, useSelector } from 'react-redux'
import { useHistory } from 'react-router-dom' import { useHistory } from 'react-router-dom'
import { updateProfile } from 'store/profile/profile.actions' import { updateProfile } from 'store/profile/profile.actions'
import { ProfileType } from 'models/profileType.model' import { ProfileType } from 'models/profileType.model'
...@@ -9,6 +9,9 @@ import MuiButton from '@material-ui/core/Button' ...@@ -9,6 +9,9 @@ import MuiButton from '@material-ui/core/Button'
import StyledIcon from 'components/CommonKit/Icon/StyledIcon' import StyledIcon from 'components/CommonKit/Icon/StyledIcon'
import finishIcon from 'assets/icons/visu/profileType/finish.svg' import finishIcon from 'assets/icons/visu/profileType/finish.svg'
import ProfileTypeService from 'services/profileType.service' import ProfileTypeService from 'services/profileType.service'
import useExploration from 'components/Hooks/useExploration'
import { AppStore } from 'store'
import { UserExplorationID } from 'enum/userExploration.enum'
interface ProfileTypeFinishedProps { interface ProfileTypeFinishedProps {
profileType: ProfileType profileType: ProfileType
...@@ -20,12 +23,15 @@ const ProfileTypeFinished: React.FC<ProfileTypeFinishedProps> = ({ ...@@ -20,12 +23,15 @@ const ProfileTypeFinished: React.FC<ProfileTypeFinishedProps> = ({
const { t } = useI18n() const { t } = useI18n()
const dispatch = useDispatch() const dispatch = useDispatch()
const history = useHistory() const history = useHistory()
const { currentChallenge } = useSelector(
(state: AppStore) => state.ecolyo.challenge
)
const handleClick = () => { const handleClick = () => {
history.push('/analysis') history.push('/analysis')
} }
const [isSaved, setIsSaved] = useState<boolean>(false) const [isSaved, setIsSaved] = useState<boolean>(false)
const [, setValidExploration] = useExploration()
useEffect(() => { useEffect(() => {
if (!isSaved) { if (!isSaved) {
...@@ -33,6 +39,12 @@ const ProfileTypeFinished: React.FC<ProfileTypeFinishedProps> = ({ ...@@ -33,6 +39,12 @@ const ProfileTypeFinished: React.FC<ProfileTypeFinishedProps> = ({
profileType profileType
) )
setIsSaved(true) setIsSaved(true)
if (
currentChallenge &&
currentChallenge.exploration.id === UserExplorationID.EXPLORATION007
) {
setValidExploration(currentChallenge.exploration.id)
}
dispatch( dispatch(
updateProfile({ updateProfile({
profileType: consistentProfileType, profileType: consistentProfileType,
...@@ -40,7 +52,7 @@ const ProfileTypeFinished: React.FC<ProfileTypeFinishedProps> = ({ ...@@ -40,7 +52,7 @@ const ProfileTypeFinished: React.FC<ProfileTypeFinishedProps> = ({
}) })
) )
} }
}, [dispatch, profileType, isSaved]) }, [dispatch, profileType, isSaved, currentChallenge, setValidExploration])
return ( return (
<div className={'profile-type-finished-card'}> <div className={'profile-type-finished-card'}>
......
...@@ -20,4 +20,5 @@ export enum UserExplorationID { ...@@ -20,4 +20,5 @@ export enum UserExplorationID {
EXPLORATION005 = 'EXPLORATION005', EXPLORATION005 = 'EXPLORATION005',
EXPLORATION006 = 'EXPLORATION006', EXPLORATION006 = 'EXPLORATION006',
EXPLORATION006_0 = 'EXPLORATION006_0', EXPLORATION006_0 = 'EXPLORATION006_0',
EXPLORATION007 = 'EXPLORATION007',
} }
...@@ -4,13 +4,10 @@ import { ...@@ -4,13 +4,10 @@ import {
} from 'enum/userChallenge.enum' } from 'enum/userChallenge.enum'
import { DateTime } from 'luxon' import { DateTime } from 'luxon'
import { import {
DuelEntity,
UserDuel, UserDuel,
UserDuelEntity, UserDuelEntity,
Dataload, Dataload,
QuizEntity,
UserQuiz, UserQuiz,
ExplorationEntity,
UserExploration, UserExploration,
Relation, Relation,
} from 'models' } from 'models'
......
...@@ -218,6 +218,7 @@ export default class ExplorationService { ...@@ -218,6 +218,7 @@ export default class ExplorationService {
case UserExplorationID.EXPLORATION004: case UserExplorationID.EXPLORATION004:
case UserExplorationID.EXPLORATION005: case UserExplorationID.EXPLORATION005:
case UserExplorationID.EXPLORATION006: case UserExplorationID.EXPLORATION006:
case UserExplorationID.EXPLORATION007:
// ACTION EXPLORATIONS // ACTION EXPLORATIONS
return challengeService.updateUserChallenge( return challengeService.updateUserChallenge(
currentChallenge, currentChallenge,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment