Skip to content
Snippets Groups Projects
Commit 0e8538b2 authored by Guilhem CARRON's avatar Guilhem CARRON
Browse files

feat(konnectors): Fix display when konnector is not installed and prevent...

feat(konnectors): Fix display when konnector is not installed and prevent water consumption alert to be sent in this case
parent fc48e11f
No related branches found
No related tags found
3 merge requests!530chore(release): 1.6.4,!512chore(release): 1.6.0,!498Resolve "Notification dépassement seuil eau"
...@@ -14,6 +14,7 @@ import defaultIcon from 'assets/icons/visu/challenge/challengeLocked.svg' ...@@ -14,6 +14,7 @@ import defaultIcon from 'assets/icons/visu/challenge/challengeLocked.svg'
import { importIconbyId } from 'utils/utils' import { importIconbyId } from 'utils/utils'
import UsageEventService from 'services/usageEvent.service' import UsageEventService from 'services/usageEvent.service'
import { UsageEventType } from 'enum/usageEvent.enum' import { UsageEventType } from 'enum/usageEvent.enum'
import { FluidState } from 'enum/fluid.enum'
interface ChallengeCardUnlockedProps { interface ChallengeCardUnlockedProps {
userChallenge: UserChallenge userChallenge: UserChallenge
...@@ -35,8 +36,11 @@ const ChallengeCardUnlocked: React.FC<ChallengeCardUnlockedProps> = ({ ...@@ -35,8 +36,11 @@ const ChallengeCardUnlocked: React.FC<ChallengeCardUnlockedProps> = ({
setopenNoFluidModal(prev => !prev) setopenNoFluidModal(prev => !prev)
}, []) }, [])
fluidStatus.forEach(elem => { fluidStatus.forEach(fluid => {
if (elem.status === 200) { if (
fluid.status !== FluidState.NOT_CONNECTED &&
fluid.status !== FluidState.KONNECTOR_NOT_FOUND
) {
statusRequirementOk = true statusRequirementOk = true
} }
}) })
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
right: 0; right: 0;
margin: auto; margin: auto;
top: -1rem; top: -1rem;
background: rgba(27, 28, 34, 1); background: $dark-light-2;
width: fit-content; width: fit-content;
padding: 0 1rem; padding: 0 1rem;
max-width: 235px; max-width: 235px;
......
...@@ -9,6 +9,7 @@ import { ...@@ -9,6 +9,7 @@ import {
import * as profileActions from 'store/profile/profile.actions' import * as profileActions from 'store/profile/profile.actions'
import { Button } from '@material-ui/core' import { Button } from '@material-ui/core'
import StyledSwitch from 'components/CommonKit/Switch/StyledSwitch' import StyledSwitch from 'components/CommonKit/Switch/StyledSwitch'
import { FluidState, FluidType } from 'enum/fluid.enum'
jest.mock('cozy-ui/transpiled/react/I18n', () => { jest.mock('cozy-ui/transpiled/react/I18n', () => {
return { return {
...@@ -83,6 +84,10 @@ describe('ReportOptions component', () => { ...@@ -83,6 +84,10 @@ describe('ReportOptions component', () => {
}) })
it('should be rendered with sendConsumptionAlert to false', () => { it('should be rendered with sendConsumptionAlert to false', () => {
mockInitialEcolyoState.profile.sendAnalysisNotification = false
mockInitialEcolyoState.global.fluidStatus[FluidType.WATER].status =
FluidState.DONE
store = createMockStore(mockInitialEcolyoState)
const wrapper = mount( const wrapper = mount(
<Provider store={store}> <Provider store={store}>
<ReportOptions /> <ReportOptions />
......
import React, { useEffect, useState } from 'react' import React, { useCallback, useEffect, useState } from 'react'
import './reportOptions.scss' import './reportOptions.scss'
import { useI18n } from 'cozy-ui/transpiled/react/I18n' import { useI18n } from 'cozy-ui/transpiled/react/I18n'
import { useSelector, useDispatch } from 'react-redux' import { useSelector, useDispatch } from 'react-redux'
...@@ -25,9 +25,12 @@ const ReportOptions: React.FC = () => { ...@@ -25,9 +25,12 @@ const ReportOptions: React.FC = () => {
dispatch(updateProfile({ sendAnalysisNotification: value })) dispatch(updateProfile({ sendAnalysisNotification: value }))
} }
const updateProfileAlert = async (value: boolean) => { const updateProfileAlert = useCallback(
dispatch(updateProfile({ sendConsumptionAlert: value })) async (value: boolean) => {
} dispatch(updateProfile({ sendConsumptionAlert: value }))
},
[dispatch]
)
const setWaterLimit = (e: React.ChangeEvent<HTMLInputElement>) => { const setWaterLimit = (e: React.ChangeEvent<HTMLInputElement>) => {
if (e.target.value !== null && parseInt(e.target.value) > 0) { if (e.target.value !== null && parseInt(e.target.value) > 0) {
...@@ -83,7 +86,12 @@ const ReportOptions: React.FC = () => { ...@@ -83,7 +86,12 @@ const ReportOptions: React.FC = () => {
return () => { return () => {
subscribed = false subscribed = false
} }
}, [client]) }, [
client,
profile.sendConsumptionAlert,
profile.waterDailyConsumptionLimit,
updateProfileAlert,
])
return ( return (
<div className="report-option-root"> <div className="report-option-root">
<div className="report-option-content"> <div className="report-option-content">
...@@ -113,27 +121,31 @@ const ReportOptions: React.FC = () => { ...@@ -113,27 +121,31 @@ const ReportOptions: React.FC = () => {
</div> </div>
</div> </div>
{/* Consumption Alert activation */} {/* Consumption Alert activation */}
{fluidStatus[FluidType.WATER].status !== FluidState.NOT_CONNECTED && ( {fluidStatus[FluidType.WATER].status !== FluidState.NOT_CONNECTED &&
<> fluidStatus[FluidType.WATER].status !==
<div className="head text-16-normal-uppercase"> FluidState.KONNECTOR_NOT_FOUND &&
{t('profile.report.title_alert')} fluidStatus[FluidType.WATER].status !==
</div> FluidState.ERROR_LOGIN_FAILED && (
<div className="switch-container-alert"> <>
<StyledSwitch <div className="head text-16-normal-uppercase">
checked={profile.sendConsumptionAlert} {t('profile.report.title_alert')}
onChange={handleAlertChange} </div>
inputProps={{ <div className="switch-container-alert">
'aria-label': t( <StyledSwitch
'profile.accessibility.button_toggle_consumption_alert' checked={profile.sendConsumptionAlert}
), onChange={handleAlertChange}
}} inputProps={{
/> 'aria-label': t(
<span className="switch-label text-16-normal"> 'profile.accessibility.button_toggle_consumption_alert'
{t('profile.report.switch_label_alert')} ),
</span> }}
</div> />
</> <span className="switch-label text-16-normal">
)} {t('profile.report.switch_label_alert')}
</span>
</div>
</>
)}
{profile.sendConsumptionAlert && ( {profile.sendConsumptionAlert && (
<div className="alert-inputs-display"> <div className="alert-inputs-display">
<div className="alert-input-row"> <div className="alert-input-row">
......
...@@ -35,7 +35,8 @@ export function isKonnectorActive( ...@@ -35,7 +35,8 @@ export function isKonnectorActive(
fluidStatus.filter( fluidStatus.filter(
fluid => fluid =>
fluid.status === FluidState.NOT_CONNECTED || fluid.status === FluidState.NOT_CONNECTED ||
fluid.status === FluidState.ERROR_LOGIN_FAILED fluid.status === FluidState.ERROR_LOGIN_FAILED ||
fluid.status === FluidState.KONNECTOR_NOT_FOUND
).length === 3 ).length === 3
) { ) {
return false return false
...@@ -43,7 +44,10 @@ export function isKonnectorActive( ...@@ -43,7 +44,10 @@ export function isKonnectorActive(
return true return true
} }
} }
if (fluidStatus[fluidType].status === FluidState.NOT_CONNECTED) { if (
fluidStatus[fluidType].status === FluidState.NOT_CONNECTED ||
fluidStatus[fluidType].status === FluidState.KONNECTOR_NOT_FOUND
) {
return false return false
} else return true } else return true
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment