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

60 lines
2.0 KiB

import { connect } from 'react-redux'
import { getForm } from 'src/selectors/forms'
import { getStep } from 'src/selectors/registration'
import { initForm, initField } from 'src/actions/forms'
import { showNotification } from 'src/actions/notifications'
import { createGroup, register } from 'src/actions/registration'
import { valueFromForm } from 'src/utils'
import { AppState, AppThunkDispatch, Form } from 'src/types'
import Register, { Props } from './register'
const mapStateToProps = (state: AppState) => ({
stepIndex: getStep(state),
form: getForm(state),
})
const mapDispatchToProps = (dispatch: AppThunkDispatch, ownProps: Props) => ({
initForm: () => {
dispatch(initForm())
dispatch(initField('group-name'))
dispatch(initField('group-registration'))
dispatch(initField('group-agree'))
dispatch(initField('user-id'))
dispatch(initField('user-name'))
dispatch(initField('user-email'))
dispatch(initField('password'))
dispatch(initField('user-agree'))
},
register: async (form: Form) => {
const groupAgree = valueFromForm<boolean>(form, 'group-agree', false)
const userAgree = valueFromForm<boolean>(form, 'user-agree', false)
if (!groupAgree || !userAgree) {
dispatch(showNotification('error', 'You must agree to both Community and User terms and conditions.'))
return
}
const groupId = await dispatch(createGroup(
valueFromForm<string>(form, 'group-name', ''),
valueFromForm<string>(form, 'group-registration', '')
))
const userId = await dispatch(register(
valueFromForm<string>(form, 'user-id', ''),
valueFromForm<string>(form, 'user-email', ''),
valueFromForm<string>(form, 'password', ''),
valueFromForm<string>(form, 'user-name', ''),
groupId
))
ownProps.history.push('/self')
}
})
export default connect(
mapStateToProps,
mapDispatchToProps
)(Register)