Le changement de période convertit les saisies
parent
7740267984
commit
9657fae7a3
|
@ -53,6 +53,7 @@
|
|||
"react-virtualized-select": "^3.1.3",
|
||||
"reduce-reducers": "^0.1.2",
|
||||
"redux": "^3.7.2",
|
||||
"redux-batched-actions": "^0.4.1",
|
||||
"redux-form": "^7.4.2",
|
||||
"redux-thunk": "^2.3.0",
|
||||
"reselect": "^4.0.0",
|
||||
|
|
|
@ -11,6 +11,7 @@ import { applyMiddleware, compose, createStore } from 'redux'
|
|||
import thunk from 'redux-thunk'
|
||||
import computeThemeColours from 'Ui/themeColours'
|
||||
import { getIframeOption, inIframe } from './utils'
|
||||
import { enableBatching } from 'redux-batched-actions'
|
||||
|
||||
let initialStore = {
|
||||
themeColours: computeThemeColours(getIframeOption('couleur'))
|
||||
|
@ -50,7 +51,7 @@ export default class Layout extends PureComponent {
|
|||
)
|
||||
)
|
||||
this.store = createStore(
|
||||
reducers,
|
||||
enableBatching(reducers),
|
||||
{ ...initialStore, ...this.props.initialStore },
|
||||
storeEnhancer
|
||||
)
|
||||
|
|
|
@ -2,9 +2,16 @@ import React from 'react'
|
|||
import { Trans, translate } from 'react-i18next'
|
||||
import { Field } from 'redux-form'
|
||||
import './PeriodSwitch.css'
|
||||
import { reduxForm } from 'redux-form'
|
||||
import { compose } from 'ramda'
|
||||
import { reduxForm, change } from 'redux-form'
|
||||
import { compose, map, filter, toPairs } from 'ramda'
|
||||
import emoji from 'react-easy-emoji'
|
||||
import { batchActions } from 'redux-batched-actions'
|
||||
import { connect } from 'react-redux'
|
||||
import {
|
||||
situationSelector,
|
||||
flatRulesSelector
|
||||
} from 'Selectors/analyseSelectors'
|
||||
import { findRuleByDottedName, nestedSituationToPathMap } from 'Engine/rules'
|
||||
|
||||
export default compose(
|
||||
reduxForm({
|
||||
|
@ -12,12 +19,29 @@ export default compose(
|
|||
destroyOnUnmount: false,
|
||||
initialValues: { période: 'mois' }
|
||||
}),
|
||||
translate()
|
||||
)(function PeriodSwitch() {
|
||||
translate(),
|
||||
connect(
|
||||
state => ({
|
||||
rules: flatRulesSelector(state),
|
||||
situation: nestedSituationToPathMap(situationSelector(state))
|
||||
}),
|
||||
dispatch => ({
|
||||
batchPeriodChange: actions => dispatch(batchActions(actions))
|
||||
})
|
||||
)
|
||||
)(function PeriodSwitch({ situation, rules, batchPeriodChange }) {
|
||||
return (
|
||||
<div id="PeriodSwitch">
|
||||
<label>
|
||||
<Field name="période" component="input" type="radio" value="mois" />
|
||||
<Field
|
||||
name="période"
|
||||
component="input"
|
||||
type="radio"
|
||||
value="mois"
|
||||
onChange={e =>
|
||||
updateSituation('mois', batchPeriodChange, situation, rules)
|
||||
}
|
||||
/>
|
||||
<span />
|
||||
<span className="radioText">
|
||||
<Trans>Mois</Trans>
|
||||
|
@ -25,7 +49,15 @@ export default compose(
|
|||
</label>
|
||||
<span style={{ fontSize: '1.5em' }}>{emoji('⏳')}</span>
|
||||
<label>
|
||||
<Field name="période" component="input" type="radio" value="année" />
|
||||
<Field
|
||||
name="période"
|
||||
component="input"
|
||||
type="radio"
|
||||
value="année"
|
||||
onChange={e =>
|
||||
updateSituation('année', batchPeriodChange, situation, rules)
|
||||
}
|
||||
/>
|
||||
<span />
|
||||
|
||||
<span className="radioText">
|
||||
|
@ -35,3 +67,28 @@ export default compose(
|
|||
</div>
|
||||
)
|
||||
})
|
||||
|
||||
let updateSituation = (toPeriod, batchPeriodChange, situation, rules) => {
|
||||
let needConversation = filter(([dottedName, value]) => {
|
||||
let rule = findRuleByDottedName(rules, dottedName)
|
||||
return value != null && rule.période === 'flexible'
|
||||
})(toPairs(situation))
|
||||
let actions = [
|
||||
...map(
|
||||
([dottedName, value]) =>
|
||||
change(
|
||||
'conversation',
|
||||
dottedName,
|
||||
situation.période === 'mois' && toPeriod === 'année'
|
||||
? value * 12
|
||||
: situation.période === 'année' && toPeriod === 'mois'
|
||||
? value / 12
|
||||
: console.log('oups')
|
||||
),
|
||||
needConversation
|
||||
),
|
||||
change('conversation', 'période', toPeriod)
|
||||
]
|
||||
|
||||
batchPeriodChange(actions)
|
||||
}
|
||||
|
|
|
@ -7133,6 +7133,10 @@ reduce-reducers@^0.1.2:
|
|||
version "0.1.5"
|
||||
resolved "https://registry.yarnpkg.com/reduce-reducers/-/reduce-reducers-0.1.5.tgz#ff77ca8068ff41007319b8b4b91533c7e0e54576"
|
||||
|
||||
redux-batched-actions@^0.4.1:
|
||||
version "0.4.1"
|
||||
resolved "https://registry.yarnpkg.com/redux-batched-actions/-/redux-batched-actions-0.4.1.tgz#a8de8cef50a1db4f009d5222820c836515597e22"
|
||||
|
||||
redux-form@^7.4.2:
|
||||
version "7.4.2"
|
||||
resolved "https://registry.yarnpkg.com/redux-form/-/redux-form-7.4.2.tgz#d6061088fb682eb9fc5fb9749bd8b102f03154b0"
|
||||
|
|
Loading…
Reference in New Issue