[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.0 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. // create-group-step.tsx
  2. // Copyright (C) 2020 Dwayne Harris
  3. // This program is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation, either version 3 of the License, or
  6. // (at your option) any later version.
  7. // This program is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. // GNU General Public License for more details.
  11. // You should have received a copy of the GNU General Public License
  12. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. import React, { FC } from 'react'
  14. import { useSelector, useDispatch } from 'react-redux'
  15. import { faArrowLeft } from '@fortawesome/free-solid-svg-icons'
  16. import { setFieldNotification } from '../actions/forms'
  17. import { showNotification } from '../actions/notifications'
  18. import { setStep } from '../actions/registration'
  19. import { getForm } from '../selectors/forms'
  20. import { valueFromForm } from '../utils'
  21. import { MAX_ID_LENGTH } from '../constants'
  22. import { AppThunkDispatch, NotificationType } from '../types'
  23. import CreateGroupForm from './create-group-form'
  24. import HorizontalRule from '../components/horizontal-rule'
  25. import PrimaryButton from '../components/controls/primary-button'
  26. import SecondaryButton from '../components/controls/secondary-button'
  27. interface Props {
  28. register: () => void
  29. }
  30. const CreateGroupStep: FC<Props> = ({ register }) => {
  31. const form = useSelector(getForm)
  32. const dispatch = useDispatch<AppThunkDispatch>()
  33. const next = () => {
  34. let invalid = false
  35. const name = valueFromForm<string>(form, 'group-name')
  36. const agree = valueFromForm<boolean>(form, 'group-agree')
  37. if (!name || name === '') {
  38. dispatch(setFieldNotification('group-name', NotificationType.Error, 'This is required'))
  39. invalid = true
  40. }
  41. if (name && name.length > MAX_ID_LENGTH) {
  42. dispatch(setFieldNotification('group-name', NotificationType.Error, `This must be less than ${MAX_ID_LENGTH} characters`))
  43. invalid = true
  44. }
  45. if (!agree) {
  46. dispatch(setFieldNotification('group-agree', NotificationType.Error, 'You must agree to the terms and conditions to continue'))
  47. dispatch(showNotification(NotificationType.Error, 'You must agree to the terms and conditions to continue.'))
  48. invalid = true
  49. }
  50. if (invalid) return
  51. register()
  52. }
  53. return (
  54. <div>
  55. <CreateGroupForm />
  56. <HorizontalRule />
  57. <nav className="level">
  58. <div>
  59. <SecondaryButton text="Your Account" icon={faArrowLeft} onClick={() => dispatch(setStep(0))} />
  60. </div>
  61. <div>
  62. <PrimaryButton text="Finish" onClick={() => next()} />
  63. </div>
  64. </nav>
  65. </div>
  66. )
  67. }
  68. export default CreateGroupStep