diff --git a/src/components/ContainerComponents/ViewContainer/FinishedChallengeDetailsViewContainer.tsx b/src/components/ContainerComponents/ViewContainer/FinishedChallengeDetailsViewContainer.tsx index 7f01171dd4d9cc477a0ee612e133e5939a90d017..d1fb4bfaf27eedfa34acad3a8c6aec18c84546fb 100644 --- a/src/components/ContainerComponents/ViewContainer/FinishedChallengeDetailsViewContainer.tsx +++ b/src/components/ContainerComponents/ViewContainer/FinishedChallengeDetailsViewContainer.tsx @@ -160,12 +160,14 @@ const FinishedChallengeDetailsViewContainer: React.FC<FinishedChallengeDetailsVi </div> </div> </div> - <EcogestureModal - opened={openEcogestureModal} - ecogesture={challenge.selectedEcogestures[challengeEcogesture]} - handleCloseClick={handleCloseClick} - unlockedEcogesture={true} - /> + {openEcogestureModal && ( + <EcogestureModal + opened={openEcogestureModal} + ecogesture={challenge.selectedEcogestures[challengeEcogesture]} + handleCloseClick={handleCloseClick} + unlockedEcogesture={true} + /> + )} </> )} </Content> diff --git a/src/components/ContainerComponents/ViewContainer/OngoingChallengeDetailsViewContainer.tsx b/src/components/ContainerComponents/ViewContainer/OngoingChallengeDetailsViewContainer.tsx index e1a4bc38918a1d39a220829b53c21bd5a2061e35..ff39bebd96360d30d8eccd0fceb6e05d2a4f15b3 100644 --- a/src/components/ContainerComponents/ViewContainer/OngoingChallengeDetailsViewContainer.tsx +++ b/src/components/ContainerComponents/ViewContainer/OngoingChallengeDetailsViewContainer.tsx @@ -38,9 +38,12 @@ const OngoingChallengeDetailsViewContainer: React.FC<OngoingChallengeDetailsView const client = props.client const challengeManager = new ChallengeManager(client) - const { refreshCurrentChallenge, screenType, userProfile } = useContext( - AppContext - ) + const { + refreshCurrentChallenge, + screenType, + userProfile, + setNotificationEcogesture, + } = useContext(AppContext) const [challengeEcogesture, setChallengeEcogesture] = useState<number>(0) const [openEcogestureModal, setOpenEcogestureModal] = useState(false) const [challenge, setChallenge] = useState<UserChallenge | null>(null) @@ -57,7 +60,18 @@ const OngoingChallengeDetailsViewContainer: React.FC<OngoingChallengeDetailsView challenge.id, ChallengeState.ABANDONED ) - userProfile.notificationEcogesture = [] + + userProfile.notificationEcogesture = + userProfile && + userProfile.notificationEcogesture.filter( + x => + x !== challenge.selectedEcogestures[0].id && + x !== challenge.selectedEcogestures[1].id + ) + await setNotificationEcogesture( + userProfile && userProfile.notificationEcogesture + ) + await refreshCurrentChallenge() history.goBack() } diff --git a/src/components/ContentComponents/EcogestureList/EcogestureList.tsx b/src/components/ContentComponents/EcogestureList/EcogestureList.tsx index d7de60cae0324b43da5d323f31bca370b1f23213..51fe49e01cb9cc3e8d82d97ac0bef2146fea10d6 100644 --- a/src/components/ContentComponents/EcogestureList/EcogestureList.tsx +++ b/src/components/ContentComponents/EcogestureList/EcogestureList.tsx @@ -19,7 +19,6 @@ const EcogesturesList: React.FC<EcogesturesListProps> = ({ t, client, }: EcogesturesListProps) => { - const { userProfile, setNotificationEcogesture } = useContext(AppContext) const [ selectedEcogesture, setSelectedEcogesture, @@ -32,14 +31,6 @@ const EcogesturesList: React.FC<EcogesturesListProps> = ({ const handleClick = (ecogesture: EcogestureType) => { setSelectedEcogesture(ecogesture) setOpenEcogestureModal(true) - let index = -1 - index = userProfile.notificationEcogesture.indexOf(ecogesture.id) - if (index > -1) { - const updatedNotificationEcogestureList = - userProfile && userProfile.notificationEcogesture - updatedNotificationEcogestureList.splice(index, 1) - setNotificationEcogesture(updatedNotificationEcogestureList) - } } const handleCloseClick = () => { diff --git a/src/components/ContentComponents/EcogestureModal/EcogestureModal.tsx b/src/components/ContentComponents/EcogestureModal/EcogestureModal.tsx index 4d9d01fc788c4db55a6fa042102d686926dd0d4e..8ceed213d29b88573e88801b74c65a0305b3fb00 100644 --- a/src/components/ContentComponents/EcogestureModal/EcogestureModal.tsx +++ b/src/components/ContentComponents/EcogestureModal/EcogestureModal.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react' +import React, { useState, useEffect, useContext } from 'react' import { translate } from 'cozy-ui/react/I18n' import Modal from 'components/CommonKit/Modal/Modal' import { getPicto } from 'utils/utils' @@ -6,6 +6,7 @@ import { EcogestureType } from 'services/dataChallengeContracts' import StyledIcon from 'components/CommonKit/Icon/StyledIcon' import Icon from 'cozy-ui/react/Icon' import def from 'assets/icons/visu/ecogesture/default.svg' +import { AppContext } from 'components/Contexts/AppContextProvider' interface EcogestureModalProps { opened: boolean @@ -24,6 +25,7 @@ const EcogestureModal: React.FC<EcogestureModalProps> = ({ handleCloseClick, }: EcogestureModalProps) => { const [ecogestureIcon, setEcogestureIcon] = useState(def) + const { userProfile, setNotificationEcogesture } = useContext(AppContext) async function importEcogestureIcon(id: string) { // Les svg doivent ĂȘtre au format id.svg @@ -38,6 +40,17 @@ const EcogestureModal: React.FC<EcogestureModalProps> = ({ } } + useEffect(() => { + let index = -1 + index = userProfile.notificationEcogesture.indexOf(ecogesture.id) + if (index > -1) { + const updatedNotificationEcogestureList = + userProfile && userProfile.notificationEcogesture + updatedNotificationEcogestureList.splice(index, 1) + setNotificationEcogesture(updatedNotificationEcogestureList) + } + }, []) + useEffect(() => { if (ecogesture) { importEcogestureIcon(ecogesture.id) diff --git a/src/services/queryRunnerService.ts b/src/services/queryRunnerService.ts index a788e6d6c53959cf36b6c306343daaa6b938c513..1d2f16e6ca4fd4b039acba31791ebd4c4b77f4e8 100644 --- a/src/services/queryRunnerService.ts +++ b/src/services/queryRunnerService.ts @@ -211,8 +211,6 @@ export class QueryRunner { ) { const doctype = this.getRelevantDoctype(fluidType, timeStep) if (timeStep === TimeStep.HALF_AN_HOUR) { - const lastDayOfPreviousMonth = maxTimePeriod.startDate.plus({ day: -1 }) - return this._client .find(doctype) .where(this.getPredicate(maxTimePeriod, 20))