[ABANDONED] React/Redux front end for the Flexor social network.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
3.1 KiB

5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. import React, { FC } from 'react'
  2. import { useSelector, useDispatch } from 'react-redux'
  3. import zxcvbn from 'zxcvbn'
  4. import { setFieldNotification } from '../actions/forms'
  5. import { showNotification } from '../actions/notifications'
  6. import { setStep } from '../actions/registration'
  7. import { getForm } from '../selectors/forms'
  8. import { MAX_ID_LENGTH, MAX_NAME_LENGTH } from '../constants'
  9. import { valueFromForm } from '../utils'
  10. import { AppThunkDispatch, NotificationType } from '../types'
  11. import CreateUserForm from './create-user-form'
  12. import HorizontalRule from '../components/horizontal-rule'
  13. import PrimaryButton from '../components/controls/primary-button'
  14. const CreateUserStep: FC = () => {
  15. const form = useSelector(getForm)
  16. const dispatch = useDispatch<AppThunkDispatch>()
  17. const next = () => {
  18. let invalid = false
  19. const userId = valueFromForm<string>(form, 'user-id')
  20. const name = valueFromForm<string>(form, 'user-name')
  21. const email = valueFromForm<string>(form, 'user-email')
  22. const password = valueFromForm<string>(form, 'password')
  23. const agree = valueFromForm<boolean>(form, 'user-agree')
  24. if (!userId || userId === '') {
  25. dispatch(setFieldNotification('user-id', NotificationType.Error, 'This is required'))
  26. invalid = true
  27. }
  28. if (userId && userId.length > MAX_ID_LENGTH) {
  29. dispatch(setFieldNotification('user-id', NotificationType.Error, `This must be less than ${MAX_ID_LENGTH} characters`))
  30. invalid = true
  31. }
  32. if (name && name.length > MAX_NAME_LENGTH) {
  33. dispatch(setFieldNotification('user-name', NotificationType.Error, `This must be less than ${MAX_NAME_LENGTH} characters`))
  34. invalid = true
  35. }
  36. if (!email || email === '') {
  37. dispatch(setFieldNotification('user-email', NotificationType.Error, 'This is required'))
  38. invalid = true
  39. }
  40. if (!agree) {
  41. dispatch(setFieldNotification('user-agree', NotificationType.Error, 'You must agree to the terms and conditions to continue'))
  42. dispatch(showNotification(NotificationType.Error, 'You must agree to the terms and conditions to continue.'))
  43. invalid = true
  44. }
  45. if (!password || password === '') {
  46. dispatch(setFieldNotification('password', NotificationType.Error, 'This is required'))
  47. invalid = true
  48. } else {
  49. const { score } = zxcvbn(password)
  50. if (score === 0) {
  51. dispatch(setFieldNotification('password', NotificationType.Error, 'Try another password'))
  52. invalid = true
  53. }
  54. }
  55. if (invalid) return
  56. dispatch(setStep(1))
  57. }
  58. return (
  59. <div>
  60. <CreateUserForm />
  61. <HorizontalRule />
  62. <nav className="level" style={{ flexDirection: 'row-reverse'}}>
  63. <div>
  64. <PrimaryButton text="To Community" onClick={() => next()} />
  65. </div>
  66. </nav>
  67. </div>
  68. )
  69. }
  70. export default CreateUserStep