AddMemberForm.jsx 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import React from 'react'
  2. import { translate } from 'react-i18next'
  3. export class AddMemberForm extends React.Component {
  4. constructor (props) {
  5. super(props)
  6. this.state = {
  7. newUserEmail: '',
  8. newUserProfile: ''
  9. }
  10. }
  11. handleChangeNewUserEmail = e => this.setState({newUserEmail: e.target.value})
  12. handleChangeNewUserProfile = e => this.setState({newUserProfile: e.currentTarget.value})
  13. handleClickAddUser = () => {
  14. const { props, state } = this
  15. if (state.newUserEmail === '' || state.newUserProfile === '') {
  16. GLOBAL_dispatchEvent({
  17. type: 'addFlashMsg',
  18. data: {
  19. msg: props.t('Please type a name and select a profile'),
  20. type: 'warning',
  21. delay: undefined
  22. }
  23. })
  24. return
  25. }
  26. props.onClickAddUser(state.newUserEmail, state.newUserProfile)
  27. }
  28. render () {
  29. const { props, state } = this
  30. return (
  31. <form className='adminUserPage__adduser__form'>
  32. <div className='adminUserPage__adduser__form__username'>
  33. <label className='username__text' htmlFor='adduser'>
  34. {props.t('Add a user')}
  35. </label>
  36. <input
  37. type='text'
  38. className='username__input form-control'
  39. id='adduser'
  40. placeholder={props.t('Email')}
  41. value={state.newUserEmail}
  42. onChange={this.handleChangeNewUserEmail}
  43. />
  44. {/*
  45. <div className='username__createaccount'>
  46. <input type='radio' id='createuseraccount' />
  47. <label className='ml-2' htmlFor='createuseraccount'>Create an account for this member</label>
  48. </div>
  49. */}
  50. </div>
  51. <div className='adminUserPage__adduser__form__profile'>
  52. <div className='profile__text'>
  53. {props.t('Choose the profile of the user')}
  54. </div>
  55. <div className='profile__list'>
  56. {Object.keys(props.profile).map(p => props.profile[p]).map(p =>
  57. <label
  58. className='profile__list__item'
  59. htmlFor={p.slug}
  60. key={p.id}
  61. >
  62. <input
  63. type='radio'
  64. name='newUserProfile'
  65. id={p.slug}
  66. value={p.slug}
  67. checked={state.newUserProfile === p.slug}
  68. onChange={this.handleChangeNewUserProfile}
  69. />
  70. <div className='d-flex align-items-center'>
  71. <div className='userrole__role__icon mx-2' style={{color: p.hexcolor}}>
  72. <i className={`fa fa-fw fa-${p.faIcon}`} />
  73. </div>
  74. {p.label}
  75. </div>
  76. </label>
  77. )}
  78. </div>
  79. </div>
  80. <div className='adminUserPage__adduser__form__submit'>
  81. <button
  82. type='button'
  83. className='btn'
  84. onClick={this.handleClickAddUser}
  85. >
  86. {props.t('Add the user')}
  87. </button>
  88. </div>
  89. </form>
  90. )
  91. }
  92. }
  93. export default translate()(AddMemberForm)