Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import React from 'react'
import { translate } from 'cozy-ui/react/I18n'
import { NavLink } from 'react-router-dom'
import { FluidType } from 'enum/fluid.enum'
import { IDataload } from 'services/dataConsumptionContracts'
import StyledIcon from 'components/CommonKit/Icon/StyledIcon'
import { getPicto, formatNumberValues } from 'utils/utils'
import LoadToCurrencyConverter from 'services/loadToCurrencyConverterService'
import { isDataToCome } from 'services/dateChartService'
import StyledSpinner from 'components/CommonKit/Spinner/StyledSpinner'
import { DateTime, Interval } from 'luxon'
interface DataloadConsumptionVisualizerProps {
fluidTypes: FluidType[]
dataload: IDataload
compareDataload: IDataload
showCompare: boolean
multiFluid: boolean
lastDataDate: DateTime
isLoaded: boolean
handleClickMove: (increment: number) => void
handleClickDetails: () => void
t: Function // translation service
}
const DataloadConsumptionVisualizer = ({
fluidTypes,
dataload,
compareDataload,
showCompare,
multiFluid,
lastDataDate,
isLoaded,
t,
}: DataloadConsumptionVisualizerProps) => {
const ltcc = new LoadToCurrencyConverter()
const fluidStyle = multiFluid
? 'MULTIFLUID'
: fluidTypes.length > 1
? 'MULTIFLUID'
: FluidType[fluidTypes[0]]
const hasData = dataload && dataload.value && dataload.value >= 0
const hasCompareData =
showCompare &&
!multiFluid &&
compareDataload &&
compareDataload.value &&
compareDataload.value >= 0
return (
<div className="cv-load">
{!isLoaded ? null : hasData ? (
<div className="cv-load-content">
{hasCompareData && (
<div className="cv-load-section cv-load-section-left">
<div
className={`cv-load-value ${fluidStyle.toLowerCase()}-compare chart-result`}
>
{formatNumberValues(compareDataload.value)}
<span className="text-18-medium">{`${t(
'FLUID.' + fluidStyle + '.UNIT'
)}`}</span>
</div>
<div
className={`cv-euro ${fluidStyle.toLowerCase()}-compare chart-fluid`}
>
{`${formatNumberValues(
ltcc.Convert(compareDataload.value, fluidTypes[0])
)} €`}
</div>
</div>
)}
<div
className={
showCompare
? 'cv-load-section cv-load-section-right'
: 'cv-load-section'
}
>
<div
className={`cv-load-value ${fluidStyle.toLowerCase()} chart-result`}
>
{multiFluid && fluidTypes.length === 1
? formatNumberValues(
ltcc.Convert(dataload.value, fluidTypes[0])
)
: formatNumberValues(dataload.value)}
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<span className="text-18-medium">{`${t(
'FLUID.' + fluidStyle + '.UNIT'
)}`}</span>
</div>
{!multiFluid ? (
<div
className={`cv-euro ${fluidStyle.toLowerCase()} chart-fluid`}
>
{`${formatNumberValues(
ltcc.Convert(dataload.value, fluidTypes[0])
)} €`}
</div>
) : (
<div className="cv-euro chart-fluid">
{dataload.valueDetail ? (
dataload.valueDetail.map((load, index) => {
return (
<NavLink
key={index}
to={`/consumption/${t(
'FLUID.' + FluidType[index] + '.NAME'
).toLowerCase()}`}
className="cv-euro-link"
>
<div
className={
load === -1 && !isDataToCome(dataload, index)
? 'cv-euro-fluid error'
: `cv-euro-fluid ${FluidType[
index
].toLowerCase()}`
}
>
<StyledIcon
className="cv-euro-fluid-icon"
icon={getPicto(index)}
size={22}
/>
<div>
{!isDataToCome(dataload, index) && load !== -1
? `${formatNumberValues(load)} €`
: isDataToCome(dataload, index)
? t('COMMON.DATATOCOME')
: '---- €'}
</div>
</div>
</NavLink>
)
})
) : (
<NavLink
to={`/consumption/${t(
'FLUID.' + FluidType[fluidTypes[0]] + '.NAME'
).toLowerCase()}`}
className="cv-euro-link"
>
<div
className={`cv-euro-fluid ${FluidType[
fluidTypes[0]
].toLowerCase()}`}
>
<StyledIcon
className="cv-euro-fluid-icon"
icon={getPicto(fluidTypes[0])}
size={22}
/>
<div>{`${formatNumberValues(
ltcc.Convert(dataload.value, fluidTypes[0])
)} €`}</div>
</div>
</NavLink>
)}
</div>
)}
</div>
</div>
) : (
<div
className={`cv-load-content ${fluidStyle.toLowerCase()} text-22-normal`}
>
{`${t('COMMON.LASTDATA')} : ${lastDataDate.toFormat("dd'/'MM'/'yy")}`}
</div>
)}
</div>
)
}
export default translate()(DataloadConsumptionVisualizer)