diff --git a/src/components/Splash/SplashRoot.tsx b/src/components/Splash/SplashRoot.tsx index 24402436bd0bd59c53319791fe36673e6fd29d00..6afbfff8ca5ffae4390e88e7a0ef94cf02031467 100644 --- a/src/components/Splash/SplashRoot.tsx +++ b/src/components/Splash/SplashRoot.tsx @@ -11,7 +11,6 @@ import { updateProfile } from 'store/profile/profile.actions' import { setUserChallengeList, setChallengeConsumption, - updateUserChallengeList, } from 'store/challenge/challenge.actions' import { setSelectedDate } from 'store/chart/chart.actions' import InitializationService from 'services/initialization.service' @@ -26,6 +25,7 @@ import { } from 'enum/userExploration.enum' import { DateTime } from 'luxon' import { UserActionState } from 'enum/userAction.enum' +import ActionService from 'services/action.service' interface SplashRootProps { fadeTimer?: number @@ -165,12 +165,11 @@ const SplashRoot = ({ filteredCurrentOngoingChallenge[0].action.state === UserActionState.ONGOING ) { - const isActionDone = await initializationService.isActionDone( + const actionService = new ActionService(client) + const isActionDone: boolean = await actionService.isActionDone( filteredCurrentOngoingChallenge[0] ) - if (subscribed) { - dispatch(toogleChallengeNotification(isActionDone)) - } + dispatch(toogleChallengeNotification(isActionDone)) } const filteredCurrentDuelChallenge = userChallengeList.filter( challenge => challenge.state === UserChallengeState.DUEL diff --git a/src/services/action.service.ts b/src/services/action.service.ts index 6daebc56b63522f1c11d13b24261f5029529596b..31371b6ad14c2c701338dfef6305a898ceabbcc4 100644 --- a/src/services/action.service.ts +++ b/src/services/action.service.ts @@ -2,6 +2,7 @@ import { Client } from 'cozy-client' import { Season } from 'enum/ecogesture.enum' import { FluidType } from 'enum/fluid.enum' import { UserActionState } from 'enum/userAction.enum' +import { UserChallengeUpdateFlag } from 'enum/userChallenge.enum' import { orderBy } from 'lodash' import { DateTime, Interval } from 'luxon' import { Ecogesture, UserAction, UserChallenge } from 'models' @@ -240,4 +241,28 @@ export default class ActionService { } return updatedUserAction } + /** + * isActionDone - Set Action state to notification if progress > actionDuration + * @param {UserChallenge} currentChallenge + * @returns {Promise<boolean>} + */ + public async isActionDone(currentChallenge: UserChallenge): Promise<boolean> { + if ( + currentChallenge.action.startDate && + currentChallenge.action.ecogesture + ) { + const startDate: DateTime = currentChallenge.action.startDate + const durationInHours = + currentChallenge.action.ecogesture.actionDuration * 24 + const progressInHours = -startDate.diffNow('hours').hours + if (progressInHours > durationInHours) { + const challengeService = new ChallengeService(this._client) + await challengeService.updateUserChallenge( + currentChallenge, + UserChallengeUpdateFlag.ACTION_NOTIFICATION + ) + return true + } else return false + } else return false + } } diff --git a/src/services/initialization.service.ts b/src/services/initialization.service.ts index 394f601c87eba6d7d7dad190fa5c02b280d244d4..261f928612dba3a7cbd3e98a0ec384ecf5df41bb 100644 --- a/src/services/initialization.service.ts +++ b/src/services/initialization.service.ts @@ -842,26 +842,4 @@ export default class InitializationService { throw error } } - /** - * isActionDone - Set Action state to notification if progress > actionDuration - */ - public async isActionDone(currentChallenge: UserChallenge): Promise<boolean> { - if ( - currentChallenge.action.startDate && - currentChallenge.action.ecogesture - ) { - const startDate: DateTime = currentChallenge.action.startDate - const durationInHours = - currentChallenge.action.ecogesture.actionDuration * 24 - const progressInHours = -startDate.diffNow('hours').hours - if (progressInHours > durationInHours) { - const challengeService = new ChallengeService(this._client) - await challengeService.updateUserChallenge( - currentChallenge, - UserChallengeUpdateFlag.ACTION_NOTIFICATION - ) - return true - } else return false - } else return false - } }