Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. import { Button, Form, Grid, Input } from 'semantic-ui-react'
  2. import React, { Component } from 'react'
  3.  
  4. import PropTypes from 'prop-types'
  5.  
  6. class ItemList extends Component {
  7. // Color
  8. onItemColorChange(index, event) {
  9. this.props.onItemChange({
  10. index: index,
  11. newColor: event.target.value,
  12. })
  13. }
  14. // Estimate Quantity
  15. onItemEstQuantChange(index, event) {
  16. this.props.onItemEstQuantChange({
  17. index: index,
  18. newEstQuant: event.target.value,
  19. })
  20. }
  21. // Estimate Total
  22. onItemEstTotalChange(index, event) {
  23. this.props.onItemEstTotalChange({
  24. index: index,
  25. newEstTotal: event.target.value,
  26. })
  27. }
  28. // Final quantity
  29. onItemFinQuantChange(index, event) {
  30. this.props.onItemFinQuantChange({
  31. index: index,
  32. newFinQuant: event.target.value,
  33. })
  34. }
  35. // Item Reference Number
  36. onItemRefNumChange(index, event) {
  37. this.props.onItemRefNumChange({
  38. index: index,
  39. newRefNum: event.target.value,
  40. })
  41. }
  42. // Item Unit Price
  43. onItemUnitPriceChange(index, event) {
  44. this.props.onItemUnitPriceChange({
  45. index: index,
  46. newUnitPrice: event.target.value,
  47. })
  48. }
  49. // extended price
  50. onItemExtPriceChange(index, event) {
  51. this.props.onItemExtPriceChange({
  52. index: index,
  53. newExtPrice: event.target.value,
  54. })
  55. }
  56.  
  57. onItemDeleteClick(index) {
  58. this.props.onItemDeleteClick({
  59. index: index,
  60. })
  61. }
  62.  
  63. getItemsTotal(items) {
  64. return items.reduce((sum, item) => {
  65. return sum + item.extPrice + item.finQuant * item.unitPrice
  66. }, 0)
  67. }
  68.  
  69. renderItemRow(item, index) {
  70. return (
  71. <Form key={index}>
  72. <Form.Group>
  73. <Form.Input
  74. label="Color"
  75. placeholder="Color of the item"
  76. width={2}
  77. value={item.color}
  78. onChange={this.onItemColorChange.bind(this, index)}
  79. />
  80. <Form.Input
  81. label="Estimated Quantity"
  82. placeholder="Estimate"
  83. width={2}
  84. value={item.estQuant}
  85. onChange={this.onItemEstQuantChange.bind(this, any)}
  86. />
  87. <Form.Input
  88. label="Final Quantity"
  89. placeholder="Final"
  90. width={2}
  91. value={item.finQuant}
  92. onChange={this.onItemFinQuantChange.bind(this, index)}
  93. />
  94. <Form.Input
  95. label="Unit Price"
  96. placeholder="Unit Price"
  97. width={2}
  98. value={item.unitPrice}
  99. onChange={this.onItemUnitPriceChange.bind(this, index)}
  100. />
  101. <Form.Input
  102. label="Extended Price"
  103. placeholder="Extended Price"
  104. width={2}
  105. value={item.extPrice}
  106. onChange={this.onItemExtPriceChange.bind(this, index)}
  107. />
  108. <Form.Input
  109. label="Estimated Total"
  110. placeholder="Total"
  111. width={2}
  112. value={item.estTotal}
  113. >
  114. {item.extPrice + item.finQuant * item.unitPrice}
  115. </Form.Input>
  116. </Form.Group>
  117. </Form>
  118. )
  119. }
  120.  
  121. render() {
  122. let items = this.props.items
  123. let ItemRows = items.map(this.renderItemRow.bind(this))
  124. let ItemsTotal = this.getItemsTotal(items)
  125.  
  126. return (
  127. <Grid columns={3}>
  128. <Grid.Row>
  129. Hello
  130. </Grid.Row>
  131. {ItemRows}
  132. <Grid.Row>
  133. <Grid.Column>
  134. <Button
  135. positive
  136. onClick={this.props.onItemAddClick}
  137. content="Add another Item"
  138. />
  139. </Grid.Column>
  140. <Grid.Column>
  141. Total: {ItemsTotal}
  142. </Grid.Column>
  143. </Grid.Row>
  144. </Grid>
  145. )
  146. }
  147. }
  148.  
  149. ItemList.propTypes = {
  150. items: React.PropTypes.array,
  151. onItemColorChange: React.PropTypes.func,
  152. onItemDeleteClick: React.PropTypes.func,
  153. onItemEstQuantChange: React.PropTypes.func,
  154. onItemEstTotalChange: React.PropTypes.func,
  155. onItemExtPriceChange: React.PropTypes.func,
  156. onItemFinQuantChange: React.PropTypes.func,
  157. onItemRefNumChange: React.PropTypes.func,
  158. onItemUnitPriceChange: React.PropTypes.func,
  159. }
  160.  
  161. ItemList.defaultProps = {
  162. items: [],
  163. }
  164.  
  165. export default ItemList
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement