AdminUser.jsx 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import React from 'react'
  2. import { translate } from 'react-i18next'
  3. import {
  4. Delimiter,
  5. PageWrapper,
  6. PageTitle,
  7. PageContent,
  8. BtnSwitch
  9. } from 'tracim_frontend_lib'
  10. import AddMemberForm from './AddMemberForm.jsx'
  11. // import { translate } from 'react-i18next'
  12. export class AdminUser extends React.Component {
  13. constructor (props) {
  14. super(props)
  15. this.state = {
  16. displayAddMember: false
  17. }
  18. }
  19. handleToggleAddMember = () => this.setState(prevState => ({
  20. displayAddMember: !prevState.displayAddMember
  21. }))
  22. handleToggleUser = (e, idUser, toggle) => {
  23. e.preventDefault()
  24. e.stopPropagation()
  25. this.props.onClickToggleUserBtn(idUser, toggle)
  26. }
  27. handleToggleProfileManager = (e, idUser, toggle) => {
  28. e.preventDefault()
  29. e.stopPropagation()
  30. const { props } = this
  31. if (props.userList.find(u => u.user_id === idUser).profile === 'administrators') {
  32. GLOBAL_dispatchEvent({
  33. type: 'addFlashMsg',
  34. data: {
  35. msg: props.t('An administrator can always create workspaces'),
  36. type: 'warning',
  37. delay: undefined
  38. }
  39. })
  40. return
  41. }
  42. if (toggle) props.onChangeProfile(idUser, 'managers')
  43. else props.onChangeProfile(idUser, 'users')
  44. }
  45. handleToggleProfileAdministrator = (e, idUser, toggle) => {
  46. e.preventDefault()
  47. e.stopPropagation()
  48. if (toggle) this.props.onChangeProfile(idUser, 'administrators')
  49. else this.props.onChangeProfile(idUser, 'managers')
  50. }
  51. handleClickAddUser = (email, profile) => {
  52. this.props.onClickAddUser(email, profile)
  53. this.handleToggleAddMember()
  54. }
  55. render () {
  56. const { props } = this
  57. return (
  58. <PageWrapper customClass='adminUserPage'>
  59. <PageTitle
  60. parentClass={'adminUserPage'}
  61. title={"Member's management"}
  62. />
  63. <PageContent parentClass='adminUserPage'>
  64. <div className='adminUserPage__description'>
  65. {props.t('On this page you can manage the members of your Tracim instance.')}
  66. </div>
  67. <div className='adminUserPage__adduser'>
  68. <button className='adminUserPage__adduser__button btn' onClick={this.handleToggleAddMember}>
  69. {props.t('Add a member')}
  70. </button>
  71. {this.state.displayAddMember &&
  72. <AddMemberForm
  73. profile={props.profile}
  74. onClickAddUser={this.handleClickAddUser}
  75. />
  76. }
  77. </div>
  78. <Delimiter customClass={'adminUserPage__delimiter'} />
  79. <div className='adminUserPage__table'>
  80. <table className='table'>
  81. <thead>
  82. <tr>
  83. <th scope='col'>{props.t('Active')}</th>
  84. <th scope='col'>{props.t('Member')}</th>
  85. <th scope='col'>{props.t('Email')}</th>
  86. <th scope='col'>{props.t('Can create workspace')}</th>
  87. <th scope='col'>{props.t('Administrator')}</th>
  88. </tr>
  89. </thead>
  90. <tbody>
  91. {props.userList.map(u =>
  92. <tr key={u.user_id}>
  93. <td>
  94. <BtnSwitch checked={u.is_active} onChange={e => this.handleToggleUser(e, u.user_id, !u.is_active)} />
  95. </td>
  96. <th scope='row'>{u.public_name}</th>
  97. <td>{u.email}</td>
  98. <td>
  99. <BtnSwitch
  100. checked={u.profile === 'managers' || u.profile === 'administrators'}
  101. onChange={e => this.handleToggleProfileManager(e, u.user_id, !(u.profile === 'managers' || u.profile === 'administrators'))}
  102. />
  103. </td>
  104. <td>
  105. <BtnSwitch
  106. checked={u.profile === 'administrators'}
  107. onChange={e => this.handleToggleProfileAdministrator(e, u.user_id, !(u.profile === 'administrators'))}
  108. />
  109. </td>
  110. </tr>
  111. )}
  112. </tbody>
  113. </table>
  114. </div>
  115. </PageContent>
  116. </PageWrapper>
  117. )
  118. }
  119. }
  120. export default translate()(AdminUser)