user-activate-register.jsx 2.6 KB

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