Matches.js 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import React from 'react'
  2. import { Link } from 'react-router-dom'
  3. import moment from 'moment'
  4. class Matches extends React.Component {
  5. constructor() {
  6. super()
  7. this.handleChange = this.handleChange.bind(this)
  8. }
  9. componentDidMount () {
  10. console.log('Matches did mount', this)
  11. const { matchesGetMatchesRequest } = this.props.matchesActions
  12. matchesGetMatchesRequest()
  13. }
  14. handleChange (event) {
  15. event.preventDefault()
  16. const { matchesSetFilter } = this.props.matchesActions
  17. const nextFilter = {
  18. category: this.category.value,
  19. date: this.date.value,
  20. time: this.time.value,
  21. place: this.place.value,
  22. player: this.player.value,
  23. result: this.result.value
  24. }
  25. matchesSetFilter(nextFilter)
  26. }
  27. render () {
  28. const state = this.props.matches
  29. const actions = this.props.matchesActions
  30. const { setRecipients } = this.props.smsActions
  31. const { matches, filteredMatches, filter } = state
  32. const participatingPlayers = []
  33. filteredMatches.forEach(match => {
  34. if (match.player1) participatingPlayers.push(match.player1)
  35. if (match.player2) participatingPlayers.push(match.player2)
  36. })
  37. return (
  38. <div>
  39. <p>{filteredMatches.length}/{matches.length} Spiele, {participatingPlayers.length} Spieler > <Link to="/sms" onClick={() => setRecipients(participatingPlayers)}>SMS</Link></p>
  40. <form>
  41. <table className='table table-bordered table-striped'>
  42. <thead>
  43. <tr>
  44. <th>Kategorie</th><th>Datum</th><th>Zeit</th><th>Ort</th><th>Spieler 1</th><th>Spieler 2</th><th>Resultat</th>
  45. </tr>
  46. <tr>
  47. <td>
  48. <input type="input" ref={(input) => {this.category = input}} id="category" value={filter.category} placeholder="Kategorie" onChange={this.handleChange}></input>
  49. </td>
  50. <td>
  51. <input type="input" ref={(input) => {this.date = input}} id="date" value={filter.date} placeholder="Datum" onChange={this.handleChange}></input>
  52. </td>
  53. <td>
  54. <input type="input" ref={(input) => {this.time = input}} id="time" value={filter.time} placeholder="Zeit" onChange={this.handleChange}></input>
  55. </td>
  56. <td>
  57. <input type="input" ref={(input) => {this.place = input}} id="place" value={filter.place} placeholder="Ort" onChange={this.handleChange}></input>
  58. </td>
  59. <td colSpan={2}>
  60. <input type="input" ref={(input) => {this.player = input}} id="player" value={filter.player} placeholder="Spieler" onChange={this.handleChange}></input>
  61. </td>
  62. <td>
  63. <input type="input" ref={(input) => {this.result = input}} id="result" value={filter.result} placeholder="Resultat" onChange={this.handleChange}></input>
  64. </td>
  65. </tr>
  66. </thead>
  67. <tbody>
  68. {filteredMatches.map((match, key) =>
  69. <tr key={key}>
  70. <td>{match.category}</td>
  71. <td>{moment(match.date).format('DD.MM.YYYY')}</td>
  72. <td>{moment(match.date).format('HH:mm')}</td>
  73. <td>{match.place}</td>
  74. <td>{match.player1 ? match.player1.fullName : ''}</td>
  75. <td>{match.player2 ? match.player2.fullName : ''}</td>
  76. <td>{match.result}</td>
  77. </tr>
  78. )}
  79. </tbody>
  80. </table>
  81. </form>
  82. </div>
  83. )
  84. }
  85. }
  86. export default Matches