From aa708af8780387d1cbe644cd5980ca92a01b3d36 Mon Sep 17 00:00:00 2001 From: Bastien DUMONT <bdumont@grandlyon.com> Date: Tue, 26 Mar 2024 13:31:44 +0000 Subject: [PATCH] chore(types): fix types error --- .../ElecHalfHourMonthlyAnalysis.tsx | 32 +++++++------- .../Ecogesture/SingleEcogestureView.tsx | 6 +-- .../Options/ReportOptions/ReportOptions.tsx | 16 ++++--- .../ProfileTypeFinished.tsx | 2 +- src/db/profileTypeData.json | 1 - src/models/account.model.ts | 21 ++++------ src/services/profileType.service.spec.ts | 3 +- src/services/profileType.service.ts | 1 - tests/__mocks__/accountsData.mock.ts | 42 +++++++++---------- .../enedisMonthlyAnalysisData.mock.ts | 5 +++ tests/__mocks__/fluidPrice.mock.ts | 9 ++++ tests/__mocks__/fluidStatusData.mock.ts | 12 ------ 12 files changed, 76 insertions(+), 74 deletions(-) diff --git a/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourMonthlyAnalysis.tsx b/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourMonthlyAnalysis.tsx index 332d2177c..40b4223d8 100644 --- a/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourMonthlyAnalysis.tsx +++ b/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourMonthlyAnalysis.tsx @@ -35,6 +35,7 @@ const ElecHalfHourMonthlyAnalysis = ({ const { t } = useI18n() const client = useClient() const { analysisMonth } = useAppSelector(state => state.ecolyo.analysis) + const [isWeekend, setIsWeekend] = useState<boolean>(true) const [isHalfHourActivated, setIsHalfHourActivated] = useState<boolean>(true) const [isLoading, setIsLoading] = useState<boolean>(true) @@ -51,19 +52,21 @@ const ElecHalfHourMonthlyAnalysis = ({ setIsWeekend(prev => !prev) }, []) - const toggleOpenModal = useCallback(() => { + const toggleInfoModal = useCallback(() => { setOpenInfoModal(prev => !prev) }, []) - const isDataFullyComplete = useCallback(monthDataloads => { - if ( - monthDataloads?.weekend && - monthDataloads.week && - monthDataloads.weekend[0]?.value !== null && - monthDataloads.week[0]?.value !== null - ) { - return true - } else return false - }, []) + + const isDataFullyComplete = useCallback( + (monthDataloads: AggregatedEnedisMonthlyDataloads | undefined) => { + return ( + monthDataloads?.weekend && + monthDataloads.week && + monthDataloads.weekend[0]?.value !== null && + monthDataloads.week[0]?.value !== null + ) + }, + [] + ) const getPowerChart = useCallback((): JSX.Element => { if (monthDataloads && isDataFullyComplete(monthDataloads)) { @@ -73,9 +76,8 @@ const ElecHalfHourMonthlyAnalysis = ({ isWeekend={isWeekend} /> ) - } else { - return <p className="text-20-bold no_data">{t('analysis.no_data')}</p> } + return <p className="text-20-bold no_data">{t('analysis.no_data')}</p> }, [isDataFullyComplete, isWeekend, monthDataloads, t]) useEffect(() => { @@ -279,7 +281,7 @@ const ElecHalfHourMonthlyAnalysis = ({ </div> </div> - <Button className="btnText" onClick={toggleOpenModal}> + <Button className="btnText" onClick={toggleInfoModal}> {t('special_elec.showModal')} </Button> </div> @@ -291,7 +293,7 @@ const ElecHalfHourMonthlyAnalysis = ({ <ElecInfoModal open={openInfoModal} offPeakHours={offPeakHours} - handleCloseClick={toggleOpenModal} + handleCloseClick={toggleInfoModal} /> </div> ) diff --git a/src/components/Ecogesture/SingleEcogestureView.tsx b/src/components/Ecogesture/SingleEcogestureView.tsx index ee8465dcb..3254cab1b 100644 --- a/src/components/Ecogesture/SingleEcogestureView.tsx +++ b/src/components/Ecogesture/SingleEcogestureView.tsx @@ -45,12 +45,12 @@ const SingleEcogestureView = () => { const [, setValidExploration] = useExploration() const updateEcogesture = useCallback( - async (objective, doing) => { + async (objective: boolean, doing: boolean) => { if (ecogesture) { const updates: Ecogesture = { ...ecogesture, - objective: objective, - doing: doing, + objective, + doing, } const result = await ecogestureService.updateEcogesture(updates) if (result) { diff --git a/src/components/Options/ReportOptions/ReportOptions.tsx b/src/components/Options/ReportOptions/ReportOptions.tsx index 50556fd28..528aa2951 100644 --- a/src/components/Options/ReportOptions/ReportOptions.tsx +++ b/src/components/Options/ReportOptions/ReportOptions.tsx @@ -1,3 +1,4 @@ +import { OutlinedInput } from '@material-ui/core' import StyledSwitch from 'components/CommonKit/Switch/StyledSwitch' import { useClient } from 'cozy-client' import { useI18n } from 'cozy-ui/transpiled/react/I18n' @@ -9,7 +10,6 @@ import ConsumptionDataManager from 'services/consumption.service' import { useAppDispatch, useAppSelector } from 'store/hooks' import { updateProfile } from 'store/profile/profile.slice' import './reportOptions.scss' -import { TextField } from '@material-ui/core' const ReportOptions = () => { const { t } = useI18n() @@ -37,7 +37,9 @@ const ReportOptions = () => { fluidStatus[FluidType.WATER].status !== FluidState.KONNECTOR_NOT_FOUND && fluidStatus[FluidType.WATER].status !== FluidState.ERROR_LOGIN_FAILED - const setWaterLimit = (e: React.ChangeEvent<HTMLInputElement>) => { + const setWaterLimit = ( + e: React.FocusEvent<HTMLInputElement | HTMLTextAreaElement, Element> + ) => { if (e.target.value !== null && parseInt(e.target.value) > 0) { dispatch( updateProfile({ @@ -134,8 +136,7 @@ const ReportOptions = () => { {t('profile.report.input_label_alert')} </div> <div className="switch-container-alert"> - <TextField - variant="outlined" + <OutlinedInput className="inputNumber text-18" type="number" defaultValue={ @@ -144,7 +145,12 @@ const ReportOptions = () => { : profile.waterDailyConsumptionLimit } onBlur={setWaterLimit} - label={t('profile.accessibility.input_water_alert_report')} + inputProps={{ + min: 0, + }} + aria-label={t( + 'profile.accessibility.input_water_alert_report' + )} inputMode="numeric" /> <span className="switch-label text-16-normal">L</span> diff --git a/src/components/ProfileType/ProfileTypeFinished/ProfileTypeFinished.tsx b/src/components/ProfileType/ProfileTypeFinished/ProfileTypeFinished.tsx index c7de43077..f32dd2d9d 100644 --- a/src/components/ProfileType/ProfileTypeFinished/ProfileTypeFinished.tsx +++ b/src/components/ProfileType/ProfileTypeFinished/ProfileTypeFinished.tsx @@ -53,7 +53,7 @@ const ProfileTypeFinished = ({ profileType }: { profileType: ProfileType }) => { }), } const profileTypeEntityService = new ProfileTypeEntityService(client) - const myProfileTypes: ProfileType[] | null = + const myProfileTypes = await profileTypeEntityService.getAllProfileTypes(chosenPeriod) if (myProfileTypes !== null) { const destroyPT = diff --git a/src/db/profileTypeData.json b/src/db/profileTypeData.json index beda4cf31..63b94873c 100644 --- a/src/db/profileTypeData.json +++ b/src/db/profileTypeData.json @@ -12,7 +12,6 @@ "coldWater": "individual", "hotWater": "individual", "individualInsulationWork": ["window_replacement"], - "facilitiesInstallation": "none", "hotWaterEquipment": "solar", "hasInstalledVentilation": "unknown", "hasReplacedHeater": "unknown", diff --git a/src/models/account.model.ts b/src/models/account.model.ts index 738666545..bb125bcc9 100644 --- a/src/models/account.model.ts +++ b/src/models/account.model.ts @@ -1,4 +1,12 @@ -/* eslint-disable camelcase */ +export interface AccountAttributes { + account_type: string + auth?: AccountEGLData | AccountSgeData | AccountGRDFData + identifier?: string + state?: string | null + name?: string + data?: SgeAccountData +} + export interface Account extends AccountAttributes { _id: string id?: string @@ -12,17 +20,6 @@ export interface SgeAccountData { offPeakHours?: string } -export interface AccountAttributes { - account_type: string - auth?: AccountEGLData | AccountSgeData | AccountGRDFData - identifier?: string - state?: string | null - name?: string - data?: SgeAccountData - // TODO remove this ? - oauth_callback_results?: Record<string, any> -} - export interface AccountEGLData { login: string credentials_encrypted?: string diff --git a/src/services/profileType.service.spec.ts b/src/services/profileType.service.spec.ts index 3c52e9a65..0e8340734 100644 --- a/src/services/profileType.service.spec.ts +++ b/src/services/profileType.service.spec.ts @@ -533,11 +533,10 @@ describe('ProfileType service', () => { DateTime.fromISO('2021-01-01T00:00:00.000Z', { zone: 'utc' }) ) - const expectedResult = { + const expectedResult: ProfileType = { ...mockProfile, warmingFluid: null, individualInsulationWork: [], - facilitiesInstallation: [], hotWaterFluid: null, hotWaterEquipment: HotWaterEquipment.OTHER, } diff --git a/src/services/profileType.service.ts b/src/services/profileType.service.ts index 814a340ed..91aa35bba 100644 --- a/src/services/profileType.service.ts +++ b/src/services/profileType.service.ts @@ -479,7 +479,6 @@ export default class ProfileTypeService { if (profileType.heating === IndividualOrCollective.COLLECTIVE) { profileType.warmingFluid = null profileType.individualInsulationWork = [] - profileType.facilitiesInstallation = [] } if (profileType.hotWater === IndividualOrCollective.COLLECTIVE) { profileType.hotWaterFluid = null diff --git a/tests/__mocks__/accountsData.mock.ts b/tests/__mocks__/accountsData.mock.ts index 7775e8b61..911835bf0 100644 --- a/tests/__mocks__/accountsData.mock.ts +++ b/tests/__mocks__/accountsData.mock.ts @@ -7,23 +7,24 @@ export const accountsData: Account[] = [ _rev: '1-88e68b8450cee09fe2f077610901094d', account_type: 'enedissgegrandlyon', name: '', - oauth: { - access_token: 'MY_ACCESS_TOKEN', - expires_at: '2020-10-09T08:00:00.285910671+02:00', - refresh_token: '', - token_type: 'Bearer', - }, - oauth_callback_results: { - issued_at: '1592232569642', - refresh_token_issued_at: '1592232569642', - scope: '/my_enedis_scope', - usage_points_id: '', - }, cozyMetadata: { createdAt: '2020-11-10T16:42:11.132Z', metadataVersion: 1, updatedAt: '2020-11-10T16:42:11.132Z', }, + auth: { + address: '6 Rue Vaillant Couturier', + city: 'Vénissieux', + firstname: 'Jane', + lastname: 'Doe', + pointId: '19170766804121', + postalCode: '69200', + }, + data: { + consentId: 43, + expirationDate: '2023-09-26', + offPeakHours: '22H00-6H00', + }, }, { _id: '90e68b8450cee09fe2f077610901094d', @@ -51,16 +52,13 @@ export const accountsData: Account[] = [ _rev: '1-89e68b8450cee09fe2f077610901094d', account_type: 'grdfgrandlyon', name: '', - oauth: { - access_token: 'MY_ACCESS_TOKEN', - expires_at: '2020-10-09T08:00:00.285910671+02:00', - refresh_token: '', - token_type: 'Bearer', - }, - oauth_callback_results: { - id_token: 'MY_ID_TOKEN', - pce: '12345678987654', - scope: '/my_grdf_scope', + identifier: 'email', + auth: { + email: 'jane@grandlyon.com', + firstname: 'Jane', + lastname: 'Doe', + pce: '12345678901234', + postalCode: '69003', }, cozyMetadata: { createdAt: '2020-11-10T16:42:11.132Z', diff --git a/tests/__mocks__/enedisMonthlyAnalysisData.mock.ts b/tests/__mocks__/enedisMonthlyAnalysisData.mock.ts index bba9d3cc0..e980d11b4 100644 --- a/tests/__mocks__/enedisMonthlyAnalysisData.mock.ts +++ b/tests/__mocks__/enedisMonthlyAnalysisData.mock.ts @@ -13,6 +13,7 @@ export const mockEnedisMonthlyAnalysis: EnedisMonthlyAnalysisData = { year: 2021, minimumLoad: 3, maxPower: 2, + offPeakHoursRatio: null, } export const mockEnedisMonthlyAnalysisArray: EnedisMonthlyAnalysisData[] = [ @@ -23,6 +24,7 @@ export const mockEnedisMonthlyAnalysisArray: EnedisMonthlyAnalysisData[] = [ year: 2021, minimumLoad: 3, maxPower: 2, + offPeakHoursRatio: null, }, { weekDaysHalfHourAverageValues: [0.35, 0.34, 0.33, 0.32, 0.31, 0.3], @@ -31,6 +33,7 @@ export const mockEnedisMonthlyAnalysisArray: EnedisMonthlyAnalysisData[] = [ year: 2021, minimumLoad: 3, maxPower: 2, + offPeakHoursRatio: null, }, { weekDaysHalfHourAverageValues: [0.35, 0.34, 0.33, 0.32, 0.31, 0.3], @@ -39,6 +42,7 @@ export const mockEnedisMonthlyAnalysisArray: EnedisMonthlyAnalysisData[] = [ year: 2021, minimumLoad: 3, maxPower: 2, + offPeakHoursRatio: null, }, { weekDaysHalfHourAverageValues: [0.35, 0.34, 0.33, 0.32, 0.31, 0.3], @@ -47,6 +51,7 @@ export const mockEnedisMonthlyAnalysisArray: EnedisMonthlyAnalysisData[] = [ year: 2021, minimumLoad: 3, maxPower: 2, + offPeakHoursRatio: null, }, ] diff --git a/tests/__mocks__/fluidPrice.mock.ts b/tests/__mocks__/fluidPrice.mock.ts index 63f6b6f56..b93fac787 100644 --- a/tests/__mocks__/fluidPrice.mock.ts +++ b/tests/__mocks__/fluidPrice.mock.ts @@ -7,6 +7,7 @@ export const fluidPrices: FluidPrice[] = [ fluidType: 0, price: 0.1429, startDate: '2020-08-01T00:00:00.000Z', + UpdatedAt: '', }, { _id: '03045ea1afecc7a86e5443a52e00b07d', @@ -14,6 +15,7 @@ export const fluidPrices: FluidPrice[] = [ fluidType: 0, price: 0.1529, startDate: '2021-01-01T00:00:00.000Z', + UpdatedAt: '', }, { _id: '03045ea1afecc7a86e5443a52e00b07d', @@ -21,6 +23,7 @@ export const fluidPrices: FluidPrice[] = [ fluidType: 0, price: 0.1329, startDate: '2021-10-10T00:00:00.000Z', + UpdatedAt: '', }, { _id: '03045ea1afecc7a86e5443a52e00b07d', @@ -28,6 +31,7 @@ export const fluidPrices: FluidPrice[] = [ fluidType: 1, price: 0.0039, startDate: '2013-08-01T00:00:00.000Z', + UpdatedAt: '', }, { _id: '03045ea1afecc7a86e5443a52e00b07d', @@ -35,6 +39,7 @@ export const fluidPrices: FluidPrice[] = [ fluidType: 2, price: 1.029, startDate: '2013-08-01T00:00:00.000Z', + UpdatedAt: '', }, { _id: '03045ea1afecc7a86e5443a52e00b07d', @@ -42,6 +47,7 @@ export const fluidPrices: FluidPrice[] = [ fluidType: 2, price: 1.029, startDate: '2014-11-01T00:00:00.000Z', + UpdatedAt: '', }, ] @@ -52,6 +58,7 @@ export const allLastFluidPrices: FluidPrice[] = [ fluidType: 0, price: 0.1329, startDate: '2021-10-10T00:00:00.000Z', + UpdatedAt: '', }, { _id: '03045ea1afecc7a86e5443a52e00b07d', @@ -59,6 +66,7 @@ export const allLastFluidPrices: FluidPrice[] = [ fluidType: 1, price: 0.0039, startDate: '2013-08-01T00:00:00.000Z', + UpdatedAt: '', }, { _id: '03045ea1afecc7a86e5443a52e00b07d', @@ -66,5 +74,6 @@ export const allLastFluidPrices: FluidPrice[] = [ fluidType: 2, price: 1.029, startDate: '2014-11-01T00:00:00.000Z', + UpdatedAt: '', }, ] diff --git a/tests/__mocks__/fluidStatusData.mock.ts b/tests/__mocks__/fluidStatusData.mock.ts index eb1338c76..2943514e3 100644 --- a/tests/__mocks__/fluidStatusData.mock.ts +++ b/tests/__mocks__/fluidStatusData.mock.ts @@ -194,18 +194,6 @@ export const SgeStatusWithAccount: FluidStatus = { _rev: '1-88e68b8450cee09fe2f077610901094d', account_type: 'enedissgegrandlyon', name: '', - oauth: { - access_token: 'MY_ACCESS_TOKEN', - expires_at: '2020-10-09T08:00:00.285910671+02:00', - refresh_token: '', - token_type: 'Bearer', - }, - oauth_callback_results: { - issued_at: '1592232569642', - refresh_token_issued_at: '1592232569642', - scope: '/my_enedis_scope', - usage_points_id: '', - }, cozyMetadata: { createdAt: '2020-11-10T16:42:11.132Z', metadataVersion: 1, -- GitLab