diff --git a/src/components/Charts/Bar.tsx b/src/components/Charts/Bar.tsx index fbb7a306d8bc98ee28fa2af669490e16770d7c45..3c7937f9317277fb4ede37c26e44c7791e226220 100644 --- a/src/components/Charts/Bar.tsx +++ b/src/components/Charts/Bar.tsx @@ -54,6 +54,7 @@ const Bar = ({ : fluidTypes.length > 1 ? 'MULTIFLUID' : FluidType[fluidTypes[0]] + const handleClick = () => { if (!isSwitching) { setClicked(true) @@ -65,6 +66,7 @@ const Bar = ({ setClicked(false) setAnimationEnded(true) } + const onCompareAnimationEnd = () => { setClicked(false) setCompareAnimationEnded(true) @@ -115,17 +117,17 @@ const Bar = ({ } const topRoundedRect = ( - x: number, - y: number, - width: number, - height: number - ) => { - const radius = height > 4 ? 4 : height / 4 + _x: number, + _y: number, + _width: number, + _height: number + ): string => { + const radius = _height > 4 ? 4 : _height / 4 return ( 'M' + - x + + _x + ',' + - (y + radius) + + (_y + radius) + ' a' + radius + ',' + @@ -135,7 +137,7 @@ const Bar = ({ ',' + -radius + 'h' + - (width - 2 * radius) + + (_width - 2 * radius) + 'a' + radius + ',' + @@ -145,9 +147,9 @@ const Bar = ({ ',' + radius + 'v' + - (height - radius) + + (_height - radius) + 'h' + - -width + + -_width + 'z' ) } @@ -157,7 +159,7 @@ const Bar = ({ setClicked(true) handleClickData(dataload, compareDataload) } - }, [selectedDate.toString()]) + }, [compareDataload, dataload, handleClickData, isSelectedDate]) return ( <g> diff --git a/src/components/Charts/Hash.tsx b/src/components/Charts/Hash.tsx deleted file mode 100644 index 6ece3d347da1164cf1d2646112d5868691881683..0000000000000000000000000000000000000000 --- a/src/components/Charts/Hash.tsx +++ /dev/null @@ -1,129 +0,0 @@ -import React, { useState, useEffect } from 'react' -import { ScaleBand } from 'd3-scale' -import { DateTime } from 'luxon' - -import { TimeStep } from 'enum/timeStep.enum' -import { Datachart } from 'models' -import { TimePeriod } from 'models' -import DateChartService from 'services/dateChart.service' - -interface HashProps { - challengePeriod: TimePeriod | null - multiFluid: boolean - xScale: ScaleBand<string> - padding: number - width: number - height: number - chartData: Datachart -} - -const Hash = (props: HashProps) => { - const { - challengePeriod, - multiFluid, - xScale, - padding, - width, - height, - chartData, - } = props - - /* - number array with - - the start position of the area - - the width of the area - */ - const [scale, setScale] = useState<number[]>([]) - - useEffect(() => { - function loadScale() { - if (challengePeriod) { - const startScale = xScale( - challengePeriod.startDate - .startOf('day') - .toLocaleString(DateTime.DATETIME_SHORT) - ) - const endScale = xScale( - challengePeriod.endDate - .startOf('day') - .toLocaleString(DateTime.DATETIME_SHORT) - ) - - if (!startScale && !endScale) { - const lastGraphDate = - chartData && - chartData.actualData && - chartData.actualData[chartData.actualData.length - 1] && - chartData.actualData[chartData.actualData.length - 1].date - const firstGraphDate = - chartData && - chartData.actualData && - chartData.actualData[0] && - chartData.actualData[0].date - if ( - challengePeriod.endDate > lastGraphDate && - challengePeriod.startDate < firstGraphDate - ) { - setScale([0, width - padding]) - } else { - setScale([]) - } - } else if (startScale && !endScale) { - setScale([startScale - padding, width - startScale]) - } else if (!startScale && endScale) { - const dateChartService = new DateChartService() - if ( - dateChartService.compareStepDate( - TimeStep.DAY, - challengePeriod.endDate, - chartData.actualData[0].date - ) - ) { - setScale([]) - } else { - setScale([0, endScale - padding]) - } - } else if (startScale && endScale) { - setScale([startScale - padding, endScale - startScale]) - } - } else { - setScale([]) - } - } - loadScale() - }, [xScale]) - - return ( - <g> - {scale.length > 0 && multiFluid ? ( - <g> - <g transform={`translate(${scale[0] + 1}, -40)`}> - <defs> - <pattern - id="hash" - width="8" - height="8" - patternUnits="userSpaceOnUse" - patternTransform="rotate(45)" - > - <rect width="3" height="8" fill="#255454"></rect> - </pattern> - </defs> - <rect - x="0" - y="0" - width={scale[1]} - height={height + 40} - fill="url(#hash)" - /> - </g> - <g transform={`translate(${scale[0] + 1}, ${height - 2})`}> - <rect x="0" y="0" width={scale[1]} height={2} fill="#61F0F2" /> - </g> - </g> - ) : null} - </g> - ) -} - -export default Hash diff --git a/src/components/Connection/ConnectionForm.tsx b/src/components/Connection/ConnectionForm.tsx index 31332ed049355f89f54fe948997a9ac79c398b9b..ed4a25a9bcb411893ceb93f4dfc4a284962fcf32 100644 --- a/src/components/Connection/ConnectionForm.tsx +++ b/src/components/Connection/ConnectionForm.tsx @@ -3,7 +3,7 @@ import { useClient } from 'cozy-client' import { useDispatch } from 'react-redux' import { updateProfile } from 'store/profile/profile.actions' -import { Konnector, Trigger, FluidConfig } from 'models' +import { Account, Konnector, Trigger, FluidConfig } from 'models' import ProfileService from 'services/profile.service' import ConnectionLoginForm from 'components/Connection/ConnectionLoginForm' @@ -37,12 +37,15 @@ const ConnectionForm: React.FC<ConnectionFormProps> = ({ dispatch(updateProfile(updatedProfile)) } }) - }, []) + }, [client, dispatch]) - const handleSuccess = async (_account: Account, _trigger: Trigger) => { - await updateProfileHaveSeenOldFluidModal() - handleSuccessForm(_account, _trigger) - } + const handleSuccess = useCallback( + async (_account: Account, _trigger: Trigger) => { + await updateProfileHaveSeenOldFluidModal() + handleSuccessForm(_account, _trigger) + }, + [updateProfileHaveSeenOldFluidModal, handleSuccessForm] + ) return ( <> diff --git a/src/components/Connection/ConnectionLaunch.tsx b/src/components/Connection/ConnectionLaunch.tsx index 6f9aed352c84a523dea216d9eb1c5b413d947e3c..0a221cacb6fffa3acc02cfa3da5b4f91e75dda9f 100644 --- a/src/components/Connection/ConnectionLaunch.tsx +++ b/src/components/Connection/ConnectionLaunch.tsx @@ -75,7 +75,7 @@ const ConnectionLaunch: React.FC<ConnectionLaunchProps> = ({ return () => { subscribed = false } - }, []) + }, [client, konnector, trigger]) return ( <Modal open={openModal} handleCloseClick={handleCloseClick} border={false}> diff --git a/src/components/Connection/ConnectionLoginForm.tsx b/src/components/Connection/ConnectionLoginForm.tsx index 0c6e06ed6e951b32d4c7e2e53f8ca0a84295cb08..e8a494ea285080699163a3ff08388ab4d3c388eb 100644 --- a/src/components/Connection/ConnectionLoginForm.tsx +++ b/src/components/Connection/ConnectionLoginForm.tsx @@ -18,8 +18,8 @@ import StyledIcon from 'components/CommonKit/Icon/StyledIcon' interface ConnectionLoginFormProps { fluidConfig: FluidConfig onSuccess: Function - account: Account - trigger: Trigger + account: Account | null + trigger: Trigger | null } const ConnectionLoginForm: React.FC<ConnectionLoginFormProps> = ({ @@ -62,7 +62,7 @@ const ConnectionLoginForm: React.FC<ConnectionLoginFormProps> = ({ setPassword(value) } - function revealPassword(idInput: string) { + const revealPassword = (idInput: string) => { const input = document.getElementById(idInput) if (input) { if (input.getAttribute('type') === 'password') { @@ -97,14 +97,16 @@ const ConnectionLoginForm: React.FC<ConnectionLoginFormProps> = ({ } const update = async () => { - const auth = { - login: login, - password: password, + if (account) { + const auth = { + login: login, + password: password, + } + account.auth = auth + const accountService = new AccountService(client) + const updatedAccount = await accountService.updateAccount(account) + onSuccess(updatedAccount, trigger) } - account.auth = auth - const accountService = new AccountService(client) - const updatedAccount = await accountService.updateAccount(account) - onSuccess(updatedAccount, trigger) } const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => { @@ -136,7 +138,7 @@ const ConnectionLoginForm: React.FC<ConnectionLoginFormProps> = ({ } setError(t('KONNECTORCONFIG.ERROR_LOGIN_FAILED')) } - }, []) + }, [account, t]) return ( <form diff --git a/src/components/Connection/ConnectionOAuthForm.tsx b/src/components/Connection/ConnectionOAuthForm.tsx index 40de80569fddf46aec5c99ed5cca8451f9a370bf..550f0d8d61545d06be1a9e02707249b4df2ff18c 100644 --- a/src/components/Connection/ConnectionOAuthForm.tsx +++ b/src/components/Connection/ConnectionOAuthForm.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useCallback } from 'react' import { useI18n } from 'cozy-ui/transpiled/react/I18n' import { useClient } from 'cozy-client' @@ -13,7 +13,6 @@ interface ConnectionOAuthFormProps { konnector: Konnector siteLink: string onSuccess: Function - loading: boolean } const ConnectionOAuthForm: React.FC<ConnectionOAuthFormProps> = ({ @@ -21,25 +20,28 @@ const ConnectionOAuthForm: React.FC<ConnectionOAuthFormProps> = ({ konnector, siteLink, onSuccess, - loading, }: ConnectionOAuthFormProps) => { const { t } = useI18n() const client = useClient() const konnectorSlug: string = fluidConfig.konnectorConfig.slug - const handleSuccess = async (accountId: string) => { - const accountService = new AccountService(client) - const account = await accountService.getAccount(accountId) - if (!account) { - onSuccess(null, null) - } - const triggersServices = new TriggerService(client) - const trigger: Trigger = await triggersServices.createTrigger( - account, - konnector - ) - onSuccess(account, trigger) - } + const handleSuccess = useCallback( + async (accountId: string) => { + const accountService = new AccountService(client) + const account = await accountService.getAccount(accountId) + if (!account) { + onSuccess(null, null) + } + const triggersServices = new TriggerService(client) + const trigger: Trigger = await triggersServices.createTrigger( + account, + konnector + ) + onSuccess(account, trigger) + }, + [client, konnector, onSuccess] + ) + return ( <div className="koauthform"> <p className="info-provider text-16-normal"> @@ -61,7 +63,6 @@ const ConnectionOAuthForm: React.FC<ConnectionOAuthFormProps> = ({ type="button" color="secondary" className="create-account" - disabled={loading} onClick={() => window.open(siteLink, '_blank')} > {t('auth.' + konnector.slug + '.create_account')} diff --git a/src/components/Connection/ConnectionResult.tsx b/src/components/Connection/ConnectionResult.tsx index 0f50415added5e7a7d04d084ddc082532520c2db..769b85633c6730ac21fb813c58182d38b0653fa3 100644 --- a/src/components/Connection/ConnectionResult.tsx +++ b/src/components/Connection/ConnectionResult.tsx @@ -43,13 +43,13 @@ const ConnectionResult: React.FC<ConnectionResultProps> = ({ const [konnectorError, setKonnectorError] = useState<string>('') const [status, setStatus] = useState<string>('') - const refreshFluidState = async () => { + const refreshFluidState = useCallback(async () => { const fluidService = new FluidService(client) const fluidStatus = await fluidService.getFluidStatus() if (fluidStatus) { dispatch(setFluidStatus(fluidStatus)) } - } + }, [client, dispatch]) const updateProfileHaveSeenOldFluidModal = useCallback(async () => { const profileService = new ProfileService(client) @@ -60,28 +60,31 @@ const ConnectionResult: React.FC<ConnectionResultProps> = ({ dispatch(updateProfile(updatedProfile)) } }) - }, []) + }, [client, dispatch]) - const updateState = async (_trigger: Trigger) => { - const triggerService = new TriggerService(client) - const triggerState = await triggerService.fetchTriggerState(_trigger) + const updateState = useCallback( + async (_trigger: Trigger) => { + const triggerService = new TriggerService(client) + const triggerState = await triggerService.fetchTriggerState(_trigger) - if (triggerState) { - if (triggerState.last_success) { - setLastExecutionDate( - new Date(triggerState.last_success).toLocaleString() - ) - } else { - setLastExecutionDate('-') - } - if (triggerState.status === 'errored' && triggerState.last_error) { - setKonnectorError(getKonnectorUpdateError(triggerState.last_error)) + if (triggerState) { + if (triggerState.last_success) { + setLastExecutionDate( + new Date(triggerState.last_success).toLocaleString() + ) + } else { + setLastExecutionDate('-') + } + if (triggerState.status === 'errored' && triggerState.last_error) { + setKonnectorError(getKonnectorUpdateError(triggerState.last_error)) + } + setStatus(triggerState.status) + handleJobState(triggerState.status) + await refreshFluidState() } - setStatus(triggerState.status) - handleJobState(triggerState.status) - await refreshFluidState() - } - } + }, + [client, handleJobState, refreshFluidState] + ) const callbackResponse = async () => { if (trigger) { @@ -141,7 +144,7 @@ const ConnectionResult: React.FC<ConnectionResultProps> = ({ return () => { subscribed = false } - }, []) + }, [account, client, konnector, updateState]) return ( <div className="accordion-update-result"> diff --git a/src/components/Connection/OAuthForm.tsx b/src/components/Connection/OAuthForm.tsx index bf68d6ad2946237984910189363dd9334baab1ac..29643099a035586e14dd09a8488508e2de9e9160 100644 --- a/src/components/Connection/OAuthForm.tsx +++ b/src/components/Connection/OAuthForm.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react' +import React, { useCallback, useState } from 'react' import { useI18n } from 'cozy-ui/transpiled/react/I18n' import { useClient } from 'cozy-client' @@ -17,7 +17,6 @@ import StyledBlackSpinner from 'components/CommonKit/Spinner/StyledBlackSpinner' interface OAuthFormProps { konnector: Konnector onSuccess: Function - loginFailed: boolean } const OAuthForm: React.FC<OAuthFormProps> = ({ @@ -31,22 +30,25 @@ const OAuthForm: React.FC<OAuthFormProps> = ({ const client = useClient() const [status, setStatus] = useState<string>(IDLE) - function endOAuth() { + const endOAuth = () => { setStatus(IDLE) } - function startOAuth() { + const startOAuth = () => { setStatus(WAITING) } - function handleAccountId(accountId: string) { - endOAuth() - onSuccess(accountId) - } - function handleSubmit() { + const handleAccountId = useCallback( + (accountId: string) => { + endOAuth() + onSuccess(accountId) + }, + [onSuccess] + ) + const handleSubmit = () => { startOAuth() } - function handleOAuthCancel() { + const handleOAuthCancel = useCallback(() => { endOAuth() - } + }, []) const fluidconfig = new ConfigService().getFluidConfig() const icon = diff --git a/src/components/ConsumptionVisualizer/ConsumptionVisualizer.tsx b/src/components/ConsumptionVisualizer/ConsumptionVisualizer.tsx index cf8e1b3159b45f2b97a03ffcac8f1cf1bff896ab..ad0b3b4fca4f3372fc8e586b4f5e05e85f8463c9 100644 --- a/src/components/ConsumptionVisualizer/ConsumptionVisualizer.tsx +++ b/src/components/ConsumptionVisualizer/ConsumptionVisualizer.tsx @@ -1,5 +1,4 @@ import React from 'react' -import { useI18n } from 'cozy-ui/transpiled/react/I18n' import { FluidType } from 'enum/fluid.enum' import { DateTime } from 'luxon' @@ -49,7 +48,6 @@ const ConsumptionVisualizer = ({ handleClickDetails, handleChangeIndex, }: ConsumptionVisualizerProps) => { - const { t } = useI18n() const dateChartService = new DateChartService() return ( <div className="cv"> diff --git a/src/components/ConsumptionVisualizer/DataloadConsumptionVisualizer.tsx b/src/components/ConsumptionVisualizer/DataloadConsumptionVisualizer.tsx index 0bb51fb93139e30c689fbcf65a3891df55544875..6c17b3cf38c80d9543c2c8b6d27266cd563ea678 100644 --- a/src/components/ConsumptionVisualizer/DataloadConsumptionVisualizer.tsx +++ b/src/components/ConsumptionVisualizer/DataloadConsumptionVisualizer.tsx @@ -20,8 +20,6 @@ interface DataloadConsumptionVisualizerProps { multiFluid: boolean lastDataDate: DateTime isLoaded: boolean - handleClickMove: (increment: number) => void - handleClickDetails: () => void } const DataloadConsumptionVisualizer = ({ fluidTypes, @@ -66,7 +64,7 @@ const DataloadConsumptionVisualizer = ({ setHasCompareData(false) } } - }, [dataload, showCompare]) + }, [dataload, showCompare, compareDataload, multiFluid]) return ( <div className="cv-load"> {isLoaded && hasData ? ( diff --git a/src/components/ConsumptionVisualizer/ErrorDataConsumptionVisualizer.tsx b/src/components/ConsumptionVisualizer/ErrorDataConsumptionVisualizer.tsx index 729bb0188151a76a9d816f10473d1698130bb262..4e0b09de54048ec3a5051f11579e5834711c0eb6 100644 --- a/src/components/ConsumptionVisualizer/ErrorDataConsumptionVisualizer.tsx +++ b/src/components/ConsumptionVisualizer/ErrorDataConsumptionVisualizer.tsx @@ -6,7 +6,6 @@ import StyledIcon from 'components/CommonKit/Icon/StyledIcon' interface ErrorDataConsumptionVisualizerProps { lastDateWithAllData: DateTime - handleChangeIndex: (index: number) => void indexDisplayed: number setSelectedDate: Function setIndexDisplayed: Function diff --git a/src/components/Content/Content.tsx b/src/components/Content/Content.tsx index 0d8b0e9462b8953573fe02e309515653b34bf295..d865f18ee08a1422b86ee13357c5128d2fe99a3c 100644 --- a/src/components/Content/Content.tsx +++ b/src/components/Content/Content.tsx @@ -35,12 +35,12 @@ const Content: React.FC<ContentProps> = ({ const { screenType } = useSelector((state: EcolyoState) => state.global) const profile = useSelector((state: EcolyoState) => state.profile) const modalState = useSelector((state: EcolyoState) => state.modal) - const mailService = new MailService() const cozyBarHeight = 48 const cozyNavHeight = 56 const setWelcomeModalViewed = useCallback(async () => { + const mailService = new MailService() let username = '' // TODO Move this code to Mail Service const settings = await client @@ -75,7 +75,7 @@ const Content: React.FC<ContentProps> = ({ dispatch(setFirstConnection(false)) } }) - }, []) + }, [client, dispatch]) const setFavoriteModalViewed = useCallback(async () => { const profileService = new ProfileService(client) @@ -86,11 +86,11 @@ const Content: React.FC<ContentProps> = ({ dispatch(updateProfile(updatedProfile)) } }) - }, []) + }, [client, dispatch]) - const handleFeedbackModalClose = () => { + const handleFeedbackModalClose = useCallback(() => { dispatch(updateModalIsFeedbacksOpen(false)) - } + }, [dispatch]) useEffect(() => { const unlisten = history.listen(() => { @@ -116,7 +116,7 @@ const Content: React.FC<ContentProps> = ({ return () => { window.removeEventListener('resize', handleResize) } - }, []) + }, [dispatch]) return ( <> diff --git a/src/components/Duel/DuelView.tsx b/src/components/Duel/DuelView.tsx index 3aa1fca28beaeab46cc534bc981f008dc428399e..a8c296e64287e9373ce3f850123e311a73b427ec 100644 --- a/src/components/Duel/DuelView.tsx +++ b/src/components/Duel/DuelView.tsx @@ -16,11 +16,11 @@ const DuelView: React.FC = () => { const [headerHeight, setHeaderHeight] = useState<number>(0) const { currentSeason } = useSelector((state: EcolyoState) => state.season) - const defineHeaderHeight = (height: number) => { + const defineHeaderHeight = useCallback((height: number) => { setHeaderHeight(height) - } + }, []) - const renderDuel = useCallback((season: UserSeason) => { + const renderDuel = (season: UserSeason) => { switch (season.boss.state) { case UserBossState.UNLOCKED: return <DuelUnlocked userSeason={season} /> @@ -29,7 +29,7 @@ const DuelView: React.FC = () => { default: return <DuelError /> } - }, []) + } return ( <> diff --git a/src/components/Ecogesture/EcogestureCard.tsx b/src/components/Ecogesture/EcogestureCard.tsx index 1c7d6e124ed6624fe6d01ab2d4f671e5c94d48c0..8895da956e78b9dbc287ce0c586459428b4cc788 100644 --- a/src/components/Ecogesture/EcogestureCard.tsx +++ b/src/components/Ecogesture/EcogestureCard.tsx @@ -35,7 +35,7 @@ const EcogestureCard: React.FC<EcogestureCardProps> = ({ if (ecogesture) { importEcogestureIcon(ecogesture.id) } - }, []) + }, [ecogesture]) return ( <> diff --git a/src/components/Ecogesture/EcogestureList.tsx b/src/components/Ecogesture/EcogestureList.tsx index 2dafa954ff0c5dd6c9f9d3244782a4e34ebf421e..c6c6506f9d7eed939721deb516693e73920eea8e 100644 --- a/src/components/Ecogesture/EcogestureList.tsx +++ b/src/components/Ecogesture/EcogestureList.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react' +import React, { useState, useEffect, useCallback } from 'react' import { useI18n } from 'cozy-ui/transpiled/react/I18n' import { useClient } from 'cozy-client' @@ -33,16 +33,15 @@ const EcogesturesList: React.FC = () => { const [filterbyFluid, setfilterbyFluid] = useState<FluidType | null>(null) const [ascendingSort, setascendingSort] = useState(false) const [openDropDown, setopenDropDown] = useState(false) - const ecogestureService = new EcogestureService(client) const handleClick = (ecogesture: Ecogesture) => { setSelectedEcogesture(ecogesture) setOpenEcogestureModal(true) } - const handleCloseClick = () => { + const handleCloseClick = useCallback(() => { setOpenEcogestureModal(false) - } + }, []) const handleNegaWattClick = () => { setOpenNegaWattModal(true) @@ -72,6 +71,7 @@ const EcogesturesList: React.FC = () => { useEffect(() => { let subscribed = true async function loadEcogestures() { + const ecogestureService = new EcogestureService(client) const dataAll = await ecogestureService.getAllEcogestures() if (subscribed && dataAll) { setEcogestures(dataAll) @@ -81,7 +81,7 @@ const EcogesturesList: React.FC = () => { return () => { subscribed = false } - }, []) + }, [client]) return ( <div className="ecogesture-root"> diff --git a/src/components/FAQ/FAQView.spec.tsx b/src/components/FAQ/FAQView.spec.tsx index 41ddd415f519a7e1fff2300cc1b04bc23122544f..0cf009bf050a365e30a9e57b179ffbe328304f2f 100644 --- a/src/components/FAQ/FAQView.spec.tsx +++ b/src/components/FAQ/FAQView.spec.tsx @@ -1,5 +1,5 @@ import React from 'react' -import { shallow, ShallowWrapper } from 'enzyme' +import { shallow } from 'enzyme' import FAQView from 'components/FAQ/FAQView' jest.mock('cozy-ui/transpiled/react/I18n', () => { diff --git a/src/components/Favorite/FavoriteModal.tsx b/src/components/Favorite/FavoriteModal.tsx index 32869fb21815b7e152128e282e6bbd1c19edc630..7c474a97bcdc0f913515e26262e433f1a061cedd 100644 --- a/src/components/Favorite/FavoriteModal.tsx +++ b/src/components/Favorite/FavoriteModal.tsx @@ -1,8 +1,7 @@ -import React, { useEffect, useState } from 'react' +import React, { useCallback, useEffect, useState } from 'react' import { useI18n } from 'cozy-ui/transpiled/react/I18n' import Modal from 'components/CommonKit/Modal/Modal' import StyledButton from 'components/CommonKit/Button/StyledButton' -import userInstanceSettings from 'components/Hooks/userInstanceSettings' interface FavoriteModalContainerProps { open: boolean @@ -17,7 +16,7 @@ const FavoriteModalContainer: React.FC<FavoriteModalContainerProps> = ({ const [isEventListener, setIsEventListener] = useState(false) const { t } = useI18n() - const handleAddToFavorite = () => { + const handleAddToFavorite = useCallback(() => { if (window.sidebar && window.sidebar.addPanel) { // Firefox <23 window.sidebar.addPanel(document.title, window.location.href, '') @@ -46,7 +45,8 @@ const FavoriteModalContainer: React.FC<FavoriteModalContainerProps> = ({ } // If you have something in the `href` of your trigger return false - } + }, []) + useEffect(() => { if (!isEventListener) { handleAddToFavorite() @@ -57,7 +57,7 @@ const FavoriteModalContainer: React.FC<FavoriteModalContainerProps> = ({ }) setIsEventListener(true) } - }) + }, [isEventListener, handleAddToFavorite]) return ( <React.Fragment> <Modal diff --git a/src/components/Feedback/FeedbackModal.spec.tsx b/src/components/Feedback/FeedbackModal.spec.tsx index de58026fb6a8a1ab3b611918722fabdd347a854c..e0e148371c29ea10985105ec3742041aa84add7b 100644 --- a/src/components/Feedback/FeedbackModal.spec.tsx +++ b/src/components/Feedback/FeedbackModal.spec.tsx @@ -2,7 +2,6 @@ import React from 'react' import { shallow } from 'enzyme' import FeedbackModal from 'components/Feedback/FeedbackModal' import StyledButton from 'components/CommonKit/Button/StyledButton' -import { useClient } from 'cozy-client' import Modal from 'components/CommonKit/Modal/Modal' import StyledIconButton from 'components/CommonKit/IconButton/StyledIconButton' diff --git a/src/components/FluidChart/FluidChart.tsx b/src/components/FluidChart/FluidChart.tsx index 033d259c8c730c3911c33c65126aba6886748815..2ab7a96b9daa98fb3fd8b0ae31dd10094adff57b 100644 --- a/src/components/FluidChart/FluidChart.tsx +++ b/src/components/FluidChart/FluidChart.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react' +import React, { useState, useEffect, useCallback } from 'react' import { useClient } from 'cozy-client' import { DateTime } from 'luxon' @@ -35,16 +35,18 @@ const FluidChart: React.FC<FluidChartProps> = ({ const [referenceDate, setReferenceDate] = useState<DateTime>(DateTime.local()) const [isLoaded, setIsLoaded] = useState<boolean>(false) - const consumptionService = new ConsumptionService(client) - - const handleDetailedDate = (date: DateTime, _timeStep: TimeStep) => { - setReferenceDate(date) - handleClickTimeStep(_timeStep) - } + const handleDetailedDate = useCallback( + (date: DateTime, _timeStep: TimeStep) => { + setReferenceDate(date) + handleClickTimeStep(_timeStep) + }, + [handleClickTimeStep] + ) useEffect(() => { let subscribed = true async function loadData() { + const consumptionService = new ConsumptionService(client) const activateHalfHourLoad = !(await consumptionService.checkDoctypeEntries( FluidType.ELECTRICITY, TimeStep.HALF_AN_HOUR @@ -72,7 +74,7 @@ const FluidChart: React.FC<FluidChartProps> = ({ return () => { subscribed = false } - }, []) + }, [client, fluidTypes, setChartLoaded]) useEffect(() => { let subscribed = true @@ -87,7 +89,7 @@ const FluidChart: React.FC<FluidChartProps> = ({ return () => { subscribed = false } - }, [resetReferenceDate]) + }, [resetReferenceDate, lastDataDate, setChartLoaded]) return ( <> diff --git a/src/components/FluidChart/FluidChartContent.tsx b/src/components/FluidChart/FluidChartContent.tsx index 7229c22dba559e528ab05618a7cb4732ee1f29f5..2790d0bea1c8df8a809621e62baba5c6f6fa39c7 100644 --- a/src/components/FluidChart/FluidChartContent.tsx +++ b/src/components/FluidChart/FluidChartContent.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react' +import React, { useState, useEffect, useCallback } from 'react' import { useI18n } from 'cozy-ui/transpiled/react/I18n' import { DateTime } from 'luxon' @@ -48,30 +48,33 @@ const FluidChartContent: React.FC<FluidChartContentProps> = ({ const [showCompare, setShowCompare] = useState<boolean>(false) const [isLoaded, setIsLoaded] = useState<boolean>(true) - const handleChangeIndex = (index: number) => { - const dateChartService = new DateChartService() - const date = - index === 0 - ? referenceDate - : dateChartService.defineLastStepDate(referenceDate, timeStep, index) - setSelectedDate(date) - setIndexDisplayed(index) - setIsLoaded(false) - } + const handleChangeIndex = useCallback( + (index: number) => { + const dateChartService = new DateChartService() + const date = + index === 0 + ? referenceDate + : dateChartService.defineLastStepDate(referenceDate, timeStep, index) + setSelectedDate(date) + setIndexDisplayed(index) + setIsLoaded(false) + }, + [referenceDate, timeStep] + ) - const handleClickData = ( - dataload: Dataload, - compareDataload: Dataload | null - ) => { - setSelectedDate(dataload.date) - setSelectedDataload(dataload) - if (compareDataload) { - setSelectedComparedataload(compareDataload) - } - setIsLoaded(true) - } + const handleClickData = useCallback( + (dataload: Dataload, compareDataload: Dataload | null) => { + setSelectedDate(dataload.date) + setSelectedDataload(dataload) + if (compareDataload) { + setSelectedComparedataload(compareDataload) + } + setIsLoaded(true) + }, + [] + ) - const handleClickDetails = () => { + const handleClickDetails = useCallback(() => { const dateChartService = new DateChartService() const detailedTimeStep = dateChartService.defineDetailedTimeStep( timeStep, @@ -83,22 +86,28 @@ const FluidChartContent: React.FC<FluidChartContentProps> = ({ ) handleDetailedDate(detailedDate, detailedTimeStep) setIsLoaded(false) - } + }, [fluidTypes, handleDetailedDate, selectedDate, timeStep]) - const handleClickMove = (increment: number) => { - const dateChartService = new DateChartService() - const { incrementIndex, incrementedDate } = dateChartService.incrementDate( - increment, - selectedDate, - timeStep, - lastDataDate - ) - setSelectedDate(incrementedDate) - if (incrementIndex != 0) { - setIndexDisplayed(indexDisplayed + incrementIndex) - setIsLoaded(false) - } - } + const handleClickMove = useCallback( + (increment: number) => { + const dateChartService = new DateChartService() + const { + incrementIndex, + incrementedDate, + } = dateChartService.incrementDate( + increment, + selectedDate, + timeStep, + lastDataDate + ) + setSelectedDate(incrementedDate) + if (incrementIndex != 0) { + setIndexDisplayed(indexDisplayed + incrementIndex) + setIsLoaded(false) + } + }, + [indexDisplayed, lastDataDate, selectedDate, timeStep] + ) const handleChangeSwitch = () => { setShowCompare(!showCompare) diff --git a/src/components/FluidChart/FluidChartSlide.tsx b/src/components/FluidChart/FluidChartSlide.tsx index 9d3c47ff07f70e35bb359072ddd75caa77f94c99..0f3ca01e7a4c153b8d635af46590f523aabe8c59 100644 --- a/src/components/FluidChart/FluidChartSlide.tsx +++ b/src/components/FluidChart/FluidChartSlide.tsx @@ -116,7 +116,7 @@ const FluidChartSlide: React.FC<FluidChartSlideProps> = ({ return () => { subscribed = false } - }, [timeStep, fluidTypes]) + }, [timeStep, fluidTypes, client, dispatch, index, isHome, referenceDate]) return ( <> diff --git a/src/components/FluidChart/FluidChartSwipe.tsx b/src/components/FluidChart/FluidChartSwipe.tsx index 413de2f96785fdced2f8da5edfe3f84230c4fac4..bb612c347438501844f206d0983cc04684e6cecf 100644 --- a/src/components/FluidChart/FluidChartSwipe.tsx +++ b/src/components/FluidChart/FluidChartSwipe.tsx @@ -62,7 +62,7 @@ const FluidChartSwipe: React.FC<FluidChartSwipeProps> = ({ handleResize() window.addEventListener('resize', handleResize) return () => window.removeEventListener('resize', handleResize) - }, [swipe.current]) + }, []) return ( <div className="fs-root" ref={swipe}> diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx index 5e4ecd59b4f00e6a50879909fe6c418379fbf80d..7d059bb088d2b9bb824085de310f4c1e767fb3e1 100644 --- a/src/components/Header/Header.tsx +++ b/src/components/Header/Header.tsx @@ -1,9 +1,9 @@ -import React, { useEffect, useRef } from 'react' +import React, { useCallback, useEffect, useRef } from 'react' import { useI18n } from 'cozy-ui/transpiled/react/I18n' import { useSelector, useDispatch } from 'react-redux' import { EcolyoState } from 'store' import { updateModalIsFeedbacksOpen } from 'store/modal/modal.actions' -import { history } from 'components/App' +import { useHistory } from 'react-router-dom' import { ScreenType } from 'enum/screen.enum' @@ -27,6 +27,7 @@ const Header: React.FC<HeaderProps> = ({ setHeaderHeight, }: HeaderProps) => { const { t } = useI18n() + const history = useHistory() const header = useRef(null) const dispatch = useDispatch() const { screenType } = useSelector((state: EcolyoState) => state.global) @@ -34,9 +35,9 @@ const Header: React.FC<HeaderProps> = ({ const cozyBarHeight = 48 const headerBottomHeight = 8 - const handleClickBack = () => { + const handleClickBack = useCallback(() => { history.goBack() - } + }, [history]) const handleClickFeedbacks = () => { dispatch(updateModalIsFeedbacksOpen(true)) @@ -54,7 +55,7 @@ const Header: React.FC<HeaderProps> = ({ header.current ? header.current.clientHeight - headerBottomHeight : 0 ) } - }, [screenType, children]) + }, [screenType, children, setHeaderHeight]) return ( <div className="header" ref={header}> diff --git a/src/components/Home/HomeIndicators.tsx b/src/components/Home/HomeIndicators.tsx index c20d692e60f5bcf5dc0872b735230fe822874ba6..edd8dc49316ed46bc57cef24e8fb16ae16e6bbef 100644 --- a/src/components/Home/HomeIndicators.tsx +++ b/src/components/Home/HomeIndicators.tsx @@ -82,7 +82,7 @@ const HomeIndicators: React.FC<HomeIndicatorsProps> = ({ return () => { subscribed = false } - }, [timeStep, fluidTypes]) + }, [timeStep, fluidTypes, client, setIndicatorsLoaded]) return ( <> diff --git a/src/components/Home/HomeView.tsx b/src/components/Home/HomeView.tsx index 6509b7fedb3c0cfdeda477e923613ebcfd80778f..dd9d98adfa3c2b438509da8d734b4919789d66c2 100644 --- a/src/components/Home/HomeView.tsx +++ b/src/components/Home/HomeView.tsx @@ -49,32 +49,38 @@ const HomeView: React.FC = () => { dispatch(updateProfile(updatedProfile)) } }) - }, []) + }, [client, dispatch]) - const setChartLoaded = () => { + const setChartLoaded = useCallback(() => { setChartLoading(false) - } + }, []) - const setIndicatorsLoaded = () => { + const setIndicatorsLoaded = useCallback(() => { setIndicatorsLoading(false) - } + }, []) - const handleClickTimeStepForNavigation = (_timeStep: TimeStep) => { - setResetReferenceDate(true) - setTimeStep(_timeStep) - dispatch(setPreviousTimeStep(_timeStep)) - } + const handleClickTimeStepForNavigation = useCallback( + (_timeStep: TimeStep) => { + setResetReferenceDate(true) + setTimeStep(_timeStep) + dispatch(setPreviousTimeStep(_timeStep)) + }, + [dispatch] + ) - const handleClickTimeStepForFluidContainer = (_timeStep: TimeStep) => { - setResetReferenceDate(false) - setTimeStep(_timeStep) - } + const handleClickTimeStepForFluidContainer = useCallback( + (_timeStep: TimeStep) => { + setResetReferenceDate(false) + setTimeStep(_timeStep) + }, + [] + ) const defineHeaderHeight = (height: number) => { setHeaderHeight(height) } - const checkFluidDataPeriod = async () => { + const checkFluidDataPeriod = useCallback(async () => { for (const fluid of fluidStatus) { let diffInDays = 0 if (fluid && fluid.lastDataDate) { @@ -104,18 +110,23 @@ const HomeView: React.FC = () => { } else return setopenOldFluidDataModal(false) } } - } - - const handleCloseClick = () => { + }, [ + fluidOldData, + fluidStatus, + profile.haveSeenOldFluidModal, + updateProfileHaveSeenOldFluidModal, + ]) + + const handleCloseClick = useCallback(() => { setopenOldFluidDataModal(false) - } + }, []) useEffect(() => { async function checkData() { await checkFluidDataPeriod() } checkData() - }, [fluidStatus]) + }, [fluidStatus, checkFluidDataPeriod]) return ( <React.Fragment> diff --git a/src/components/Home/OldFluidDataModal.spec.tsx b/src/components/Home/OldFluidDataModal.spec.tsx index fcfa7a4797f7c11e0457a7519c88797f0b309eb6..e910332329cc07e30cdec5e661442013b85cf0a3 100644 --- a/src/components/Home/OldFluidDataModal.spec.tsx +++ b/src/components/Home/OldFluidDataModal.spec.tsx @@ -1,6 +1,5 @@ -import * as React from 'react' - -import { mount, render, shallow } from 'enzyme' +import React from 'react' +import { shallow } from 'enzyme' import OldFluidDataModal from 'components/Home/OldFluidDataModal' import { FluidType } from 'enum/fluid.enum' diff --git a/src/components/Home/OldFluidDataModal.tsx b/src/components/Home/OldFluidDataModal.tsx index 11b9a21bc16e81b3893b2331b3bafaa84369bae7..a9dca0ffc1d9413bc313f0375d40c6427117d502 100644 --- a/src/components/Home/OldFluidDataModal.tsx +++ b/src/components/Home/OldFluidDataModal.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react' +import React, { useState, useEffect, useCallback } from 'react' import { useI18n } from 'cozy-ui/transpiled/react/I18n' import Modal from 'components/CommonKit/Modal/Modal' import WarnCross from 'assets/icons/ico/warn-cross.svg' @@ -28,7 +28,7 @@ const OldFluidDataModal: React.FC<OldFluidDataModalProps> = ({ const [erroredKonnectors] = useState<FluidType[]>([]) const [redirect, setRedirect] = useState(false) - const checkFluidDataDate = () => { + const checkFluidDataDate = useCallback(() => { fluidStatus && fluidStatus.length > 0 && fluidStatus.forEach(fluid => { @@ -38,12 +38,13 @@ const OldFluidDataModal: React.FC<OldFluidDataModalProps> = ({ } }) if (erroredKonnectors.length > 0) setkonnectorError(true) - } + }, [erroredKonnectors, fluidStatus]) - const redirectTrue = () => { + const redirectTrue = useCallback(() => { handleCloseClick() setRedirect(true) - } + }, [handleCloseClick]) + const redirectToKonnectors = () => { if (redirect) { return <Redirect to="/options" /> @@ -52,7 +53,8 @@ const OldFluidDataModal: React.FC<OldFluidDataModalProps> = ({ useEffect(() => { checkFluidDataDate() - }, [fluidStatus]) + }, [checkFluidDataDate]) + return ( <> <Modal open={open} handleCloseClick={handleCloseClick}> diff --git a/src/components/Konnector/KonnectorViewerCard.tsx b/src/components/Konnector/KonnectorViewerCard.tsx index 2a212d1008b3781368ab295fc914d5e139ac6c0f..7acc60717cbb139b8607f36b7297c48bb78879d5 100644 --- a/src/components/Konnector/KonnectorViewerCard.tsx +++ b/src/components/Konnector/KonnectorViewerCard.tsx @@ -1,10 +1,10 @@ -import React, { useState, useEffect, useRef } from 'react' +import React, { useState, useEffect, useRef, useCallback } from 'react' import { useI18n } from 'cozy-ui/transpiled/react/I18n' import { useClient } from 'cozy-client' import { FluidType } from 'enum/fluid.enum' import { JobState } from 'enum/jobState.enum' -import { Konnector, Trigger, TriggerState, FluidConfig } from 'models' +import { Account, Konnector, Trigger, TriggerState, FluidConfig } from 'models' import AccountService from 'services/account.service' import TriggerService from 'services/triggers.service' import { getPicto, getAddPicto, getParamPicto } from 'utils/picto' @@ -22,8 +22,7 @@ import ConnectionLaunch from 'components/Connection/ConnectionLaunch' interface KonnectorViewerCardProps { fluidConfig: FluidConfig - konnector: Konnector - + konnector: Konnector | null isParam: boolean } @@ -79,30 +78,36 @@ const KonnectorViewerCard: React.FC<KonnectorViewerCardProps> = ({ ) } - const updateState = async (_trigger: Trigger) => { - const triggerService = new TriggerService(client) - const _triggerState = await triggerService.fetchTriggerState(_trigger) - if (_triggerState) { - setTriggerState(_triggerState) - } - } + const updateState = useCallback( + async (_trigger: Trigger) => { + const triggerService = new TriggerService(client) + const _triggerState = await triggerService.fetchTriggerState(_trigger) + if (_triggerState) { + setTriggerState(_triggerState) + } + }, + [client] + ) - const handleSuccessForm = (_account: Account, _trigger: Trigger) => { - setAccount(_account) - setTrigger(_trigger) - setLaunch(true) - } + const handleSuccessForm = useCallback( + (_account: Account, _trigger: Trigger) => { + setAccount(_account) + setTrigger(_trigger) + setLaunch(true) + }, + [] + ) - const handleConnectionLaunch = async () => { + const handleConnectionLaunch = useCallback(async () => { if (trigger) { await updateState(trigger) } setLaunch(false) - } + }, [trigger, updateState]) - const handleJobState = (_jobState: JobState) => { + const handleJobState = useCallback((_jobState: JobState) => { setJobState(_jobState) - } + }, []) useEffect(() => { let subscribed = true @@ -127,7 +132,7 @@ const KonnectorViewerCard: React.FC<KonnectorViewerCardProps> = ({ return () => { subscribed = false } - }, []) + }, [client, konnector, updateState]) return ( <> diff --git a/src/components/Konnector/KonnectorViewerListItem.tsx b/src/components/Konnector/KonnectorViewerListItem.tsx index 3cb48f4d33583262448e91622f93cd876a288690..68b4910cb56618d85d4ed15f10036df4088391fc 100644 --- a/src/components/Konnector/KonnectorViewerListItem.tsx +++ b/src/components/Konnector/KonnectorViewerListItem.tsx @@ -23,7 +23,7 @@ const KonnectorViewerListItem: React.FC<KonnectorViewerListItemProps> = ({ let subscribed = true const konnectorService = new KonnectorService(client) async function getData() { - const _konnector: Konnector = await konnectorService.getKonnector( + const _konnector: Konnector | null = await konnectorService.getKonnector( fluidConfig.konnectorConfig.slug ) if (subscribed && _konnector) { @@ -37,7 +37,7 @@ const KonnectorViewerListItem: React.FC<KonnectorViewerListItemProps> = ({ return () => { subscribed = false } - }, []) + }, [client, fluidConfig.konnectorConfig.slug]) return ( <> diff --git a/src/components/Options/ReportOptions.tsx b/src/components/Options/ReportOptions.tsx index c4ba11a3c2ec73c70dbc673916682ee050e0548d..584e6b79cb69e5ae2a0e70f61d3a0cebe3b70bfe 100644 --- a/src/components/Options/ReportOptions.tsx +++ b/src/components/Options/ReportOptions.tsx @@ -1,4 +1,4 @@ -import React, { useCallback } from 'react' +import React from 'react' import { useI18n } from 'cozy-ui/transpiled/react/I18n' import { useClient } from 'cozy-client' import { useSelector, useDispatch } from 'react-redux' @@ -12,7 +12,7 @@ const ReportOptions: React.FC = () => { const dispatch = useDispatch() const profile = useSelector((state: EcolyoState) => state.profile) - const updateProfileReport = useCallback(async (value: boolean) => { + const updateProfileReport = async (value: boolean) => { const profileService = new ProfileService(client) await profileService .updateProfile({ sendReportNotification: value }) @@ -21,7 +21,7 @@ const ReportOptions: React.FC = () => { dispatch(updateProfile(updatedProfile)) } }) - }, []) + } const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => { e.target.value === 'true' diff --git a/src/components/PerformanceIndicator/PerformanceIndicatorContent.tsx b/src/components/PerformanceIndicator/PerformanceIndicatorContent.tsx index 1900e2ed00b34a3f77ae8eb03df118e74993aa6e..a53b6c94d8204545ca9582ed4393e3d7fdddee63 100644 --- a/src/components/PerformanceIndicator/PerformanceIndicatorContent.tsx +++ b/src/components/PerformanceIndicator/PerformanceIndicatorContent.tsx @@ -12,7 +12,6 @@ import GreenIndicatorIcon from 'assets/icons/visu/indicator/green.svg' import RedIndicatorIcon from 'assets/icons/visu/indicator/red.svg' import GreyIndicatorIcon from 'assets/icons/visu/indicator/grey.svg' import ErrorIndicatorIcon from 'assets/icons/visu/indicator/error.svg' -import NodataIndicatorIcon from 'assets/icons/visu/indicator/nodata.svg' import { FluidType } from 'enum/fluid.enum' interface PerformanceIndicatorContentProps { diff --git a/src/components/Report/MonthlyReport.tsx b/src/components/Report/MonthlyReport.tsx index 29b374c3e2d1e8e5760213261ef63aa2ece06b21..3ab06dc2daa4487f265ee4be859048573d468cb4 100644 --- a/src/components/Report/MonthlyReport.tsx +++ b/src/components/Report/MonthlyReport.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react' +import React, { useCallback, useEffect, useState } from 'react' import { useI18n } from 'cozy-ui/transpiled/react/I18n' import { useClient } from 'cozy-client' import { useSelector } from 'react-redux' @@ -41,20 +41,23 @@ const MonthlyReport: React.FC = () => { const [isLoaded, setIsLoaded] = useState<boolean>(false) const [fluidLackOfData, setFluidLackOfData] = useState<Array<FluidType>>([]) - const consumptionService = new ConsumptionService(client) - const performanceIndicatorService = new PerformanceIndicatorService() const configService = new ConfigService() const fluidConfig = configService.getFluidConfig() const timeStep = TimeStep.MONTH - const handleClickMove = (increment: number) => { - const newDate = reportDate.plus({ month: increment }) - setReportDate(newDate) - } + const handleClickMove = useCallback( + (increment: number) => { + const newDate = reportDate.plus({ month: increment }) + setReportDate(newDate) + }, + [reportDate] + ) useEffect(() => { let subscribed = true async function populateData() { + const consumptionService = new ConsumptionService(client) + const performanceIndicatorService = new PerformanceIndicatorService() const periods = { timePeriod: { startDate: reportDate.minus({ month: 1 }).startOf('month'), @@ -74,7 +77,7 @@ const MonthlyReport: React.FC = () => { if (subscribed) { if (fetchedPerformanceIndicators) { const fluidLackOfDataIndicators: Array<FluidType> = [] - fetchedPerformanceIndicators.map((fluidIndicator, index) => { + fetchedPerformanceIndicators.forEach((fluidIndicator, index) => { if (fluidIndicator.compareValue === null) { fluidLackOfDataIndicators.push(index) } @@ -94,7 +97,7 @@ const MonthlyReport: React.FC = () => { return () => { subscribed = false } - }, [timeStep, fluidTypes, reportDate]) + }, [client, timeStep, fluidTypes, reportDate]) return ( <> diff --git a/src/components/Report/ReportView.tsx b/src/components/Report/ReportView.tsx index bc6a42517d11ee66fddb3eedb988826d05f3da69..fbdd20f486797b1ada6b6bdbcb2ccc33943aaa79 100644 --- a/src/components/Report/ReportView.tsx +++ b/src/components/Report/ReportView.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react' +import React, { useState, useEffect, useCallback } from 'react' import { useClient } from 'cozy-client' import { useSelector, useDispatch } from 'react-redux' import { updateProfile } from 'store/profile/profile.actions' @@ -18,9 +18,10 @@ const ReportView: React.FC = () => { (state: EcolyoState) => state.global ) const dispatch = useDispatch() - const defineHeaderHeight = (height: number) => { + + const defineHeaderHeight = useCallback((height: number) => { setHeaderHeight(height) - } + }, []) useEffect(() => { let subscribed = true @@ -45,7 +46,7 @@ const ReportView: React.FC = () => { return () => { subscribed = false } - }, []) + }, [client, dispatch, reportNotification]) return ( <> diff --git a/src/components/Season/SeasonCard.tsx b/src/components/Season/SeasonCard.tsx index df041e5896344883d289dc8630e9ddd9a65fa8f0..adbe4b9f4e17909929a3a04eb5b7ce96db8d1b25 100644 --- a/src/components/Season/SeasonCard.tsx +++ b/src/components/Season/SeasonCard.tsx @@ -1,6 +1,6 @@ import { UserSeasonState } from 'enum/userSeason.enum' import { UserSeason } from 'models' -import React, { useCallback } from 'react' +import React from 'react' import SeasonCardDone from './SeasonCardDone' import SeasonCardLocked from './SeasonCardLocked' import SeasonCardOnGoing from './SeasonCardOnGoing' @@ -21,24 +21,21 @@ const SeasonCard: React.FC<SeasonCardProps> = ({ cardWitdh, cardHeight, }: SeasonCardProps) => { - const renderCard = useCallback( - (state: UserSeasonState) => { - switch (state) { - case UserSeasonState.LOCKED: - return <SeasonCardLocked userSeason={userSeason} /> - case UserSeasonState.UNLOCKED: - return <SeasonCardUnlocked userSeason={userSeason} /> - case UserSeasonState.DONE: - return <SeasonCardDone userSeason={userSeason} /> - case UserSeasonState.ONGOING: - case UserSeasonState.BOSS: - return <SeasonCardOnGoing userSeason={userSeason} /> - default: - return <SeasonCardLocked userSeason={userSeason} /> - } - }, - [userSeason] - ) + const renderCard = (state: UserSeasonState) => { + switch (state) { + case UserSeasonState.LOCKED: + return <SeasonCardLocked userSeason={userSeason} /> + case UserSeasonState.UNLOCKED: + return <SeasonCardUnlocked userSeason={userSeason} /> + case UserSeasonState.DONE: + return <SeasonCardDone userSeason={userSeason} /> + case UserSeasonState.ONGOING: + case UserSeasonState.BOSS: + return <SeasonCardOnGoing userSeason={userSeason} /> + default: + return <SeasonCardLocked userSeason={userSeason} /> + } + } return ( <div className={indexSlider === index ? 'slide active' : 'slide'} diff --git a/src/components/Season/SeasonCardOnGoing.tsx b/src/components/Season/SeasonCardOnGoing.tsx index 28ccd0145c0cf23a1a4f48ca3085a7dfdea31b3d..778b931be258a5063df6c8b585b8331203c547ed 100644 --- a/src/components/Season/SeasonCardOnGoing.tsx +++ b/src/components/Season/SeasonCardOnGoing.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useEffect, useState } from 'react' +import React, { useEffect, useState } from 'react' import { Client, useClient } from 'cozy-client' import { useI18n } from 'cozy-ui/transpiled/react/I18n' import { useDispatch } from 'react-redux' @@ -33,7 +33,7 @@ const SeasonCardOnGoing: React.FC<SeasonCardOnGoingProps> = ({ const history = useHistory() const [bossIcon, setBossIcon] = useState(defaultIcon) - const winStarts = useCallback(async () => { + const winStarts = async () => { const seasonService = new SeasonService(client) let progress = 0 let updateType: UpdateUserSeason @@ -49,9 +49,9 @@ const SeasonCardOnGoing: React.FC<SeasonCardOnGoingProps> = ({ updateType ) dispatch(updateUserSeasonList(updatedSeason)) - }, [client, dispatch, userSeason]) + } - const goDuel = useCallback(async () => { + const goDuel = async () => { if (userSeason.boss.state !== UserBossState.ONGOING) { const seasonService = new SeasonService(client) const updatedSeason = await seasonService.updateUserSeason( @@ -61,7 +61,7 @@ const SeasonCardOnGoing: React.FC<SeasonCardOnGoingProps> = ({ dispatch(updateUserSeasonList(updatedSeason)) } history.push('/challenges/duel') - }, [client, dispatch, userSeason, history]) + } useEffect(() => { importIconbyId(userSeason.boss.id).then(icon => { diff --git a/src/components/Season/SeasonView.spec.tsx b/src/components/Season/SeasonView.spec.tsx index 023b67c922e72fd4b69068be47cd6e95ca11defd..2ad75386267660e7471068e21fafbe92137a7e71 100644 --- a/src/components/Season/SeasonView.spec.tsx +++ b/src/components/Season/SeasonView.spec.tsx @@ -3,8 +3,8 @@ import { shallow } from 'enzyme' import SeasonView from 'components/Season/SeasonView' const mockaHandleTouchStart = jest.fn() -const mockaHandleTouchMove = jest.fn() -const mockaHandleTouchEnd = jest.fn() +// const mockaHandleTouchMove = jest.fn() +// const mockaHandleTouchEnd = jest.fn() describe('SeasonView component', () => { it('should be rendered correctly', () => { diff --git a/src/components/Season/SeasonView.tsx b/src/components/Season/SeasonView.tsx index 21b597bb7c9c2b4f103924ae9f5d4941bae5460c..7e9fa9cec00f9fbe07767cc6fb3940a6379ae93f 100644 --- a/src/components/Season/SeasonView.tsx +++ b/src/components/Season/SeasonView.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react' +import React, { useCallback, useState } from 'react' import './seasonView.scss' import { useSelector } from 'react-redux' import { EcolyoState } from 'store' @@ -37,7 +37,7 @@ const SeasonView: React.FC = () => { setTouchStart(0) } - const moveSliderRight = () => { + const moveSliderRight = useCallback(() => { if (index < userSeasonList.length - 1) { if (index === 0) setcontainerTranslation( @@ -48,8 +48,9 @@ const SeasonView: React.FC = () => { else setcontainerTranslation((prev: number) => prev - cardWitdh) setindex(prev => prev + 1) } - } - const moveSliderLeft = () => { + }, [cardWitdh, index, userSeasonList.length]) + + const moveSliderLeft = useCallback(() => { if (index > 0) { if (index >= 1) setcontainerTranslation((prev: number) => prev + cardWitdh + marginPx) @@ -59,7 +60,8 @@ const SeasonView: React.FC = () => { if (index <= 1) { setcontainerTranslation(marginPx) } - } + }, [cardWitdh, index]) + // eslint-disable-next-line @typescript-eslint/no-explicit-any const handleClickOrTouchStart = (e: any) => { if (e.nativeEvent instanceof TouchEvent) @@ -83,6 +85,7 @@ const SeasonView: React.FC = () => { } resetValues() } + // eslint-disable-next-line @typescript-eslint/no-explicit-any const handleClickOrTouchMove = (e: any) => { if (e.nativeEvent instanceof TouchEvent) diff --git a/src/components/Season/StarsContainer.tsx b/src/components/Season/StarsContainer.tsx index 95b89c1d10e1bed7b11d730ca106add7f5df2036..a3f7675924714687d23dbea85b00edbaba7a608e 100644 --- a/src/components/Season/StarsContainer.tsx +++ b/src/components/Season/StarsContainer.tsx @@ -1,5 +1,4 @@ import React from 'react' -import { useI18n } from 'cozy-ui/transpiled/react/I18n' import StyledIcon from 'components/CommonKit/Icon/StyledIcon' import starIcon from 'assets/icons/visu/season/star.svg' @@ -10,8 +9,6 @@ interface StarsContainerProps { const StarsContainer: React.FC<StarsContainerProps> = ({ starNumber, }: StarsContainerProps) => { - const { t } = useI18n() - return ( <div className="stars"> <StyledIcon className="star" icon={starIcon} /> diff --git a/src/components/SingleFluid/SingleFluidIndicators.tsx b/src/components/SingleFluid/SingleFluidIndicators.tsx index 2cb38f43500efac521dc6a8398810df474587b8d..08602d77c4435c87c8900d8b2150cc3d8bbdfc77 100644 --- a/src/components/SingleFluid/SingleFluidIndicators.tsx +++ b/src/components/SingleFluid/SingleFluidIndicators.tsx @@ -79,7 +79,7 @@ const SingleFluidIndicators: React.FC<SingleFluidIndicatorsProps> = ({ } populatePerformanceIndicators() - }, [timeStep]) + }, [timeStep, client, fluidTypes, setIndicatorsLoaded]) return ( <> @@ -95,10 +95,6 @@ const SingleFluidIndicators: React.FC<SingleFluidIndicatorsProps> = ({ performanceIndicator={performanceIndicatorService.aggregatePerformanceIndicators( performanceIndicators )} - timePeriodText={convertDateToShortDateString( - comparisonTimePeriod, - timeStep - )} timeStep={timeStep} /> diff --git a/src/components/SingleFluid/SingleFluidView.tsx b/src/components/SingleFluid/SingleFluidView.tsx index f9b0e24ece7a84467c7d8582776bff01041a53a3..0c49371a304e31df3e7490c12b394ac9d4d368b6 100644 --- a/src/components/SingleFluid/SingleFluidView.tsx +++ b/src/components/SingleFluid/SingleFluidView.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react' +import React, { useCallback, useState } from 'react' import { useSelector, useDispatch } from 'react-redux' import { EcolyoState } from 'store' import { setPreviousTimeStep } from 'store/chart/chart.actions' @@ -32,28 +32,33 @@ const SingleFluidView: React.FC<SingleFluidViewProps> = ({ const [isChartLoading, setChartLoading] = useState<boolean>(true) const [isIndicatorsLoading, setIndicatorsLoading] = useState<boolean>(true) - const setChartLoaded = () => { + const setChartLoaded = useCallback(() => { setChartLoading(false) - } + }, []) - const setIndicatorsLoaded = () => { + const setIndicatorsLoaded = useCallback(() => { setIndicatorsLoading(false) - } + }, []) - const handleClickTimeStepForNavigation = (_timeStep: TimeStep) => { - setResetReferenceDate(true) - setTimeStep(_timeStep) - dispatch(setPreviousTimeStep(_timeStep)) - } - - const handleClickTimeStepForFluidContainer = (_timeStep: TimeStep) => { - setResetReferenceDate(false) - setTimeStep(_timeStep) - } + const handleClickTimeStepForNavigation = useCallback( + (_timeStep: TimeStep) => { + setResetReferenceDate(true) + setTimeStep(_timeStep) + dispatch(setPreviousTimeStep(_timeStep)) + }, + [dispatch] + ) - const defineHeaderHeight = (height: number) => { + const handleClickTimeStepForFluidContainer = useCallback( + (_timeStep: TimeStep) => { + setResetReferenceDate(false) + setTimeStep(_timeStep) + }, + [] + ) + const defineHeaderHeight = useCallback((height: number) => { setHeaderHeight(height) - } + }, []) return ( <> diff --git a/src/components/Splash/SplashRoot.tsx b/src/components/Splash/SplashRoot.tsx index e3b5b1b8803b7282b9319d8c01ae8bd5117dadc1..89b2a56179fe1b0a17959ec80cde6bd8f653b426 100644 --- a/src/components/Splash/SplashRoot.tsx +++ b/src/components/Splash/SplashRoot.tsx @@ -35,8 +35,6 @@ const SplashRoot = ({ const [error, setError] = useState<Error | null>(null) const dispatch = useDispatch() - const initializationService = new InitializationService(client) - useEffect(() => { let timeoutSplash: NodeJS.Timeout if (splashStart) { @@ -50,6 +48,7 @@ const SplashRoot = ({ useEffect(() => { let subscribed = true async function loadData() { + const initializationService = new InitializationService(client) try { // Init index await initializationService.initIndex() @@ -112,7 +111,7 @@ const SplashRoot = ({ return () => { subscribed = false } - }, []) + }, [client, dispatch]) return ( <> diff --git a/src/models/season.model.ts b/src/models/season.model.ts index 66771f19fd4103552c89f44c7d3ec01de113482c..d6a19ce6b1681bae64f25e22bf8489e5a30e9bba 100644 --- a/src/models/season.model.ts +++ b/src/models/season.model.ts @@ -1,6 +1,6 @@ import { UserSeasonState, UserSeasonSuccess } from 'enum/userSeason.enum' import { Boss, BossEntity } from 'models/boss.model' -import { DateTime, Duration } from 'luxon' +import { DateTime } from 'luxon' export interface SeasonState { userSeasonList: UserSeason[] diff --git a/src/react-swipeable-views-utils.d.ts b/src/react-swipeable-views-utils.d.ts index d27874aaec2c3d11bfb1b8abccedbbcf613bf0e6..8495e5a54f1a1c88d2ef0b7c993a18b756c197cd 100644 --- a/src/react-swipeable-views-utils.d.ts +++ b/src/react-swipeable-views-utils.d.ts @@ -15,6 +15,7 @@ declare module 'react-swipeable-views-utils' { slideCount?: number slideRenderer?: (params: VirtualizedSlideRendererParams) => JSX.Element enableMouseEvents?: boolean + onSwitching?: (() => void) | null axis?: AxisType } diff --git a/src/services/dateChart.service.spec.ts b/src/services/dateChart.service.spec.ts index 0743f96c7eb4d18043218701b9a34c355735193c..9f277f21e76c50e6f659f06149263bd336cac877 100644 --- a/src/services/dateChart.service.spec.ts +++ b/src/services/dateChart.service.spec.ts @@ -542,11 +542,7 @@ describe('dateChart service', () => { const firstDate = DateTime.fromISO('2020-10-31T00:00:00.000') const secondDate = DateTime.fromISO('2020-10-31T00:30:00.000') try { - const result = dateChartService.compareStepDate( - 4, - firstDate, - secondDate - ) + dateChartService.compareStepDate(4, firstDate, secondDate) } catch (error) { expect(error).toEqual(new Error('TimeStep unknown')) } diff --git a/src/services/season.service.spec.ts b/src/services/season.service.spec.ts index 0cff5c3b82a19d345661df0d3764ba7209826b64..b4be933f8ab1aaf574e5e6415af14f53f5f14091 100644 --- a/src/services/season.service.spec.ts +++ b/src/services/season.service.spec.ts @@ -1,7 +1,5 @@ import { QueryResult } from 'cozy-client' -import { UserBossState } from 'enum/userBoss.enum' -import { DateTime } from 'luxon' -import { Boss, BossEntity, SeasonEntity, UserSeason } from 'models' +import { BossEntity, SeasonEntity, UserSeason } from 'models' import { userSeasonData, userSeasonDefault, diff --git a/src/styles/index.css b/src/styles/index.css index 30ccc61054e8c55a56939f45e4b699b13e39836c..d46d1d8c169598d19d7e85cdc5fecd42a2d7988c 100644 --- a/src/styles/index.css +++ b/src/styles/index.css @@ -332,6 +332,14 @@ p { line-height: 120%; } /* line 136, src/styles/base/_typography.scss */ +.text-20-italic { + font-family: Lato, sans-serif; + font-style: italic; + font-weight: bold; + font-size: 1.25rem; + line-height: 120%; } + +/* line 143, src/styles/base/_typography.scss */ .text-21-bold { font-family: Lato, sans-serif; font-style: normal; @@ -339,7 +347,7 @@ p { font-size: 1.313rem; line-height: 120%; } -/* line 143, src/styles/base/_typography.scss */ +/* line 150, src/styles/base/_typography.scss */ .text-22-normal { font-family: Lato, sans-serif; font-style: normal; @@ -347,7 +355,7 @@ p { font-size: 1.375rem; line-height: 120%; } -/* line 150, src/styles/base/_typography.scss */ +/* line 157, src/styles/base/_typography.scss */ .text-22-bold { font-family: Lato, sans-serif; font-style: normal; @@ -355,7 +363,7 @@ p { font-size: 1.375rem; line-height: 120%; } -/* line 157, src/styles/base/_typography.scss */ +/* line 164, src/styles/base/_typography.scss */ .text-24-normal { font-family: Lato, sans-serif; font-style: normal; @@ -363,7 +371,7 @@ p { font-size: 1.5rem; line-height: 120%; } -/* line 164, src/styles/base/_typography.scss */ +/* line 171, src/styles/base/_typography.scss */ .text-24-bold { font-family: Lato, sans-serif; font-style: normal; @@ -371,8 +379,16 @@ p { font-size: 1.5rem; line-height: 120%; } +/* line 178, src/styles/base/_typography.scss */ +.text-28-normal { + font-family: Lato, sans-serif; + font-style: normal; + font-weight: normal; + font-size: 1.75rem; + line-height: 120%; } + /* Button */ -/* line 174, src/styles/base/_typography.scss */ +/* line 188, src/styles/base/_typography.scss */ .button-primary-text span { font-family: Lato, sans-serif; font-style: normal; @@ -381,7 +397,7 @@ p { line-height: 120%; color: #e0e0e0; } -/* line 183, src/styles/base/_typography.scss */ +/* line 197, src/styles/base/_typography.scss */ .button-secondary-text { font-family: Lato, sans-serif; font-style: normal; @@ -391,7 +407,7 @@ p { color: #e0e0e0; } /* Card */ -/* line 193, src/styles/base/_typography.scss */ +/* line 207, src/styles/base/_typography.scss */ .card-title-on { font-family: Lato, sans-serif; font-style: normal; @@ -400,7 +416,7 @@ p { line-height: 120%; color: #e0e0e0; } -/* line 201, src/styles/base/_typography.scss */ +/* line 215, src/styles/base/_typography.scss */ .card-title-off { font-family: Lato, sans-serif; font-style: normal; @@ -409,7 +425,7 @@ p { line-height: 120%; color: #e0e0e0; } -/* line 209, src/styles/base/_typography.scss */ +/* line 223, src/styles/base/_typography.scss */ .card-text-bold { font-family: Lato, sans-serif; font-style: normal; @@ -418,7 +434,7 @@ p { line-height: 120%; color: #e0e0e0; } -/* line 217, src/styles/base/_typography.scss */ +/* line 231, src/styles/base/_typography.scss */ .card-result { font-family: Lato, sans-serif; font-style: normal; @@ -427,7 +443,7 @@ p { line-height: 120%; color: #e0e0e0; } -/* line 225, src/styles/base/_typography.scss */ +/* line 239, src/styles/base/_typography.scss */ .card-indicator { font-family: Lato, sans-serif; font-style: normal; @@ -436,7 +452,7 @@ p { line-height: 120%; color: #e0e0e0; } -/* line 233, src/styles/base/_typography.scss */ +/* line 247, src/styles/base/_typography.scss */ .card-text { font-family: Lato, sans-serif; font-style: normal; @@ -446,7 +462,7 @@ p { color: #e0e0e0; } /* Chart */ -/* line 243, src/styles/base/_typography.scss */ +/* line 257, src/styles/base/_typography.scss */ .chart-date { font-family: Lato, sans-serif; font-style: normal; @@ -455,7 +471,7 @@ p { line-height: 123%; color: #e0e0e0; } -/* line 251, src/styles/base/_typography.scss */ +/* line 265, src/styles/base/_typography.scss */ .chart-result { font-family: Lato, sans-serif; font-style: normal; @@ -464,7 +480,7 @@ p { line-height: 120%; color: #e0e0e0; } -/* line 259, src/styles/base/_typography.scss */ +/* line 273, src/styles/base/_typography.scss */ .chart-fluid { font-family: Lato, sans-serif; font-style: normal; @@ -473,7 +489,7 @@ p { line-height: 120%; color: #e0e0e0; } -/* line 267, src/styles/base/_typography.scss */ +/* line 281, src/styles/base/_typography.scss */ .chart-switch-text { font-family: Lato, sans-serif; font-style: normal; @@ -482,7 +498,7 @@ p { line-height: 120%; color: #e0e0e0; } -/* line 275, src/styles/base/_typography.scss */ +/* line 289, src/styles/base/_typography.scss */ .chart-ticks-x-text { font-family: Lato, sans-serif; font-style: normal; @@ -490,11 +506,11 @@ p { font-size: 1rem; line-height: 120%; } @media only screen and (max-width: 768px) { - /* line 275, src/styles/base/_typography.scss */ + /* line 289, src/styles/base/_typography.scss */ .chart-ticks-x-text { font-size: 0.685rem; } } -/* line 285, src/styles/base/_typography.scss */ +/* line 299, src/styles/base/_typography.scss */ .chart-ticks-y-text { font-family: Lato, sans-serif; font-style: normal; @@ -502,12 +518,12 @@ p { font-size: 0.9rem; line-height: 120%; } @media only screen and (max-width: 768px) { - /* line 285, src/styles/base/_typography.scss */ + /* line 299, src/styles/base/_typography.scss */ .chart-ticks-y-text { font-size: 0.75rem; } } /* Cozy bar */ -/* line 297, src/styles/base/_typography.scss */ +/* line 311, src/styles/base/_typography.scss */ .cozybar { font-family: Lato, sans-serif; font-style: normal; @@ -517,7 +533,7 @@ p { color: #e0e0e0; } /* List */ -/* line 307, src/styles/base/_typography.scss */ +/* line 321, src/styles/base/_typography.scss */ .list-title { font-family: Lato, sans-serif; font-style: normal; @@ -528,7 +544,7 @@ p { color: #e0e0e0; } /* Tab */ -/* line 318, src/styles/base/_typography.scss */ +/* line 332, src/styles/base/_typography.scss */ .tab-text-on { font-family: Lato, sans-serif; font-style: normal; @@ -536,7 +552,7 @@ p { font-size: 1rem; line-height: 120%; } -/* line 325, src/styles/base/_typography.scss */ +/* line 339, src/styles/base/_typography.scss */ .tab-text-off { font-family: Lato, sans-serif; font-style: normal; diff --git a/src/targets/services/monthlyReportNotification.ts b/src/targets/services/monthlyReportNotification.ts index 4776e3fb8879f0d30e9b9f358835319bd47afb91..0f1f825e162072dd1c5f2532d43192e28ab80e0a 100644 --- a/src/targets/services/monthlyReportNotification.ts +++ b/src/targets/services/monthlyReportNotification.ts @@ -1,13 +1,8 @@ import logger from 'cozy-logger' import { Client } from 'cozy-client' import get from 'lodash/get' -import { DateTime } from 'luxon' import { runService } from './service' -import { createEmail } from './createEmail' -import { TimePeriod } from 'models' import ProfileService from 'services/profile.service' -import ConsumptionService from 'services/consumption.service' -import PerformanceIndicatorService from 'services/performanceIndicator.service' import MailService from 'services/mail.service' const log = logger.namespace('report') @@ -29,8 +24,6 @@ const monthlyReportNotification = async ({ let username = '' let url = '' - let periodLabel = '' - let monthlyPerformance = '--%' log('info', 'Fetching data for mail...') // Retrieve public name from the stack @@ -49,71 +42,8 @@ const monthlyReportNotification = async ({ url = appLink } - // Define period for the mail - const period: TimePeriod = { - startDate: DateTime.local() - .minus({ - months: 1, - }) - .startOf('month'), - endDate: DateTime.local() - .minus({ - months: 1, - }) - .endOf('month'), - } - const comparePeriod: TimePeriod = { - startDate: DateTime.local() - .minus({ - months: 2, - }) - .startOf('month'), - endDate: DateTime.local() - .minus({ - months: 2, - }) - .endOf('month'), - } - periodLabel = `${period.startDate.setLocale('fr').toFormat('LLL yyyy')}` - - // Retrieve performance for the concerned period - const consumptionService = new ConsumptionService(client) - const fetchedPerformanceIndicators = await consumptionService.getPerformanceIndicators( - period, - 20, - [0, 1, 2], - comparePeriod - ) - if (fetchedPerformanceIndicators) { - const performanceIndicatorService = new PerformanceIndicatorService() - const performanceIndicators = performanceIndicatorService.aggregatePerformanceIndicators( - fetchedPerformanceIndicators - ) - if (performanceIndicators && performanceIndicators.percentageVariation) { - const performance = 100 * performanceIndicators.percentageVariation - monthlyPerformance = - performance > 0 - ? `+${performance.toLocaleString('fr-FR', { - minimumFractionDigits: 2, - maximumFractionDigits: 2, - })}%` - : `-${performance.toLocaleString('fr-FR', { - minimumFractionDigits: 2, - maximumFractionDigits: 2, - })}%` - } - } else { - log('info', 'performanceIndicators not fetched') - } - log('info', 'Creation of mail...') const mailService = new MailService() - // const mailContent = createEmail( - // username, - // url, - // periodLabel, - // monthlyPerformance - // ) const mailContent = mailService.CreateBodyMonthlyReport(username, url) const mailData = { mode: 'noreply', diff --git a/test/__mocks__/seasonEntity.mock.ts b/test/__mocks__/seasonEntity.mock.ts index c040d446befce13f8adbf442f7d8b6e0d7ff706f..e4bc32585fdc9e5fb6712466bf6d09e876aa1916 100644 --- a/test/__mocks__/seasonEntity.mock.ts +++ b/test/__mocks__/seasonEntity.mock.ts @@ -1,5 +1,4 @@ -import { UserSeasonState, UserSeasonSuccess } from 'enum/userSeason.enum' -import { SeasonEntity, UserSeason } from 'models' +import { SeasonEntity } from 'models' import { allBossEntity, bossEntity } from './bossData.mock' export const seasonEntityData: SeasonEntity = { @@ -16,7 +15,7 @@ export const allSeasonEntityData: SeasonEntity[] = [ id: 'SEASON0001', title: 'Nicolas Hublot', description: 'foobar', - target: 40, + target: 15, boss: bossEntity, quizType: 'cultureG', }, @@ -24,7 +23,7 @@ export const allSeasonEntityData: SeasonEntity[] = [ id: 'SEASON0002', title: 'titi', description: 'foobar', - target: 40, + target: 15, boss: null, quizType: 'cultureG', }, @@ -32,7 +31,7 @@ export const allSeasonEntityData: SeasonEntity[] = [ id: 'SEASON0003', title: 'tata', description: 'foobar', - target: 40, + target: 15, boss: allBossEntity[1], quizType: 'cultureG', },