1
0
Fork 0
mirror of https://github.com/betagouv/mon-entreprise synced 2025-02-09 04:05:01 +00:00
mon-entreprise/source/components/QuickLinks.js
Maxime Quandalle 0663c97204 Utilisation du hook useTranslation de react-i18next
Suppression de notre composant withLanguage qui rajoutait une abstraction
inutile.

Note: de nombreux appels à withTranslation et withLanguage était inutile
car le composant augmenté n'utilisait pas les paramètres fournis (language, t, i18n).
L'utilisation des hooks nous permet de mieux gérer le code mort, car il s'agit
de simples variables dont le non-usage est détecté par l'analyse statique.
2019-09-11 11:17:23 +02:00

77 lines
1.8 KiB
JavaScript

/* @flow */
import { goToQuestion } from 'Actions/actions'
import { T } from 'Components'
import { compose, contains, filter, reject, toPairs } from 'ramda'
import React from 'react'
import { connect } from 'react-redux'
import { withRouter } from 'react-router'
import {
currentQuestionSelector,
nextStepsSelector
} from 'Selectors/analyseSelectors'
import type { Location } from 'react-router'
type OwnProps = {
quickLinks: { [string]: string }
}
type Props = OwnProps & {
goToQuestion: string => void,
location: Location,
currentQuestion: string,
nextSteps: Array<string>,
quickLinksToHide: Array<string>,
show: boolean
}
const QuickLinks = ({
goToQuestion,
currentQuestion,
nextSteps,
quickLinks,
quickLinksToHide
}: Props) => {
if (!quickLinks) {
return null
}
const links = compose(
toPairs,
filter(dottedName => contains(dottedName, nextSteps)),
reject(dottedName => contains(dottedName, quickLinksToHide))
)(quickLinks)
return (
!!links.length && (
<span>
<small>Questions :</small>
{links.map(([label, dottedName]) => (
<button
key={dottedName}
className={`ui__ link-button ${
dottedName === currentQuestion ? 'active' : ''
}`}
css="margin: 0 0.4rem !important"
onClick={() => goToQuestion(dottedName)}>
<T k={'quicklinks.' + label}>{label}</T>
</button>
))}{' '}
{/* <button className="ui__ link-button">Voir la liste</button> */}
</span>
)
)
}
export default (compose(
withRouter,
connect(
(state, props) => ({
key: props.language,
currentQuestion: currentQuestionSelector(state),
nextSteps: nextStepsSelector(state),
quickLinks: state.simulation?.config.questions?.["à l'affiche"],
quickLinksToHide: state.conversationSteps.foldedSteps
}),
{
goToQuestion
}
)
)(QuickLinks): React$ComponentType<OwnProps>)