2019-09-23 07:44:22 +00:00
|
|
|
import { updatePeriod } from 'Actions/actions'
|
2019-09-17 18:10:27 +00:00
|
|
|
import React from 'react'
|
2019-09-11 08:06:51 +00:00
|
|
|
import { Trans } from 'react-i18next'
|
2019-09-13 10:42:19 +00:00
|
|
|
import { useDispatch, useSelector } from 'react-redux'
|
2019-09-17 18:10:27 +00:00
|
|
|
import { situationSelector } 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()
|
2019-09-13 10:42:19 +00:00
|
|
|
const situation = useSelector(situationSelector)
|
2019-09-17 18:10:27 +00:00
|
|
|
const defaultPeriod = useSelector(
|
|
|
|
state => state.simulation?.config?.situation?.période || 'année'
|
2019-09-13 10:42:19 +00:00
|
|
|
)
|
2019-09-15 20:51:13 +00:00
|
|
|
const currentPeriod = situation.période
|
2019-09-18 13:40:45 +00:00
|
|
|
let periods = ['année', 'mois']
|
2019-09-17 18:10:27 +00:00
|
|
|
|
|
|
|
if (!currentPeriod) {
|
2019-09-23 07:44:22 +00:00
|
|
|
dispatch(updatePeriod(defaultPeriod))
|
2019-09-17 18:10:27 +00:00
|
|
|
}
|
2019-09-13 10:42:19 +00:00
|
|
|
|
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-09-13 10:42:19 +00:00
|
|
|
{periods.map(period => (
|
|
|
|
<label key={period}>
|
|
|
|
<input
|
|
|
|
name="période"
|
|
|
|
type="radio"
|
|
|
|
value={period}
|
2019-09-23 07:44:22 +00:00
|
|
|
onChange={() => dispatch(updatePeriod(period))}
|
2019-09-13 10:42:19 +00:00
|
|
|
checked={currentPeriod === period}
|
|
|
|
/>
|
|
|
|
<span>
|
|
|
|
<Trans>{period}</Trans>
|
|
|
|
</span>
|
|
|
|
</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
|
|
|
}
|