@@ -8,15 +8,16 @@ import TimeSeriesChart from '#components/TimeSeriesChart';
88import Button from '#components/Button' ;
99import { getDatesSeparatedByMonths } from '#utils/chart' ;
1010import { resolveToComponent } from '#utils/translation' ;
11+ import { getFormattedDateKey } from '#utils/common' ;
1112import useTranslation from '#hooks/useTranslation' ;
12- import { formatDate } from '#utils/common' ;
1313
1414import PointDetails from '../PointDetails' ;
1515
1616import i18n from './i18n.json' ;
1717import styles from './styles.module.css' ;
1818
1919// FIXME: these must be a constant defined somewhere else
20+ // with satisfies
2021const APPEAL_TYPE_DREF = 0 ;
2122const APPEAL_TYPE_EMERGENCY = 1 ;
2223
@@ -42,11 +43,6 @@ const dateFormatter = new Intl.DateTimeFormat(
4243 { month : 'long' } ,
4344) ;
4445
45- const getFormattedKey = ( dateFromProps : string | Date ) => {
46- const date = new Date ( dateFromProps ) ;
47- return formatDate ( date , 'yyyy-MM' ) ;
48- } ;
49-
5046const currentDate = new Date ( ) ;
5147
5248interface Props {
@@ -73,7 +69,7 @@ function MonthlyChart(props: Props) {
7369 ) ;
7470
7571 const [ activePointKey , setActivePointKey ] = useState < string > (
76- ( ) => getFormattedKey ( dateList [ 0 ] ) ,
72+ ( ) => getFormattedDateKey ( dateList [ 0 ] ) ,
7773 ) ;
7874
7975 const query = {
@@ -120,12 +116,12 @@ function MonthlyChart(props: Props) {
120116
121117 const drefData = listToMap (
122118 monthlyDrefResponse ,
123- ( appeal ) => getFormattedKey ( appeal . timespan ) ,
119+ ( appeal ) => getFormattedDateKey ( appeal . timespan ) ,
124120 ) ;
125121
126122 const emergencyAppealData = listToMap (
127123 monthlyEmergencyAppealResponse ,
128- ( appeal ) => getFormattedKey ( appeal . timespan ) ,
124+ ( appeal ) => getFormattedDateKey ( appeal . timespan ) ,
129125 ) ;
130126
131127 const data = {
@@ -140,7 +136,7 @@ function MonthlyChart(props: Props) {
140136
141137 const dateListWithData = listToMap (
142138 dateList ,
143- ( date ) => getFormattedKey ( date ) ,
139+ ( date ) => getFormattedDateKey ( date ) ,
144140 ( date , key ) => ( {
145141 date,
146142 dref : combinedData ?. dref ?. [ key ] ,
@@ -155,15 +151,15 @@ function MonthlyChart(props: Props) {
155151 ) ;
156152 const chartValueSelector = useCallback (
157153 ( dataKey : DATA_KEY , date : Date ) => {
158- const value = combinedData ?. [ dataKey ] ?. [ getFormattedKey ( date ) ] ?. count ;
154+ const value = combinedData ?. [ dataKey ] ?. [ getFormattedDateKey ( date ) ] ?. count ;
159155 // NOTE: if there are missing values for a given month or year
160156 // less then the current date we assume the value to be 0
161157 // FIXME: This could be done in the aggregation logic of the server itself
162158 if ( isNotDefined ( value ) && date < currentDate ) {
163159 return 0 ;
164160 }
165161
166- return combinedData ?. [ dataKey ] ?. [ getFormattedKey ( date ) ] ?. count ;
162+ return combinedData ?. [ dataKey ] ?. [ getFormattedDateKey ( date ) ] ?. count ;
167163 } ,
168164 [ combinedData ] ,
169165 ) ;
0 commit comments