diff --git a/src/components/Analysis/MonthlyAnalysis.tsx b/src/components/Analysis/MonthlyAnalysis.tsx index 588b3bfff2338957002fe6e4bb1649ec4e99adef..e66f960076d486d9faba827e17d1ba468f118da0 100644 --- a/src/components/Analysis/MonthlyAnalysis.tsx +++ b/src/components/Analysis/MonthlyAnalysis.tsx @@ -7,6 +7,7 @@ import React, { useEffect, useMemo, useState } from 'react' import ConsumptionService from 'services/consumption.service' import PerformanceIndicatorService from 'services/performanceIndicator.service' import { useAppSelector } from 'store/hooks' +import { allFluids } from 'utils/utils' import Comparison from './Comparison/Comparison' import ElecHalfHourMonthlyAnalysis from './ElecHalfHourMonthlyAnalysis/ElecHalfHourMonthlyAnalysis' import IncompleteDataWarning from './IncompleteDataWarning/IncompleteDataWarning' @@ -74,17 +75,16 @@ const MonthlyAnalysis = ({ startDate: analysisMonth.minus({ month: 2 }).startOf('month'), endDate: analysisMonth.minus({ month: 2 }).endOf('month'), } - const resultFluids = - await consumptionService.getFluidsWithDataForTimePeriod( - [FluidType.ELECTRICITY, FluidType.WATER, FluidType.GAS], + const [resultFluids, fetchedIncompleteDataFluids] = await Promise.all([ + consumptionService.getFluidsWithDataForTimePeriod( + allFluids, timePeriod - ) - - const fetchedIncompleteDataFluids = - await consumptionService.getFluidsWithIncompleteData( - [FluidType.ELECTRICITY, FluidType.WATER, FluidType.GAS], + ), + consumptionService.getFluidsWithIncompleteData( + allFluids, timePeriod.startDate - ) + ), + ]) setIncompleteDataFluids(fetchedIncompleteDataFluids) const fetchedPerformanceIndicators = diff --git a/src/components/Challenge/ChallengeCard/__snapshots__/ChallengeCard.spec.tsx.snap b/src/components/Challenge/ChallengeCard/__snapshots__/ChallengeCard.spec.tsx.snap index bdba3583167a557a78f45872e7dbcbe5bf83db09..2500a582f326dd82eda13780f8013d711a194b2a 100644 --- a/src/components/Challenge/ChallengeCard/__snapshots__/ChallengeCard.spec.tsx.snap +++ b/src/components/Challenge/ChallengeCard/__snapshots__/ChallengeCard.spec.tsx.snap @@ -41,7 +41,8 @@ RUISSEAU <span class="text-18" > - challenge.card_done.depense + challenge.card_done.depense + <span class="text-18-bold" > diff --git a/src/components/Challenge/ChallengeCardDone/ChallengeCardDone.tsx b/src/components/Challenge/ChallengeCardDone/ChallengeCardDone.tsx index f671152a31ce1d1a404786ff7456fd9a01ed3eb6..4497072581bd4afc53898a570dab3ffef9a7e298 100644 --- a/src/components/Challenge/ChallengeCardDone/ChallengeCardDone.tsx +++ b/src/components/Challenge/ChallengeCardDone/ChallengeCardDone.tsx @@ -28,32 +28,9 @@ const ChallengeCardDone = ({ const client = useClient() const dispatch = useAppDispatch() const { currentChallenge } = useAppSelector(state => state.ecolyo.challenge) - const [winIcon, setWinIcon] = useState<string>(defaultIcon) - const [lossIcon, setLossIcon] = useState<string>(defaultIcon) + const [resultIcon, setResultIcon] = useState<string>(defaultIcon) - const getUserSaving = (_userChallenge: UserChallenge) => { - let label - if (_userChallenge.success === UserChallengeSuccess.WIN) - label = t('challenge.card_done.saving') - else label = t('challenge.card_done.depense') - - return label + ' ' - } - - const getResultLabel = (_userChallenge: UserChallenge) => { - switch (_userChallenge.success) { - case UserChallengeSuccess.WIN: - return t('challenge.card_done.win') - case UserChallengeSuccess.LOST: - default: - return t('challenge.card_done.lost') - } - } - - const getIcon = (_userChallenge: UserChallenge) => { - if (_userChallenge.success == UserChallengeSuccess.WIN) return winIcon - else return lossIcon - } + const isSuccess = userChallenge.success === UserChallengeSuccess.WIN const goDuel = async () => { navigate('/challenges/duel?id=' + userChallenge.id) @@ -70,13 +47,14 @@ const ChallengeCardDone = ({ useEffect(() => { async function handleEcogestureIcon() { - const icon = await importIconById(userChallenge.id + '-1', 'duelResult') - setWinIcon(icon || defaultIcon) - const icon2 = await importIconById(userChallenge.id + '-0', 'duelResult') - setLossIcon(icon2 || defaultIcon) + const icon = await importIconById( + userChallenge.id + '-' + Number(isSuccess), + 'duelResult' + ) + setResultIcon(icon || defaultIcon) } handleEcogestureIcon() - }, [userChallenge]) + }, [isSuccess, userChallenge]) return ( <div className="cardContent cardDone"> @@ -84,11 +62,7 @@ const ChallengeCardDone = ({ {getChallengeTitleWithLineReturn(userChallenge.id)} </div> <div className="iconResult"> - <StyledIcon - className="imgResult" - icon={getIcon(userChallenge)} - size={180} - /> + <StyledIcon className="imgResult" icon={resultIcon} size={180} /> </div> <div className="statsResult"> <div @@ -97,10 +71,14 @@ const ChallengeCardDone = ({ lost: userChallenge.success === UserChallengeSuccess.LOST, })} > - {getResultLabel(userChallenge)} + {isSuccess + ? t('challenge.card_done.win') + : t('challenge.card_done.lost')} </div> <span className="text-18"> - {getUserSaving(userChallenge)} + {isSuccess + ? t('challenge.card_done.saving') + : t('challenge.card_done.depense')}{' '} <span className="text-18-bold"> {formatNumberValues( Math.abs( diff --git a/src/components/Challenge/ChallengeCardDone/__snapshots__/ChallengeCardDone.spec.tsx.snap b/src/components/Challenge/ChallengeCardDone/__snapshots__/ChallengeCardDone.spec.tsx.snap index 8e652c9da261c26fa84eca16f6493cf8fe2474b6..38b735fe151d96e983ddcf984fd689b512dc5f00 100644 --- a/src/components/Challenge/ChallengeCardDone/__snapshots__/ChallengeCardDone.spec.tsx.snap +++ b/src/components/Challenge/ChallengeCardDone/__snapshots__/ChallengeCardDone.spec.tsx.snap @@ -36,7 +36,8 @@ VEILLE <span class="text-18" > - challenge.card_done.saving + challenge.card_done.saving + <span class="text-18-bold" > diff --git a/src/components/Duel/DuelResultModal/DuelResultModal.tsx b/src/components/Duel/DuelResultModal/DuelResultModal.tsx index a9435238da7bf93c255657c5ea5dd34f9c6c09fe..5586bc353725a060b5c0781b4a31f5e9a92156ae 100644 --- a/src/components/Duel/DuelResultModal/DuelResultModal.tsx +++ b/src/components/Duel/DuelResultModal/DuelResultModal.tsx @@ -23,8 +23,7 @@ const DuelResultModal = ({ handleCloseClick, }: DuelResultModalProps) => { const { t } = useI18n() - const [winIcon, setWinIcon] = useState<string>(defaultIcon) - const [lossIcon, setLossIcon] = useState<string>(defaultIcon) + const [resultIcon, setResultIcon] = useState<string>(defaultIcon) const result = formatNumberValues( Math.abs(userChallenge.duel.threshold - userChallenge.duel.userConsumption) ) @@ -33,13 +32,14 @@ const DuelResultModal = ({ useEffect(() => { async function handleEcogestureIcon() { - const icon = await importIconById(userChallenge.id + '-1', 'duelResult') - setWinIcon(icon || defaultIcon) - const icon2 = await importIconById(userChallenge.id + '-0', 'duelResult') - setLossIcon(icon2 || defaultIcon) + const icon = await importIconById( + userChallenge.id + '-' + Number(win), + 'duelResult' + ) + setResultIcon(icon || defaultIcon) } handleEcogestureIcon() - }, [userChallenge]) + }, [userChallenge, win]) return ( <Dialog @@ -63,11 +63,7 @@ const DuelResultModal = ({ size={300} /> )} - <StyledIcon - className="imgResult" - icon={win ? winIcon : lossIcon} - size={180} - /> + <StyledIcon className="imgResult" icon={resultIcon} size={180} /> </div> <div className="text-28-normal-uppercase title"> {t(`duel_result_modal.${statusKey}.title`)} diff --git a/src/components/Options/ExportData/Modals/exportLoadingModal.tsx b/src/components/Options/ExportData/Modals/exportLoadingModal.tsx index f5da6d6f7384d166ddb97a9c438e53ab876a1c7d..ce937ad825a32bbdf56946df9002f797dab3d7fb 100644 --- a/src/components/Options/ExportData/Modals/exportLoadingModal.tsx +++ b/src/components/Options/ExportData/Modals/exportLoadingModal.tsx @@ -95,14 +95,13 @@ const ExportLoadingModal = ({ const getExportDataSheet = useCallback( async (fluidType: FluidType): Promise<ExportDataSheet | null> => { const consumptionService = new ConsumptionDataManager(client) - const [firstDataDate] = await consumptionService.fetchAllFirstDateData( - [fluidType], - TimeStep.MONTH - ) - const [lastDataDate] = await consumptionService.fetchAllLastDateData( - [fluidType], - TimeStep.MONTH - ) + const [firstDataDates, lastDataDates] = await Promise.all([ + consumptionService.fetchAllFirstDateData([fluidType], TimeStep.MONTH), + consumptionService.fetchAllLastDateData([fluidType], TimeStep.MONTH), + ]) + const firstDataDate = firstDataDates[0] + const lastDataDate = lastDataDates[0] + if (!firstDataDate || !lastDataDate) return null const timePeriod: TimePeriod = { diff --git a/src/targets/services/enedisHalfHourMonthlyAnalysis.ts b/src/targets/services/enedisHalfHourMonthlyAnalysis.ts index c6858269e4c8f6893f7c4948d9ad8024b45783b7..b356f516c539ad34c3f5cb6a2d51a20e1ae6fb4d 100644 --- a/src/targets/services/enedisHalfHourMonthlyAnalysis.ts +++ b/src/targets/services/enedisHalfHourMonthlyAnalysis.ts @@ -192,14 +192,14 @@ const getEnedisMonthAnalysisData = async ( const weekAverages = weekValuesArray.map(halfHourArray => arrAvg(halfHourArray) ) + const [maxPower, offPeakHoursRatio] = await Promise.all([ + getMonthMaxPower(month, year, client), + getOffPeakHoursRatio(month, year, client), + ]) monthlyAveragesLoads.weekDaysHalfHourAverageValues = weekAverages monthlyAveragesLoads.weekEndDaysHalfHourAverageValues = weekEndAverages - monthlyAveragesLoads.maxPower = await getMonthMaxPower(month, year, client) - monthlyAveragesLoads.offPeakHoursRatio = await getOffPeakHoursRatio( - month, - year, - client - ) + monthlyAveragesLoads.maxPower = maxPower + monthlyAveragesLoads.offPeakHoursRatio = offPeakHoursRatio return monthlyAveragesLoads } }