Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. import React, { Component } from 'react'
  2. import { connect } from 'react-redux'
  3. import { Field, reduxForm } from 'redux-form'
  4. import { actionCreators } from '../actions/actions'
  5. import CategoryInput from '../components/CategoryInput'
  6. import MessageInput from '../components/MessageInput'
  7. import SubjectInput from '../components/SubjectInput'
  8. import EmailInput from '../components/EmailInput'
  9.  
  10. class ContactForm extends Component {
  11.  
  12. onSubmit = event => {
  13. console.log('submit')
  14. }
  15.  
  16. onAddEmail = text => {
  17. const {dispatch} = this.props
  18. dispatch(actionCreators.add_email(text))
  19. }
  20.  
  21. onEmailError = (type) => {
  22. const {dispatch} = this.props
  23. switch (type) {
  24. case 'error':
  25. dispatch(actionCreators.add_emailError())
  26. break;
  27. default:
  28. dispatch(actionCreators.remove_emailError())
  29. break;
  30. }
  31. }
  32.  
  33. onAddCategory = text => {
  34. const {dispatch} = this.props
  35. dispatch(actionCreators.add_category(text))
  36. }
  37.  
  38. onAddSubject = text => {
  39. const {dispatch} = this.props
  40. dispatch(actionCreators.add_subject(text))
  41. }
  42.  
  43. onAddSubjectsAvailable = items => {
  44. const {dispatch} = this.props
  45. dispatch(actionCreators.add_subjectsAvailable(items))
  46. }
  47.  
  48. onAreSubjectsFound = type => {
  49. const {dispatch} = this.props
  50. switch (type) {
  51. case 'error':
  52. dispatch(actionCreators.add_noSubjectsFoundError())
  53. break;
  54. default:
  55. dispatch(actionCreators.remove_subjectsSearchError())
  56. break;
  57. }
  58. }
  59.  
  60. onAddMessage = text => {
  61. const {dispatch} = this.props
  62. dispatch(actionCreators.add_message(text))
  63. }
  64.  
  65. onMessageError = type => {
  66. const {dispatch} = this.props
  67. switch (type) {
  68. case 'error':
  69. dispatch(actionCreators.add_messageError())
  70. break;
  71. default:
  72. dispatch(actionCreators.remove_messageError())
  73. break;
  74. }
  75. }
  76.  
  77. render() {
  78. const { categoryLabel, subject,
  79. availableSubjects, noSubjectsFoundError } = this.props
  80.  
  81. return (
  82. <form
  83. style={{paddingBottom: '20px'}}
  84. onSubmit={this.onSubmit}
  85. >
  86. <EmailInput
  87. onEmailError={this.onEmailError}
  88. onEmailChange={this.onAddEmail}
  89. />
  90. <CategoryInput
  91. onSelectCategory={this.onAddCategory}
  92. />
  93. <SubjectInput
  94. onAreSubjectsFound={this.onAreSubjectsFound}
  95. onFetchSubjects={this.onAddSubjectsAvailable}
  96. onSubjectChange={this.onAddSubject}
  97. />
  98. <MessageInput
  99. onMessageChange={this.onAddMessage}
  100. onMessageError={this.onMessageError}
  101. />
  102. <button
  103. className="btn btn-primary"
  104. type="submit"
  105. >
  106. Submit
  107. </button>
  108. </form>
  109. )
  110. }
  111. }
  112.  
  113. const mapStateToProps = (state) => ({
  114.  
  115. })
  116.  
  117. ContactForm = reduxForm({
  118. form: 'contact'
  119. })(ContactForm)
  120.  
  121. export default connect(mapStateToProps)(ContactForm)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement