[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.

71 lines
2.3 KiB

5 years ago
5 years ago
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
  1. import React, { FC } from 'react'
  2. import { useSelector, useDispatch } from 'react-redux'
  3. import { faArrowLeft } from '@fortawesome/free-solid-svg-icons'
  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 { valueFromForm } from '../utils'
  9. import { MAX_ID_LENGTH } from '../constants'
  10. import { AppThunkDispatch, NotificationType } from '../types'
  11. import CreateGroupForm from './create-group-form'
  12. import HorizontalRule from '../components/horizontal-rule'
  13. import PrimaryButton from '../components/controls/primary-button'
  14. import SecondaryButton from '../components/controls/secondary-button'
  15. interface Props {
  16. register: () => void
  17. }
  18. const CreateGroupStep: FC<Props> = ({ register }) => {
  19. const form = useSelector(getForm)
  20. const dispatch = useDispatch<AppThunkDispatch>()
  21. const next = () => {
  22. let invalid = false
  23. const name = valueFromForm<string>(form, 'group-name')
  24. const agree = valueFromForm<boolean>(form, 'group-agree')
  25. if (!name || name === '') {
  26. dispatch(setFieldNotification('group-name', NotificationType.Error, 'This is required'))
  27. invalid = true
  28. }
  29. if (name && name.length > MAX_ID_LENGTH) {
  30. dispatch(setFieldNotification('group-name', NotificationType.Error, `This must be less than ${MAX_ID_LENGTH} characters`))
  31. invalid = true
  32. }
  33. if (!agree) {
  34. dispatch(setFieldNotification('group-agree', NotificationType.Error, 'You must agree to the terms and conditions to continue'))
  35. dispatch(showNotification(NotificationType.Error, 'You must agree to the terms and conditions to continue.'))
  36. invalid = true
  37. }
  38. if (invalid) return
  39. register()
  40. }
  41. return (
  42. <div>
  43. <CreateGroupForm />
  44. <HorizontalRule />
  45. <nav className="level">
  46. <div>
  47. <SecondaryButton text="Your Account" icon={faArrowLeft} onClick={() => dispatch(setStep(0))} />
  48. </div>
  49. <div>
  50. <PrimaryButton text="Finish" onClick={() => next()} />
  51. </div>
  52. </nav>
  53. </div>
  54. )
  55. }
  56. export default CreateGroupStep