diff --git a/src/components/Consumption/ConsumptionView.tsx b/src/components/Consumption/ConsumptionView.tsx index ea5922bbaf2c27a1d95c8ee76c11a7fbc5cb8141..79784af6e68a92ad15734af988504ea511ba1a5a 100644 --- a/src/components/Consumption/ConsumptionView.tsx +++ b/src/components/Consumption/ConsumptionView.tsx @@ -95,29 +95,26 @@ const ConsumptionView = ({ fluidType }: { fluidType: FluidType }) => { } } - const handleClosePartnerIssueModal = useCallback( - async (fluidType: FluidType) => { - const profileService = new ProfileService(client) - const profileValues = await profileService.getProfile() - if (profileValues) { - const updatedProfile = await profileService.updateProfile({ - partnersIssueSeenDate: { - ...profileValues.partnersIssueSeenDate, - [getPartnerKey(fluidType)]: getTodayDate(), - }, - }) - if (updatedProfile) { - dispatch( - openPartnersModal({ - ...partnersIssueModal, - [getPartnerKey(fluidType)]: false, - }) - ) - } + const handleClosePartnerIssueModal = useCallback(async () => { + const profileService = new ProfileService(client) + const profileValues = await profileService.getProfile() + if (profileValues) { + const updatedProfile = await profileService.updateProfile({ + partnersIssueSeenDate: { + ...profileValues.partnersIssueSeenDate, + [getPartnerKey(fluidType)]: getTodayDate(), + }, + }) + if (updatedProfile) { + dispatch( + openPartnersModal({ + ...partnersIssueModal, + [getPartnerKey(fluidType)]: false, + }) + ) } - }, - [client, dispatch, partnersIssueModal] - ) + } + }, [client, dispatch, fluidType, partnersIssueModal]) const handleCloseCustomPopupModal = async () => { const profileService = new ProfileService(client) diff --git a/src/components/Hooks/useKonnectorAuth.tsx b/src/components/Hooks/useKonnectorAuth.tsx index 150ab18e3e73103b3a8d35112253fcce04279cfb..77348935820f289bccd2b9d4fc87a30c9b31ac71 100644 --- a/src/components/Hooks/useKonnectorAuth.tsx +++ b/src/components/Hooks/useKonnectorAuth.tsx @@ -60,7 +60,6 @@ const formatAuthData = ({ } const useKonnectorAuth = ( - // not needed ? fluidType: FluidType, options: { eglAuthData?: AccountEGLData diff --git a/src/components/Konnector/ConnectionResult/ConnectionResult.tsx b/src/components/Konnector/ConnectionResult/ConnectionResult.tsx index ed4433a1ed16ced0b1f8de2fde10726ea18cda60..e9ed092d846669336638014d998f9a264709ce33 100644 --- a/src/components/Konnector/ConnectionResult/ConnectionResult.tsx +++ b/src/components/Konnector/ConnectionResult/ConnectionResult.tsx @@ -110,37 +110,35 @@ const ConnectionResult = ({ } }, [lastExecutionDate]) - const handleRefreshConsent = useCallback( - (fluidType: FluidType) => { - if (fluidType == FluidType.ELECTRICITY) { - const accountData = currentFluidStatus.connection.account - ?.auth as AccountSgeData - // store the previous account data since the onDelete will remove account from DB - dispatch( - updateSgeStore({ - currentStep: 0, - firstName: accountData.firstname, - lastName: accountData.lastname, - pdl: parseInt(accountData.pointId), - address: accountData.address, - zipCode: parseInt(accountData.postalCode), - city: accountData.city, - dataConsent: true, - pdlConfirm: true, - shouldLaunchAccount: true, - }) - ) - dispatch(setShouldRefreshConsent(true)) - } else { - deleteAccountsAndTriggers() - } - }, - [ - deleteAccountsAndTriggers, - dispatch, - currentFluidStatus.connection.account?.auth, - ] - ) + const handleRefreshConsent = useCallback(() => { + if (fluidType == FluidType.ELECTRICITY) { + const accountData = currentFluidStatus.connection.account + ?.auth as AccountSgeData + // store the previous account data since the onDelete will remove account from DB + dispatch( + updateSgeStore({ + currentStep: 0, + firstName: accountData.firstname, + lastName: accountData.lastname, + pdl: parseInt(accountData.pointId), + address: accountData.address, + zipCode: parseInt(accountData.postalCode), + city: accountData.city, + dataConsent: true, + pdlConfirm: true, + shouldLaunchAccount: true, + }) + ) + dispatch(setShouldRefreshConsent(true)) + } else { + deleteAccountsAndTriggers() + } + }, [ + fluidType, + currentFluidStatus.connection.account?.auth, + dispatch, + deleteAccountsAndTriggers, + ]) useEffect(() => { if (currentFluidStatus.connection.triggerState?.last_success) { diff --git a/src/services/consumption.service.ts b/src/services/consumption.service.ts index b6565ff740072fd5396b760f8c84122651a26223..daaf292f0197a6b9bd2b1366c211cd4256cf2482 100644 --- a/src/services/consumption.service.ts +++ b/src/services/consumption.service.ts @@ -36,17 +36,7 @@ export default class ConsumptionDataManager { this._consumptionValidatorService = new ConsumptionValidatorService() } - /** - * Get graph data according on timeStep and fluidType - * @param timePeriod TimePeriod - * @param timeStep TimeStep - * @param fluidTypes FluidType[] - * @param fluidStatus FluidStatus[] - * @param compareTimePeriod - Optional TimePeriod - * @param isHome - Optional boolean - * @param isExport - Optional boolean - * @returns DataChart | null - */ + /** Get graph data according on timeStep and fluidType */ public async getGraphData( timePeriod: TimePeriod, timeStep: TimeStep, @@ -56,28 +46,24 @@ export default class ConsumptionDataManager { isHome?: boolean, isExport?: boolean ): Promise<Datachart | null> { - const InputisValid: boolean = - this._consumptionValidatorService.ValidateGetGraphData( + const InputIsValid = this._consumptionValidatorService.ValidateGetGraphData( + timePeriod, + timeStep, + fluidTypes, + compareTimePeriod, + isExport + ) + if (!InputIsValid) return null + if (fluidTypes.length === 1 && !isHome) { + const fluidType: FluidType = fluidTypes[0] + const fetchedData = await this.fetchSingleFluidGraphData( timePeriod, timeStep, - fluidTypes, - compareTimePeriod, - isExport + fluidType, + compareTimePeriod ) - if (!InputisValid) return null - if (fluidTypes.length === 1 && !isHome) { - const fluidType: FluidType = fluidTypes[0] - // running the query - const fetchedData: Datachart | null = - await this.fetchSingleFluidGraphData( - timePeriod, - timeStep, - fluidType, - compareTimePeriod - ) - // formatting data - const formattedData: Datachart | null = this.formatGraphDataManager( + const formattedData = this.formatGraphDataManager( fetchedData, timeStep, timePeriod, @@ -110,8 +96,7 @@ export default class ConsumptionDataManager { chartFluid: fluidType, }) } - const aggregatedData: Datachart | null = - this.aggregateGraphData(toBeAggregatedData) + const aggregatedData = this.aggregateGraphData(toBeAggregatedData) return aggregatedData } else return null } @@ -148,7 +133,7 @@ export default class ConsumptionDataManager { } } - // fetch last dataload available for a given fluid - return the daily data + /** get last dataload available for a given fluid - return the daily data */ public async getLastDataload( fluidTypes: FluidType ): Promise<Dataload[] | null> { @@ -452,7 +437,6 @@ export default class ConsumptionDataManager { private aggregateGraphData( singleFluidCharts: ISingleFluidChartData[] - // ,withComparison: boolean = true ): Datachart | null { if (singleFluidCharts[0]?.chartData) { const converterService = new ConverterService() @@ -580,11 +564,6 @@ export default class ConsumptionDataManager { return null } - /** - * getLastHourData - * @param {number} month number - * @returns {Promise<DataloadEntity[]>} usageEvent added - */ public async getLastHourData( client: Client, month: number diff --git a/src/services/quiz.service.ts b/src/services/quiz.service.ts index ffc47a65192bb41959922668371673eac095e95e..26271500527efae3b6cb4a890b3983a3673a7db7 100644 --- a/src/services/quiz.service.ts +++ b/src/services/quiz.service.ts @@ -260,7 +260,7 @@ export default class QuizService { */ public async getCustomQuestion( customQuestionEntity: CustomQuestionEntity, - fluidType: FluidType[] + fluidTypes: FluidType[] ): Promise<QuestionEntity> { let answers: Answer[] const explanation = @@ -269,22 +269,22 @@ export default class QuizService { customQuestionEntity.interval, customQuestionEntity.period.weekday ? {} : customQuestionEntity.period ) - let useFluidType: FluidType[] = fluidType + let useFluidTypes: FluidType[] = fluidTypes let questionLabel: string = customQuestionEntity.questionLabel let unit = '€' if (customQuestionEntity.singleFluid === true) { let unitLabel = 'kWh' let fluidLabel = "d'électricité" // Define the right fluidType - if (fluidType.includes(FluidType.ELECTRICITY)) { - useFluidType = [FluidType.ELECTRICITY] + if (fluidTypes.includes(FluidType.ELECTRICITY)) { + useFluidTypes = [FluidType.ELECTRICITY] unit = 'kWh' - } else if (fluidType.includes(FluidType.GAS)) { - useFluidType = [FluidType.GAS] + } else if (fluidTypes.includes(FluidType.GAS)) { + useFluidTypes = [FluidType.GAS] unit = 'kWh' fluidLabel = 'de gaz' } else { - useFluidType = [FluidType.WATER] + useFluidTypes = [FluidType.WATER] unit = 'L' unitLabel = 'litre' fluidLabel = "d'eau" @@ -295,12 +295,11 @@ export default class QuizService { } if (customQuestionEntity.type === CustomQuestionType.DATE) { // Interval - const intervalAsnwer: IntervalAnswer = - await this.getMaxLoadOnLastInterval( - customQuestionEntity.timeStep, - finalInterval, - useFluidType - ) + const intervalAsnwer = await this.getMaxLoadOnLastInterval( + customQuestionEntity.timeStep, + finalInterval, + useFluidTypes + ) answers = this.getAnswersForInterval( intervalAsnwer.date, customQuestionEntity.timeStep, @@ -312,7 +311,7 @@ export default class QuizService { let maxLoad = await consumptionService.getMaxLoad( finalInterval, customQuestionEntity.timeStep, - useFluidType, + useFluidTypes, undefined, !customQuestionEntity.singleFluid ) @@ -320,10 +319,10 @@ export default class QuizService { answers = this.getAnswersForNumberValue(maxLoad as number, unit) } else { // average - const averageLoad: number = await this.getAverageOnGivenPeriod( + const averageLoad = await this.getAverageOnGivenPeriod( customQuestionEntity.timeStep, finalInterval, - useFluidType, + useFluidTypes, customQuestionEntity.period.weekday ? customQuestionEntity.period.weekday : undefined,