2018-05-02 15:55:25 +00:00
|
|
|
import React, { Component } from 'react'
|
|
|
|
import './Sondage.css'
|
|
|
|
import { connect } from 'react-redux'
|
2018-05-03 16:55:22 +00:00
|
|
|
import ReactCSSTransitionGroup from 'react-addons-css-transition-group'
|
2018-05-02 15:55:25 +00:00
|
|
|
import Smiley from './SatisfactionSmiley'
|
2018-05-03 13:24:19 +00:00
|
|
|
import TypeFormEmbed from './TypeFormEmbed'
|
2018-05-03 16:55:22 +00:00
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { Trans, translate } from 'react-i18next'
|
2018-05-02 15:55:25 +00:00
|
|
|
|
|
|
|
@connect(state => ({
|
|
|
|
targets: state.analysis ? state.analysis.targets : [],
|
2018-05-03 16:55:22 +00:00
|
|
|
activeInput: state.activeTargetInput,
|
|
|
|
currentQuestion: state.currentQuestion,
|
|
|
|
conversationStarted: state.conversationStarted
|
2018-05-02 15:55:25 +00:00
|
|
|
}))
|
2018-05-03 16:55:22 +00:00
|
|
|
@translate()
|
|
|
|
export default class Sondage extends Component {
|
|
|
|
state = {
|
|
|
|
visible: false,
|
|
|
|
showForm: false,
|
|
|
|
askFeedbackTime: 'AFTER_FIRST_ESTIMATE'
|
|
|
|
}
|
|
|
|
static contextTypes = {
|
|
|
|
i18n: PropTypes.object.isRequired
|
|
|
|
}
|
|
|
|
static getDerivedStateFromProps(nextProps, currentState) {
|
|
|
|
let feedbackAlreadyAsked = !!document.cookie.includes('feedback_asked=true')
|
|
|
|
let conditions = {
|
|
|
|
AFTER_FIRST_ESTIMATE: nextProps.activeInput && nextProps.targets.length,
|
|
|
|
AFTER_SIMULATION_COMPLETED:
|
|
|
|
!nextProps.currentQuestion && nextProps.conversationStarted
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
visible: conditions[currentState.askFeedbackTime] && !feedbackAlreadyAsked
|
|
|
|
}
|
|
|
|
}
|
|
|
|
componentDidMount() {
|
|
|
|
this.setState({
|
|
|
|
askFeedbackTime:
|
|
|
|
Math.random() > 0.5
|
|
|
|
? 'AFTER_SIMULATION_COMPLETED'
|
|
|
|
: 'AFTER_FIRST_ESTIMATE'
|
|
|
|
})
|
|
|
|
}
|
2018-05-03 13:24:19 +00:00
|
|
|
|
2018-05-03 16:55:22 +00:00
|
|
|
handleClose = () => {
|
|
|
|
this.setState({ visible: false })
|
|
|
|
this.setCookie()
|
|
|
|
}
|
|
|
|
setCookie = () => {
|
|
|
|
document.cookie = 'feedback_asked=true;'
|
|
|
|
}
|
|
|
|
onSmileyClick = satisfaction => {
|
|
|
|
this.setState({ showForm: true, satisfaction, visible: false })
|
|
|
|
this.setCookie()
|
|
|
|
}
|
2018-05-02 15:55:25 +00:00
|
|
|
render() {
|
2018-05-03 16:55:22 +00:00
|
|
|
let { satisfaction, showForm, visible, askFeedbackTime } = this.state
|
2018-05-02 15:55:25 +00:00
|
|
|
|
|
|
|
return (
|
2018-05-03 16:55:22 +00:00
|
|
|
<>
|
|
|
|
{showForm && (
|
|
|
|
<TypeFormEmbed
|
|
|
|
hiddenVariables={{
|
|
|
|
exterieur: false,
|
|
|
|
satisfaction,
|
|
|
|
askFeedbackTime,
|
|
|
|
language: this.context.i18n.language
|
|
|
|
}}
|
|
|
|
/>
|
2018-05-03 13:24:19 +00:00
|
|
|
)}
|
2018-05-03 16:55:22 +00:00
|
|
|
<ReactCSSTransitionGroup
|
|
|
|
transitionName="slide-blurred-bottom"
|
|
|
|
transitionEnterTimeout={2800}
|
|
|
|
transitionLeaveTimeout={300}>
|
|
|
|
{visible && (
|
|
|
|
<div className="sondage__container">
|
|
|
|
<div className="sondage">
|
|
|
|
<span className="sondage__text">
|
|
|
|
<Trans>Votre avis nous intéresse !</Trans>
|
|
|
|
</span>
|
|
|
|
<Smiley
|
|
|
|
text=":)"
|
|
|
|
hoverColor="#16a085"
|
|
|
|
onClick={this.onSmileyClick}
|
|
|
|
/>
|
|
|
|
<Smiley
|
|
|
|
text=":|"
|
|
|
|
hoverColor="#f39c12"
|
|
|
|
onClick={this.onSmileyClick}
|
|
|
|
/>
|
|
|
|
<button
|
|
|
|
className="sondage__closeButton unstyledButton"
|
|
|
|
onClick={this.handleClose}
|
|
|
|
aria-label="close">
|
|
|
|
X
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</ReactCSSTransitionGroup>
|
|
|
|
</>
|
2018-05-02 15:55:25 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|