2019-12-18 21:32:26 +00:00
|
|
|
import { ThemeColorsContext } from 'Components/utils/colors'
|
2019-11-15 21:23:21 +00:00
|
|
|
import useDisplayOnIntersecting from 'Components/utils/useDisplayOnIntersecting'
|
2019-09-05 14:27:28 +00:00
|
|
|
import Value from 'Components/Value'
|
2019-10-08 15:34:45 +00:00
|
|
|
import React, { useContext } from 'react'
|
2018-06-12 10:21:36 +00:00
|
|
|
import emoji from 'react-easy-emoji'
|
2019-10-08 15:34:45 +00:00
|
|
|
import { useSelector } from 'react-redux'
|
2019-11-15 21:23:21 +00:00
|
|
|
import { animated, config, useSpring } from 'react-spring'
|
2020-04-05 21:27:31 +00:00
|
|
|
import { DottedName } from 'Rules'
|
2020-03-26 15:03:19 +00:00
|
|
|
import { parsedRulesSelector } from 'Selectors/analyseSelectors'
|
2019-09-05 14:27:28 +00:00
|
|
|
import répartitionSelector from 'Selectors/repartitionSelectors'
|
2018-07-27 14:47:58 +00:00
|
|
|
import { isIE } from '../utils'
|
2018-06-12 10:21:36 +00:00
|
|
|
import './Distribution.css'
|
2018-06-18 09:10:26 +00:00
|
|
|
import './PaySlip'
|
2018-06-12 10:21:36 +00:00
|
|
|
import RuleLink from './RuleLink'
|
|
|
|
|
2019-10-08 15:34:45 +00:00
|
|
|
export default function Distribution() {
|
2019-11-15 21:23:21 +00:00
|
|
|
const distribution = useSelector(répartitionSelector) as any
|
2018-06-12 10:21:36 +00:00
|
|
|
|
2019-09-11 08:06:26 +00:00
|
|
|
if (!Object.values(distribution).length) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className="distribution-chart__container">
|
2019-10-08 15:34:45 +00:00
|
|
|
{distribution.répartition.map(
|
|
|
|
([brancheDottedName, { partPatronale, partSalariale }]) => (
|
|
|
|
<DistributionBranch
|
|
|
|
key={brancheDottedName}
|
2019-11-15 21:23:21 +00:00
|
|
|
dottedName={brancheDottedName}
|
|
|
|
value={partPatronale + partSalariale}
|
|
|
|
distribution={distribution}
|
2019-10-08 15:34:45 +00:00
|
|
|
/>
|
|
|
|
)
|
2019-09-11 08:06:26 +00:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
2018-06-12 10:21:36 +00:00
|
|
|
}
|
2019-10-08 15:34:45 +00:00
|
|
|
|
2019-11-15 21:23:21 +00:00
|
|
|
type DistributionBranchProps = {
|
2020-03-30 17:14:03 +00:00
|
|
|
dottedName: DottedName
|
2019-11-15 21:23:21 +00:00
|
|
|
value: number
|
|
|
|
distribution: { maximum: number; total: number }
|
|
|
|
icon?: string
|
|
|
|
}
|
|
|
|
|
2019-10-08 15:34:45 +00:00
|
|
|
const ANIMATION_SPRING = config.gentle
|
2019-11-15 21:23:21 +00:00
|
|
|
export function DistributionBranch({
|
|
|
|
dottedName,
|
|
|
|
value,
|
|
|
|
icon,
|
2019-10-08 15:34:45 +00:00
|
|
|
distribution
|
2019-11-15 21:23:21 +00:00
|
|
|
}: DistributionBranchProps) {
|
2020-03-26 15:03:19 +00:00
|
|
|
const rules = useSelector(parsedRulesSelector)
|
2019-10-08 15:34:45 +00:00
|
|
|
const [intersectionRef, brancheInViewport] = useDisplayOnIntersecting({
|
|
|
|
threshold: 0.5
|
|
|
|
})
|
2019-12-18 21:32:26 +00:00
|
|
|
const { color } = useContext(ThemeColorsContext)
|
2020-03-26 15:03:19 +00:00
|
|
|
const branche = rules[dottedName]
|
2019-11-15 21:23:21 +00:00
|
|
|
const montant = brancheInViewport ? value : 0
|
2019-10-08 15:34:45 +00:00
|
|
|
const styles = useSpring({
|
|
|
|
config: ANIMATION_SPRING,
|
|
|
|
to: {
|
2019-11-15 21:23:21 +00:00
|
|
|
flex: montant / distribution.maximum,
|
2019-10-08 15:34:45 +00:00
|
|
|
opacity: montant ? 1 : 0
|
|
|
|
}
|
2019-11-15 21:23:21 +00:00
|
|
|
}) as { flex: number; opacity: number } // TODO: problème avec les types de react-spring ?
|
2019-10-08 15:34:45 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<animated.div
|
|
|
|
ref={intersectionRef}
|
|
|
|
className="distribution-chart__item"
|
2019-11-15 21:23:21 +00:00
|
|
|
style={{ opacity: styles.opacity }}
|
|
|
|
>
|
|
|
|
<BranchIcône icône={icon ?? branche.icons} />
|
2019-10-08 15:34:45 +00:00
|
|
|
<div className="distribution-chart__item-content">
|
|
|
|
<p className="distribution-chart__counterparts">
|
|
|
|
<span className="distribution-chart__branche-name">
|
|
|
|
<RuleLink {...branche} />
|
|
|
|
</span>
|
|
|
|
<br />
|
|
|
|
<small>{branche.summary}</small>
|
|
|
|
</p>
|
|
|
|
<ChartItemBar
|
|
|
|
{...{
|
|
|
|
styles,
|
2019-12-18 21:32:26 +00:00
|
|
|
color,
|
2019-10-08 15:34:45 +00:00
|
|
|
montant,
|
|
|
|
total: distribution.total
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</animated.div>
|
|
|
|
)
|
|
|
|
}
|
2018-06-27 16:15:25 +00:00
|
|
|
|
2019-12-18 21:32:26 +00:00
|
|
|
let ChartItemBar = ({ styles, color, montant }) => (
|
2018-06-27 16:15:25 +00:00
|
|
|
<div className="distribution-chart__bar-container">
|
2019-10-08 15:34:45 +00:00
|
|
|
<animated.div
|
2018-06-27 16:15:25 +00:00
|
|
|
className="distribution-chart__bar"
|
|
|
|
style={{
|
2019-12-18 21:32:26 +00:00
|
|
|
backgroundColor: color,
|
2018-07-27 14:47:58 +00:00
|
|
|
...(!isIE()
|
|
|
|
? { flex: styles.flex }
|
|
|
|
: { minWidth: styles.flex * 500 + 'px' })
|
2018-06-27 16:15:25 +00:00
|
|
|
}}
|
|
|
|
/>
|
2019-07-01 15:59:57 +00:00
|
|
|
<div
|
|
|
|
css={`
|
|
|
|
font-weight: bold;
|
2019-09-05 14:27:28 +00:00
|
|
|
margin-left: 1rem;
|
2019-12-18 21:32:26 +00:00
|
|
|
color: var(--textColorOnWhite);
|
2019-11-15 21:23:21 +00:00
|
|
|
`}
|
|
|
|
>
|
2019-07-20 16:30:41 +00:00
|
|
|
<Value maximumFractionDigits={0} unit="€">
|
2018-06-27 16:15:25 +00:00
|
|
|
{montant}
|
2019-06-20 16:51:40 +00:00
|
|
|
</Value>
|
2018-06-27 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
|
2018-11-30 11:46:19 +00:00
|
|
|
let BranchIcône = ({ icône }) => (
|
2018-06-27 16:15:25 +00:00
|
|
|
<div className="distribution-chart__legend">
|
2018-11-30 11:46:19 +00:00
|
|
|
<span className="distribution-chart__icon">{emoji(icône)}</span>
|
2018-06-27 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
)
|