/* @flow */ import React from 'react' import classnames from 'classnames' import styles from './survey.scss' import { Errors, Spinner, } from '..' import { SurveyQuestions } from '../types' import { Button, Icon, Panel, } from '../index' type Props = { canSubmit?: boolean, dismissable?: boolean, errors: Array, loading?: boolean, onChange: () => mixed, onDismiss: () => mixed, onSubmit: () => mixed, questions: SurveyQuestions, submitting: boolean, } export default class Survey extends React.Component { static defaultProps = { canSubmit: true, dismissable: true, errors: [], loading: false, modal: false, onChange: function(){}, onDismiss: function(){}, onSubmit: function(){}, questions: [], submitting: false, } props: Props handleOnSubmit = (e) => { e.preventDefault(); this.props.onSubmit(); } handleOnChange(qaIdx) { this.props.onChange(...qaIdx) } renderHeader() { const { errors, } = this.props return (
) } renderBody() { const { questions, submitting, } = this.props const css = classnames([ 'panel-default', styles.surveyQuestion, ]) if(!questions.length) return null return (
    {questions.map((q, i) => (
    • {q.answers.map((answer, x) => { let otherProps = { onChange: this.handleOnChange.bind(this, [i, x]), } if(submitting) otherProps.disabled = true if(answer.selected) otherProps.checked = true return (
    • ) })}
  1. ) )}
) } renderFooter() { const { canSubmit, submitting, } = this.props let props = { text: submitting ? "Submitting Answers" : "Submit Answers", type: submitting ? "" : "submit", } if(!canSubmit || submitting) props.disabled = true props.className = classnames([ "btn-primary", styles.submit, ]) if(submitting) { props.icon = ( ) } return (