SMS.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import React from 'react'
  2. class SMS extends React.Component {
  3. constructor() {
  4. super()
  5. this.handleChange = this.handleChange.bind(this)
  6. this.addRecipient = this.addRecipient.bind(this)
  7. this.submitForm = this.submitForm.bind(this)
  8. }
  9. handleChange (event) {
  10. event.preventDefault()
  11. this.props.smsActions.changeForm({
  12. sender: this.sender.value,
  13. body: this.body.value,
  14. newRecipient: this.newRecipient.value
  15. })
  16. }
  17. submitForm (event) {
  18. event.preventDefault()
  19. const state = this.props.sms
  20. this.props.smsActions.sendSMSRequest(state)
  21. }
  22. addRecipient (event) {
  23. event.preventDefault()
  24. this.props.smsActions.addRecipient(this.newRecipient.value)
  25. }
  26. removeRecipient (key, event) {
  27. event.preventDefault()
  28. this.props.smsActions.removeRecipient(key)
  29. }
  30. setRecipients (value, event) {
  31. event.preventDefault()
  32. this.props.smsActions.setRecipients(value)
  33. }
  34. render () {
  35. const state = this.props.sms
  36. const { sender, body, newRecipient } = state
  37. return (
  38. <div>
  39. <h2>SMS</h2>
  40. <p>Guthaben: {state.credit}</p>
  41. <form>
  42. <label htmlFor="sender">Sender Name</label>
  43. <input type="input" id="sender" ref={(input => {this.sender = input})} value={sender} placeholder="Sender Name" onChange={this.handleChange}/>
  44. <br />
  45. <label htmlFor="body">Nachricht</label>
  46. <textarea id="body" ref={(input => {this.body = input})} value={body} placeholder="Nachricht" onChange={this.handleChange} />
  47. <p>{body.length}/160 Zeichen</p>
  48. <br />
  49. <label htmlFor="newRecipient">Neuer Empfaenger</label>
  50. <input type="input" id="newRecipient" ref={(input => {this.newRecipient = input})} value={newRecipient} placeholder="Neuer Empfaenger" onChange={this.handleChange}/>
  51. <input type="button" value="ok" onClick={this.addRecipient}/>
  52. <br />
  53. <input type="submit" value="Senden" onClick={this.submitForm}/>
  54. </form>
  55. <h3>Alle Empfaenger</h3>
  56. <p>{state.recipients.filter(recipient => (typeof recipient === 'string') || recipient.phone).length} von {state.recipients.length} mit Telefonnummer</p>
  57. {state.recipients.length ? <p><a onClick={(event) => {this.setRecipients([], event)}}>{'\u2716'}</a> Alle löschen</p> : null}
  58. <ul>
  59. {state.recipients.map((recipient, key) =>
  60. <li key={key}><a onClick={(event) => {this.removeRecipient(key, event)}}>{'\u2716'}</a> {(typeof recipient === 'string') ? recipient : `${recipient.fullName} (${recipient.phone ? recipient.phone : 'keine Nummer'})`}</li>
  61. )}
  62. </ul>
  63. </div>
  64. )
  65. }
  66. }
  67. export default SMS