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.
84 lines
3.0 KiB
84 lines
3.0 KiB
import React, { FC } from 'react'
|
|
import { useSelector, useDispatch } from 'react-redux'
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
|
import { faBuilding, faArrowLeft } from '@fortawesome/free-solid-svg-icons'
|
|
|
|
import { setFieldNotification } from 'src/actions/forms'
|
|
import { showNotification } from 'src/actions/notifications'
|
|
import { setStep } from 'src/actions/registration'
|
|
import { getForm, getFieldValue } from 'src/selectors/forms'
|
|
|
|
import { MAX_ID_LENGTH } from 'src/constants'
|
|
import { AppState, AppThunkDispatch, NotificationType, Form } from 'src/types'
|
|
|
|
import CreateGroupForm from './create-group-form'
|
|
import { valueFromForm } from 'src/utils'
|
|
|
|
interface Props {
|
|
register: () => void
|
|
}
|
|
|
|
const CreateGroupStep: FC<Props> = ({ register }) => {
|
|
const form = useSelector<AppState, Form>(getForm)
|
|
const dispatch = useDispatch<AppThunkDispatch>()
|
|
|
|
const next = () => {
|
|
let invalid = false
|
|
|
|
const name = valueFromForm<string>(form, 'group-name')
|
|
const agree = valueFromForm<boolean>(form, 'group-agree')
|
|
|
|
if (!name || name === '') {
|
|
dispatch(setFieldNotification('group-name', NotificationType.Error, 'This is required'))
|
|
invalid = true
|
|
}
|
|
|
|
if (name && name.length > MAX_ID_LENGTH) {
|
|
dispatch(setFieldNotification('group-name', NotificationType.Error, `This must be less than ${MAX_ID_LENGTH} characters`))
|
|
invalid = true
|
|
}
|
|
|
|
if (!agree) {
|
|
dispatch(setFieldNotification('group-agree', NotificationType.Error, 'You must agree to the terms and conditions to continue'))
|
|
dispatch(showNotification(NotificationType.Error, 'You must agree to the terms and conditions to continue.'))
|
|
invalid = true
|
|
}
|
|
|
|
if (invalid) return
|
|
register()
|
|
}
|
|
|
|
return (
|
|
<div className="centered-content">
|
|
<div className="centered-content-icon has-background-primary">
|
|
<span className="icon is-large has-text-white">
|
|
<FontAwesomeIcon icon={faBuilding} size="2x" />
|
|
</span>
|
|
</div>
|
|
|
|
<CreateGroupForm />
|
|
<hr />
|
|
|
|
<nav className="level">
|
|
<div className="level-left">
|
|
<p className="level-item">
|
|
<button className="button" onClick={() => dispatch(setStep(0))}>
|
|
<span className="icon is-small">
|
|
<FontAwesomeIcon icon={faArrowLeft} />
|
|
</span>
|
|
<span>Your Account</span>
|
|
</button>
|
|
</p>
|
|
</div>
|
|
|
|
<div className="level-right">
|
|
<p className="level-item">
|
|
<button className="button is-success" onClick={() => next()}>Finish</button>
|
|
</p>
|
|
</div>
|
|
</nav>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default CreateGroupStep
|