diff --git a/src/components/Duel/DuelDetails.tsx b/src/components/Duel/DuelDetails.tsx new file mode 100644 index 0000000000000000000000000000000000000000..fbfcab799a7f3c01f0aa3db36d8158e021adbba7 --- /dev/null +++ b/src/components/Duel/DuelDetails.tsx @@ -0,0 +1,17 @@ +import React, { useState } from 'react' +import './duelDetails.scss' +import { useSelector } from 'react-redux' +import { EcolyoState } from 'store' +import { UserSeason } from 'models' + +interface DuelDetailsProps { + userSeason: UserSeason +} + +const DuelDetails: React.FC<DuelDetailsProps> = ({ + userSeason, +}: DuelDetailsProps) => { + return <div></div> +} + +export default DuelDetails diff --git a/src/components/Duel/DuelError.tsx b/src/components/Duel/DuelError.tsx new file mode 100644 index 0000000000000000000000000000000000000000..d9a1a604b26909a13b7ec8b4cf4a6900d300eb39 --- /dev/null +++ b/src/components/Duel/DuelError.tsx @@ -0,0 +1,27 @@ +import React, { useCallback } from 'react' +import { useI18n } from 'cozy-ui/transpiled/react/I18n' +import { useHistory } from 'react-router-dom' +import './duelError.scss' +import StyledStopButton from 'components/CommonKit/Button/StyledStopButton' + +const DuelError: React.FC = () => { + const { t } = useI18n() + const history = useHistory() + + const goBack = useCallback(() => { + history.goBack() + }, [history]) + + return ( + <div className="duel-error-container"> + <div className="duel-error-message">{t('duel.global_error')}</div> + <div className="duel-error-button"> + <StyledStopButton color="secondary" onClick={goBack}> + Retour + </StyledStopButton> + </div> + </div> + ) +} + +export default DuelError diff --git a/src/components/Duel/DuelView.tsx b/src/components/Duel/DuelView.tsx new file mode 100644 index 0000000000000000000000000000000000000000..4c7ab2883d54cb86c7c76ba800f39b1150373cfd --- /dev/null +++ b/src/components/Duel/DuelView.tsx @@ -0,0 +1,45 @@ +import React, { useState } from 'react' +import './duelView.scss' +import { useSelector } from 'react-redux' +import { EcolyoState } from 'store' +import CozyBar from 'components/Header/CozyBar' +import Content from 'components/Content/Content' +import Header from 'components/Header/Header' +import { UserSeasonState } from 'enum/userSeason.enum' + +import DuelError from 'components/Duel/DuelError' +import DuelDetails from 'components/Duel/DuelDetails' +import { UserBossState } from 'enum/userBoss.enum' + +const DuelView: React.FC = () => { + const [headerHeight, setHeaderHeight] = useState<number>(0) + const { currentSeason } = useSelector((state: EcolyoState) => state.season) + + const defineHeaderHeight = (height: number) => { + setHeaderHeight(height) + } + + return ( + <> + <CozyBar titleKey={'COMMON.APP_DUEL_TITLE'} displayBackArrow={true} /> + <Header + setHeaderHeight={defineHeaderHeight} + desktopTitleKey={'COMMON.APP_DUEL_TITLE'} + displayBackArrow={true} + ></Header> + <Content height={headerHeight}> + <div className="duel-view-container"> + {currentSeason && + currentSeason.state === UserSeasonState.BOSS && + currentSeason.boss.state === UserBossState.ONGOING ? ( + <DuelDetails userSeason={currentSeason} /> + ) : ( + <DuelError /> + )} + </div> + </Content> + </> + ) +} + +export default DuelView diff --git a/src/components/Duel/duelDetails.scss b/src/components/Duel/duelDetails.scss new file mode 100644 index 0000000000000000000000000000000000000000..e4300007a6ea8c2a1a5e7df46294d2ee3c552521 --- /dev/null +++ b/src/components/Duel/duelDetails.scss @@ -0,0 +1,2 @@ +@import '../../styles/base/typography'; + diff --git a/src/components/Duel/duelError.scss b/src/components/Duel/duelError.scss new file mode 100644 index 0000000000000000000000000000000000000000..7085a1b770829d1d9c4d3399aef4ea3e51a47b97 --- /dev/null +++ b/src/components/Duel/duelError.scss @@ -0,0 +1,19 @@ +@import '../../styles/base/typography'; + +.duel-error-container{ + display: flex; + min-height: 60vh; + flex-direction: column; + align-items: center; + justify-content: center; + padding: 1rem 1.5rem; + color: $grey-bright; +} +.duel-error-message{ + margin-top: 3rem; + text-align: center; +} +.duel-error-button{ + margin-top: 3rem; + width: 7.5rem; +} \ No newline at end of file diff --git a/src/components/Duel/duelView.scss b/src/components/Duel/duelView.scss new file mode 100644 index 0000000000000000000000000000000000000000..8c59488437e4f3c806b25e94bf77e0f156559b0b --- /dev/null +++ b/src/components/Duel/duelView.scss @@ -0,0 +1,8 @@ +@import '../../styles/base/typography'; + +.duel-view-container{ + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; +} \ No newline at end of file diff --git a/src/components/Routes/Routes.tsx b/src/components/Routes/Routes.tsx index 51c5898a4d3f30a48e6339f4f70f3a585333dd9f..1b52f62bcc6f72137929138dd9c58662945ceb0e 100644 --- a/src/components/Routes/Routes.tsx +++ b/src/components/Routes/Routes.tsx @@ -2,6 +2,7 @@ import React, { Suspense, lazy } from 'react' import { Route, Switch, Redirect } from 'react-router-dom' import { FluidType } from 'enum/fluid.enum' import SeasonView from 'components/Season/SeasonView' +import DuelView from 'components/Duel/DuelView' const HomeView = lazy(() => import('components/Home/HomeView')) const SingleFluidView = lazy(() => @@ -52,6 +53,7 @@ const Routes = () => { path="/challenges" render={({ match: { url } }) => ( <> + <Route path={`${url}/duel`} component={DuelView} /> <Route path={`${url}/`} component={SeasonView} exact /> </> )} diff --git a/src/components/Season/SeasonCard.tsx b/src/components/Season/SeasonCard.tsx index a7b33712aae78c02d343f47015f57eb568ec7fdc..6b9bd157755183d216e8773a8460ab8a74321b05 100644 --- a/src/components/Season/SeasonCard.tsx +++ b/src/components/Season/SeasonCard.tsx @@ -31,9 +31,8 @@ const SeasonCard: React.FC<SeasonCardProps> = ({ case UserSeasonState.DONE: return <SeasonCardDone userSeason={userSeason} /> case UserSeasonState.ONGOING: - return <SeasonCardOnGoing userSeason={userSeason} /> case UserSeasonState.BOSS: - return <SeasonCardBoss userSeason={userSeason} /> + return <SeasonCardOnGoing userSeason={userSeason} /> default: return <SeasonCardLocked userSeason={userSeason} /> } diff --git a/src/components/Season/SeasonCardOnGoing.tsx b/src/components/Season/SeasonCardOnGoing.tsx index 9b3febeffe1dda5e31f29a1c316fd4741dfa1f1e..8c0f6df57bdcc35230c1ffc99084cfde06470d5b 100644 --- a/src/components/Season/SeasonCardOnGoing.tsx +++ b/src/components/Season/SeasonCardOnGoing.tsx @@ -1,6 +1,8 @@ import React, { useCallback } from 'react' import { Client, useClient } from 'cozy-client' +import { useI18n } from 'cozy-ui/transpiled/react/I18n' import { useDispatch } from 'react-redux' +import { useHistory } from 'react-router-dom' import { updateUserSeasonList } from 'store/season/season.actions' import './seasonCardOnGoing.scss' import SeasonService from 'services/season.service' @@ -10,7 +12,6 @@ import { UpdateUserSeason } from 'enum/updateUserSeason.enum' import quizIcon from 'assets/icons/visu/season/quizIcon.svg' import missionIcon from 'assets/icons/visu/season/missionIcon.svg' import actionIcon from 'assets/icons/visu/season/actionIcon.svg' -import { useI18n } from 'cozy-ui/transpiled/react/I18n' import StarsContainer from './StarsContainer' import StyledIcon from 'components/CommonKit/Icon/StyledIcon' @@ -21,8 +22,10 @@ const SeasonCardOnGoing: React.FC<SeasonCardOnGoingProps> = ({ userSeason, }: SeasonCardOnGoingProps) => { const client: Client = useClient() - const dispatch = useDispatch() const { t } = useI18n() + const dispatch = useDispatch() + const history = useHistory() + const winStarts = useCallback(async () => { const seasonService = new SeasonService(client) userSeason.progress + 5 >= userSeason.target @@ -42,7 +45,8 @@ const SeasonCardOnGoing: React.FC<SeasonCardOnGoingProps> = ({ UpdateUserSeason.BOSS_START ) dispatch(updateUserSeasonList(updatedSeason)) - }, [client, dispatch, userSeason]) + history.push('/challenges/duel') + }, [client, dispatch, userSeason, history]) const resetProgress = async () => { const seasonService = new SeasonService(client) @@ -53,7 +57,7 @@ const SeasonCardOnGoing: React.FC<SeasonCardOnGoingProps> = ({ ) dispatch(updateUserSeasonList(updatedSeason)) } - console.log('season', userSeason) + return ( <div className="cardContent onGoing"> <div className="titleBlock"> diff --git a/src/components/Season/SeasonCardUnlocked.tsx b/src/components/Season/SeasonCardUnlocked.tsx index 23b6e5b065d184d2d3478fb079e517816f35d249..eb9df5d76a91d8ecf6a170622aaae36150441478 100644 --- a/src/components/Season/SeasonCardUnlocked.tsx +++ b/src/components/Season/SeasonCardUnlocked.tsx @@ -23,8 +23,7 @@ const SeasonCardUnlocked: React.FC<SeasonCardUnlockedProps> = ({ const { t } = useI18n() const [openNoFluidModal, setopenNoFluidModal] = useState(false) - const [workingKonnectors, setworkingKonnectors] = useState<number>(0) - const { fluidStatus } = useSelector((state: EcolyoState) => state.global) + const { fluidTypes } = useSelector((state: EcolyoState) => state.global) const [seasonIcon, setSeasonIcon] = useState(def) @@ -45,20 +44,14 @@ const SeasonCardUnlocked: React.FC<SeasonCardUnlockedProps> = ({ } const launchSeason = useCallback(async () => { - if (workingKonnectors > 1) { - return toggleNoFluidModal() - } else { + if (fluidTypes.length > 0) { const seasonService = new SeasonService(client) const updatedSeason = await seasonService.startUserSeason(userSeason) dispatch(updateUserSeasonList(updatedSeason)) + } else { + return toggleNoFluidModal() } - }, [client, dispatch, userSeason, workingKonnectors]) - - useEffect(() => { - fluidStatus.map(fluid => { - if (fluid.status === 'done') setworkingKonnectors(prev => prev + 1) - }) - }, [fluidStatus]) + }, [client, dispatch, userSeason, fluidTypes]) useEffect(() => { if (userSeason) { diff --git a/src/components/Season/SeasonView.tsx b/src/components/Season/SeasonView.tsx index eabfb1c9846873394da2c6e748c665e86d3057ac..ad1792ea44613ff2ea8a65a7de5c858802dc3e77 100644 --- a/src/components/Season/SeasonView.tsx +++ b/src/components/Season/SeasonView.tsx @@ -87,10 +87,10 @@ const SeasonView: React.FC = () => { return ( <> - <CozyBar titleKey={'COMMON.APP_DEFI_TITLE'} /> + <CozyBar titleKey={'COMMON.APP_CHALLENGE_TITLE'} /> <Header setHeaderHeight={defineHeaderHeight} - desktopTitleKey={'COMMON.APP_DEFI_TITLE'} + desktopTitleKey={'COMMON.APP_CHALLENGE_TITLE'} ></Header> <Content height={headerHeight}> <div diff --git a/src/locales/fr.json b/src/locales/fr.json index 3009c08fcfb5177cf85b2c672e9903d7c2cb7954..17151fec7778db42bd6f368c8ef4cad3e065aad7 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -20,10 +20,10 @@ }, "COMMON": { "APP_TITLE": "Ecolyo", - "APP_CHALLENGE_TITLE": "Défis", + "APP_CHALLENGE_TITLE": "Défi", + "APP_DUEL_TITLE": "Duel final", "APP_ECO_GESTURE_TITLE": "Ecogestes", "APP_OPTIONS_TITLE": "Options", - "APP_DEFI_TITLE": "Défi", "APP_HELLO": "Bonjour", "APP_PRESENTATION": "Consommation d'énergie", "CONSO_DETAILS": "détail des consommations", @@ -343,5 +343,8 @@ "duel": "Duel Final" } } + }, + "duel": { + "global_error": "Oups.. Une erreur est parvenue. Veuillez retourner à l'écran des défis" } } diff --git a/src/services/initialization.service.ts b/src/services/initialization.service.ts index a6d565bc19bfa674cf668564edbb718de84ddc8d..003d533193c7ad165e7d7c8d806600d807d9786d 100644 --- a/src/services/initialization.service.ts +++ b/src/services/initialization.service.ts @@ -409,7 +409,6 @@ export default class InitializationService { profile: Profile | null }> { const hashBossEntity = hashFile(bossEntityData) - const seasonService = new SeasonService(this._client) const bossService = new BossService(this._client) const profileService = new ProfileService(this._client) @@ -458,7 +457,7 @@ export default class InitializationService { // Update the doctype try { // Deletion of all documents - await bossService.getAllBossEntities() + await bossService.deleteAllBossEntities() // Population with the data await Promise.all( bossEntityData.map(async bossEntity => { diff --git a/src/store/season/season.reducer.ts b/src/store/season/season.reducer.ts index 5baac1022c2965278adae7cc8cbf7fdb4c4ee91f..c43ce2facf138d1f63a8623c446c9da5d4b042e7 100644 --- a/src/store/season/season.reducer.ts +++ b/src/store/season/season.reducer.ts @@ -20,7 +20,8 @@ export const seasonReducer: Reducer<SeasonState> = ( case SET_USER_SEASON_LIST: if (action.payload !== undefined) { const filteredCurrentSeason = action.payload.filter( - season => season.state === UserSeasonState.ONGOING + season => + season.state === UserSeasonState.ONGOING || UserSeasonState.BOSS ) const currentSeason = filteredCurrentSeason[0] ? filteredCurrentSeason[0] @@ -37,7 +38,8 @@ export const seasonReducer: Reducer<SeasonState> = ( if (action.payload !== undefined) { const id = action.payload.id const currentSeason = - action.payload.state === UserSeasonState.ONGOING + action.payload.state === UserSeasonState.ONGOING || + UserSeasonState.BOSS ? action.payload : null const updatedList = [...state.userSeasonList]