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

49 lines
1.7 KiB

import { connect } from 'react-redux'
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 } from 'src/types'
import CreateGroupStep, { Props } from './create-group-step'
const mapStateToProps = (state: AppState) => ({
name: getFieldValue<string>(state, 'group-name', ''),
registration: getFieldValue<string>(state, 'group-registration', ''),
agree: getFieldValue<boolean>(state, 'group-agree', false),
})
const mapDispatchToProps = (dispatch: AppThunkDispatch, ownProps: Props) => ({
previous: () => {
dispatch(setStep(0))
},
next: (name: string, registration: string, agree: boolean) => {
let invalid = false
if (!name) {
dispatch(setFieldNotification('group-name', 'error', 'This is required'))
invalid = true
}
if (name.length > MAX_ID_LENGTH) {
dispatch(setFieldNotification('group-name', 'error', `This must be less than ${MAX_ID_LENGTH} characters`))
invalid = true
}
if (!agree) {
dispatch(setFieldNotification('group-agree', 'error', 'You must agree to the terms and conditions to continue'))
dispatch(showNotification('error', 'You must agree to the terms and conditions to continue.'))
invalid = true
}
if (invalid) return
if (ownProps.register) ownProps.register()
},
})
export default connect(
mapStateToProps,
mapDispatchToProps
)(CreateGroupStep)