Redirection vers /404 si la regle demandée dans l'url est inconnue

pull/138/head
mama 2017-11-24 16:56:36 +01:00
parent f5326b81bc
commit e803d63806
3 changed files with 63 additions and 52 deletions

View File

@ -1,14 +1,24 @@
import React from 'react'
import {Link} from 'react-router-dom'
import { Link } from 'react-router-dom'
export default () =>
<div style={{color: '#333350', margin: '15% auto', width: '15em', textAlign: 'center'}}>
<h2>
On peut facilement se perdre dans la législation...
</h2>
<Link to="/">
{/* TODO: credits for the image to add: https://thenounproject.com/term/treasure-map/96666/ */}
<img style={{margin: '3%'}} width="250px" src={require('../images/map-directions.png')} />
Revenir en lieu sûr
</Link>
</div>
export default () => (
<div
style={{
color: '#333350',
margin: '15% auto',
width: '15em',
textAlign: 'center'
}}
>
<h2>On peut facilement se perdre dans la législation...</h2>
<Link to="/">
{/* TODO: credits for the image to add: https://thenounproject.com/term/treasure-map/96666/ */}
<img
style={{ margin: '3%' }}
width="100%"
src={require('../images/map-directions.png')}
/>
<em>Revenir en lieu sûr</em>
</Link>
</div>
)

View File

@ -3,7 +3,7 @@ import React, { Component } from 'react'
import Helmet from 'react-helmet'
import { reset, change, formValueSelector } from 'redux-form'
import { connect } from 'react-redux'
import { withRouter } from 'react-router-dom'
import { withRouter, Redirect } from 'react-router-dom'
import { START_CONVERSATION } from '../actions'
import { rules, findRuleByName, decodeRuleName } from 'Engine/rules'
@ -47,22 +47,21 @@ export default class extends Component {
targetNames = encodedTargets.split('+').map(decodeRuleName)
this.targetNames = targetNames
this.targetRules = targetNames.map(name => findRuleByName(rules, name))
this.targetRules = R.reject(R.isNil)(
targetNames.map(name => findRuleByName(rules, name))
)
this.targetRules.map(({ dottedName }) => resetFormField(dottedName))
// C'est ici que la génération du formulaire, et donc la traversée des variables commence
// if (!existingConversation)
//TODO
if (
this.props.foldedSteps.length === 0 ||
!R.equals(targetNames, pastTargetNames)
this.targetRules.length > 0 &&
(this.props.foldedSteps.length === 0 ||
!R.equals(targetNames, pastTargetNames))
)
this.props.startConversation(targetNames)
}
render() {
//TODO
// if (!this.targets.formule && !R.path(['simulateur', 'objectifs'], this.rule))
// return <Redirect to={'/regle/' + this.name} />
if (this.targetRules.length == 0) return <Redirect to="/404" />
let {
foldedSteps,

View File

@ -1,17 +1,23 @@
import React, { Component } from "react"
import { connect } from "react-redux"
import R from "ramda"
import "./Rule.css"
import { rules, decodeRuleName, nameLeaf } from "Engine/rules.js"
import { analyse } from "Engine/traverse"
import { START_CONVERSATION } from "../../actions"
import possiblesDestinataires from "Règles/ressources/destinataires/destinataires.yaml"
import { capitalise0 } from "../../utils"
import References from "./References"
import Algorithm from "./Algorithm"
import Examples from "./Examples"
import Helmet from "react-helmet"
import {createMarkdownDiv} from 'Engine/marked'
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { Redirect } from 'react-router'
import R from 'ramda'
import './Rule.css'
import {
rules,
decodeRuleName,
nameLeaf,
findRuleByName
} from 'Engine/rules.js'
import { analyse } from 'Engine/traverse'
import { START_CONVERSATION } from '../../actions'
import possiblesDestinataires from 'Règles/ressources/destinataires/destinataires.yaml'
import { capitalise0 } from '../../utils'
import References from './References'
import Algorithm from './Algorithm'
import Examples from './Examples'
import Helmet from 'react-helmet'
import { createMarkdownDiv } from 'Engine/marked'
@connect(
state => ({
@ -29,16 +35,17 @@ export default class Rule extends Component {
showValues: true
}
componentWillReceiveProps(nextProps) {
let get = R.path(["match", "params", "name"])
let get = R.path(['match', 'params', 'name'])
if (get(nextProps) !== get(this.props)) {
this.setRule(get(nextProps))
this.setState({ example: null, showValues: true })
}
}
setRule(name) {
this.rule = analyse(rules, nameLeaf(decodeRuleName(name)))(
this.props.situationGate
).targets[0]
let ruleName = nameLeaf(decodeRuleName(name)),
rule = findRuleByName(rules, ruleName)
if (!rule) return null
this.rule = analyse(rules, rule.name)(this.props.situationGate).targets[0]
}
componentWillMount() {
let { match: { params: { name } } } = this.props
@ -46,17 +53,14 @@ export default class Rule extends Component {
this.setRule(name)
}
render() {
// if (!rule) {
// this.props.router.push('/404')
// return null
// }
if (!this.rule) return <Redirect to="/404" />
let conversationStarted = !R.isEmpty(this.props.form),
situationExists = conversationStarted || this.state.example != null
let { type, name, title, description, question } = this.rule,
situationOrExampleRule =
R.path(["example", "rule"])(this.state) || this.rule
R.path(['example', 'rule'])(this.state) || this.rule
return (
<div id="rule">
@ -67,12 +71,10 @@ export default class Rule extends Component {
<section id="rule-meta">
<div className="rule-type">{type || 'Règle'}</div>
<h1>
{capitalise0(name)}
</h1>
<h1>{capitalise0(name)}</h1>
<div id="meta-paragraph">
{createMarkdownDiv(description || question)}
{this.renderDestinataire(R.path([type, "destinataire"])(this.rule))}
{this.renderDestinataire(R.path([type, 'destinataire'])(this.rule))}
</div>
</section>
@ -93,14 +95,14 @@ export default class Rule extends Component {
<button id="reportError">
<a
href={
"mailto:contact@embauche.beta.gouv.fr?subject=Erreur dans une règle " +
'mailto:contact@embauche.beta.gouv.fr?subject=Erreur dans une règle ' +
name
}
>
<i
className="fa fa-exclamation-circle"
aria-hidden="true"
style={{ marginRight: ".6em" }}
style={{ marginRight: '.6em' }}
/>Signaler une erreur
</a>
</button>
@ -122,7 +124,7 @@ export default class Rule extends Component {
<a href={destinataireData.lien} target="_blank">
{destinataireData.image && (
<img
src={require("Règles/ressources/destinataires/" +
src={require('Règles/ressources/destinataires/' +
destinataireData.image)}
/>
)}