2019-11-28 11:03:23 +00:00
|
|
|
import { updateUnit } from 'Actions/actions'
|
2020-01-22 16:33:36 +00:00
|
|
|
import { parseUnit, serializeUnit } from 'Engine/units'
|
2019-09-17 18:10:27 +00:00
|
|
|
import React from 'react'
|
2020-01-22 16:33:36 +00:00
|
|
|
import { useTranslation } from 'react-i18next'
|
2019-09-13 10:42:19 +00:00
|
|
|
import { useDispatch, useSelector } from 'react-redux'
|
2020-01-17 16:06:27 +00:00
|
|
|
import { defaultUnitSelector } from 'Selectors/analyseSelectors'
|
2018-11-29 16:22:46 +00:00
|
|
|
import './PeriodSwitch.css'
|
2018-11-14 10:24:13 +00:00
|
|
|
|
2019-09-13 10:42:19 +00:00
|
|
|
export default function PeriodSwitch() {
|
2019-09-12 15:02:07 +00:00
|
|
|
const dispatch = useDispatch()
|
2020-01-22 16:33:36 +00:00
|
|
|
const language = useTranslation().i18n.language
|
2020-01-17 16:06:27 +00:00
|
|
|
const currentUnit = useSelector(defaultUnitSelector)
|
|
|
|
|
2019-11-28 11:03:23 +00:00
|
|
|
let units = ['€/mois', '€/an']
|
2018-11-14 10:24:13 +00:00
|
|
|
return (
|
2019-07-23 14:14:30 +00:00
|
|
|
<span id="PeriodSwitch">
|
|
|
|
<span className="base ui__ small toggle">
|
2019-11-28 11:03:23 +00:00
|
|
|
{units.map(unit => (
|
|
|
|
<label key={unit}>
|
2019-09-13 10:42:19 +00:00
|
|
|
<input
|
2019-11-28 11:03:23 +00:00
|
|
|
name="defaultUnit"
|
2019-09-13 10:42:19 +00:00
|
|
|
type="radio"
|
2019-11-28 11:03:23 +00:00
|
|
|
value={unit}
|
|
|
|
onChange={() => dispatch(updateUnit(unit))}
|
|
|
|
checked={currentUnit === unit}
|
2019-09-13 10:42:19 +00:00
|
|
|
/>
|
2020-01-22 16:33:36 +00:00
|
|
|
<span>{serializeUnit(parseUnit(unit), 1, language)}</span>
|
2019-09-13 10:42:19 +00:00
|
|
|
</label>
|
|
|
|
))}
|
2019-07-23 14:14:30 +00:00
|
|
|
</span>
|
|
|
|
</span>
|
2018-11-14 10:24:13 +00:00
|
|
|
)
|
2018-11-21 17:16:51 +00:00
|
|
|
}
|