user-activate-register.jsx 2.4 KB

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