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.
44 lines
1.5 KiB
44 lines
1.5 KiB
import { connect } from 'react-redux'
|
|
import { handleApiError } from 'src/api/errors'
|
|
import { fetchGroup, updateGroup } from 'src/actions/directory'
|
|
import { getEntity } from 'src/selectors/entities'
|
|
import { getFieldValue } from 'src/selectors/forms'
|
|
import { AppState, EntityType, Group, AppThunkDispatch } from 'src/types'
|
|
|
|
import GroupAdmin, { Props } from './group-admin'
|
|
import { initForm, initField, setFieldValue } from 'src/actions/forms'
|
|
|
|
const mapStateToProps = (state: AppState, ownProps: Props) => ({
|
|
group: getEntity<Group>(state, EntityType.Group, ownProps.match.params.id),
|
|
about: getFieldValue<string>(state, 'about'),
|
|
})
|
|
|
|
const mapDispatchToProps = (dispatch: AppThunkDispatch, ownProps: Props) => ({
|
|
fetchGroup: () => {
|
|
try {
|
|
dispatch(fetchGroup(ownProps.match.params.id))
|
|
} catch (err) {
|
|
handleApiError(err, dispatch, ownProps.history)
|
|
}
|
|
},
|
|
initForm: (group: Group) => {
|
|
dispatch(initForm())
|
|
dispatch(initField('about'))
|
|
dispatch(initField('expiration'))
|
|
dispatch(initField('limit'))
|
|
dispatch(setFieldValue('about', group.about as string))
|
|
},
|
|
updateGroup: (about: string) => {
|
|
try {
|
|
dispatch(updateGroup(ownProps.match.params.id, { about }))
|
|
dispatch(fetchGroup(ownProps.match.params.id))
|
|
} catch (err) {
|
|
handleApiError(err, dispatch, ownProps.history)
|
|
}
|
|
}
|
|
})
|
|
|
|
export default connect(
|
|
mapStateToProps,
|
|
mapDispatchToProps
|
|
)(GroupAdmin)
|