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.
83 lines
3.1 KiB
83 lines
3.1 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 { getFieldValue } from 'src/selectors/forms'
|
|
|
|
import { MAX_ID_LENGTH } from 'src/constants'
|
|
import { AppState, AppThunkDispatch, NotificationType } from 'src/types'
|
|
|
|
import CreateGroupForm from './create-group-form'
|
|
|
|
interface Props {
|
|
register: () => void
|
|
}
|
|
|
|
const CreateGroupStep: FC<Props> = ({ register }) => {
|
|
const name = useSelector<AppState, string>(state => getFieldValue<string>(state, 'group-name', ''))
|
|
const registration = useSelector<AppState, string>(state => getFieldValue<string>(state, 'group-registration', ''))
|
|
const agree = useSelector<AppState, boolean>(state => getFieldValue<boolean>(state, 'group-agree', false))
|
|
|
|
const dispatch = useDispatch<AppThunkDispatch>()
|
|
|
|
const next = (name: string, registration: string, agree: boolean) => {
|
|
let invalid = false
|
|
|
|
if (!name) {
|
|
dispatch(setFieldNotification('group-name', NotificationType.Error, 'This is required'))
|
|
invalid = true
|
|
}
|
|
|
|
if (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(name, registration, agree)}>Finish</button>
|
|
</p>
|
|
</div>
|
|
</nav>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default CreateGroupStep
|