user-activate-register.jsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { useState } from 'react'
  2. import PropTypes from 'prop-types'
  3. import RegisterForm from './register-form'
  4. import OLRow from '@/shared/components/ol/ol-row'
  5. import OLCol from '@/shared/components/ol/ol-col'
  6. import OLCard from '@/shared/components/ol/ol-card'
  7. import Notification from '@/shared/components/notification'
  8. function UserActivateRegister() {
  9. const [emails, setEmails] = useState([])
  10. const [failedEmails, setFailedEmails] = useState([])
  11. const [registerError, setRegisterError] = useState(false)
  12. const [registrationSuccess, setRegistrationSuccess] = useState(false)
  13. return (
  14. <OLRow>
  15. <OLCol>
  16. <OLCard>
  17. <div className="page-header">
  18. <h1>Register new users</h1>
  19. </div>
  20. <RegisterForm
  21. setRegistrationSuccess={setRegistrationSuccess}
  22. setEmails={setEmails}
  23. setRegisterError={setRegisterError}
  24. setFailedEmails={setFailedEmails}
  25. />
  26. {registerError ? (
  27. <UserActivateError failedEmails={failedEmails} />
  28. ) : null}
  29. {registrationSuccess ? (
  30. <>
  31. <SuccessfulRegistrationMessage />
  32. <hr />
  33. <DisplayEmailsList emails={emails} />
  34. </>
  35. ) : null}
  36. </OLCard>
  37. </OLCol>
  38. </OLRow>
  39. )
  40. }
  41. function UserActivateError({ failedEmails }) {
  42. return (
  43. <div className="row-spaced">
  44. <Notification
  45. type="error"
  46. content="Sorry, an error occured, failed to register these email:"
  47. className="mb-3"
  48. />
  49. <ul>
  50. {failedEmails.map(email => (
  51. <li key={email}>{email}</li>
  52. ))}
  53. </ul>
  54. </div>
  55. )
  56. }
  57. function SuccessfulRegistrationMessage() {
  58. return (
  59. <div className="row-spaced text-success">
  60. <p>We've sent out welcome emails to the registered users.</p>
  61. <p>
  62. You can also manually send them URLs below to allow them to reset their
  63. password and log in for the first time.
  64. </p>
  65. <p>
  66. (Password reset tokens will expire after one week and the user will need
  67. registering again).
  68. </p>
  69. </div>
  70. )
  71. }
  72. function DisplayEmailsList({ emails }) {
  73. return (
  74. <table className="table table-striped ">
  75. <tbody>
  76. <tr>
  77. <th>Email</th>
  78. <th>Set Password Url</th>
  79. </tr>
  80. {emails.map(user => (
  81. <tr key={user.email}>
  82. <td>{user.email}</td>
  83. <td style={{ wordBreak: 'break-all' }}>{user.setNewPasswordUrl}</td>
  84. </tr>
  85. ))}
  86. </tbody>
  87. </table>
  88. )
  89. }
  90. DisplayEmailsList.propTypes = {
  91. emails: PropTypes.array,
  92. }
  93. UserActivateError.propTypes = {
  94. failedEmails: PropTypes.array,
  95. }
  96. export default UserActivateRegister