Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. import React from "react";
  2. import { connect } from "react-redux";
  3. import { Field, getFormValues } from "redux-form";
  4. import { Grid, Form } from "semantic-ui-react";
  5. import RenderFieldSelect from "../../formElements/Select";
  6.  
  7. import {
  8. PROPERTY_TYPE_1,
  9. PROPERTY_TYPE_2,
  10. SUB_TYPE,
  11. EMPTY_OPTIONS
  12. } from "./SelectOptions";
  13. import { required } from "redux-form-validators";
  14. import { withRouter } from "react-router";
  15.  
  16. class SummaryAttributes extends React.Component {
  17. render() {
  18. let propertyType; // property type
  19. let propertyTypes = EMPTY_OPTIONS; // propertyTypes options
  20. let hasSubType;
  21. let subTypes = EMPTY_OPTIONS;
  22.  
  23. const { formValues } = this.props;
  24.  
  25. if (formValues !== undefined) {
  26. const { scorecardType } = this.props.match.params;
  27. switch (scorecardType) {
  28. case "1":
  29. propertyTypes = PROPERTY_TYPE_1;
  30. break;
  31. case "2":
  32. propertyTypes = PROPERTY_TYPE_2;
  33. break;
  34. default:
  35. }
  36.  
  37. propertyType = formValues.propertyType;
  38. switch (propertyType) {
  39. case "1":
  40. subTypes = SUB_TYPE;
  41. hasSubType = true;
  42. break;
  43. case "2":
  44. hasSubType = false;
  45. break;
  46. default:
  47. subTypes = SUB_TYPE;
  48. hasSubType = true;
  49. }
  50. }
  51.  
  52. return (
  53. <div>
  54. <Grid>
  55. <Grid.Row columns="equal">
  56. <Grid.Column>
  57. <Form.Group widths="equal">
  58. <Field
  59. name="propertyType"
  60. component={RenderFieldSelect}
  61. label="Property Type"
  62. required="Y"
  63. options={propertyTypes}
  64. validate={[required()]}
  65. />
  66. </Form.Group>
  67. </Grid.Column>
  68. <Grid.Column>
  69. {hasSubType && (
  70. <Field
  71. name="subType"
  72. component={RenderFieldSelect}
  73. label="Sub Type"
  74. required="Y"
  75. options={subTypes}
  76. validate={[required()]}
  77. />
  78. )}
  79. </Grid.Column>
  80. </Grid.Row>
  81. </Grid>
  82. </div>
  83. );
  84. }
  85. }
  86.  
  87. const mapStateToProps = state => ({
  88. formValues: getFormValues("propertyForm")(state)
  89. });
  90.  
  91. export default withRouter(
  92. connect(
  93. mapStateToProps,
  94. null
  95. )(SummaryAttributes)
  96. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement