Skip to content

Commit

Permalink
fix(qna): fix validating QNA-items (#979)
Browse files Browse the repository at this point in the history
  • Loading branch information
epaminond committed Oct 3, 2018
1 parent 322ebac commit 92b186f
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions packages/functionals/botpress-qna/src/views/FormModal.js
@@ -1,6 +1,7 @@
import React, { Component } from 'react'
import { FormControl, Button, Modal, Alert } from 'react-bootstrap'
import classnames from 'classnames'
import some from 'lodash/some'

import Select from 'react-select'
import style from './style.scss'
Expand Down Expand Up @@ -73,27 +74,17 @@ export default class FormModal extends Component {
}

validateForm() {
const { hasCategory, categories } = this.props
const { item, isText, isRedirect } = this.state
const categoryWrapper = hasCategory ? { category: categories.length && item.category } : {}
const invalidFields = {
...categoryWrapper,
questions: !item.questions.length,
questions: !item.questions.length || !item.questions[0].length,
answer: !(this.state.isText && this.state.item.answer),
checkbox: !(isText || isRedirect),
redirectFlow: this.state.isRedirect && !this.state.item.redirectFlow,
redirectNode: this.state.isRedirect && !this.state.item.redirectNode
}

this.setState({ invalidFields })

for (const field in invalidFields) {
if (invalidFields[field]) {
return true
}
}

return false
return some(invalidFields)
}

onCreate = event => {
Expand Down

0 comments on commit 92b186f

Please sign in to comment.