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.
38 lines
1.3 KiB
38 lines
1.3 KiB
import { connect } from 'react-redux'
|
|
import moment from 'moment'
|
|
import { handleApiError } from 'src/api/errors'
|
|
import { fetchInvitations, createInvitation } from 'src/actions/directory'
|
|
import { getInvitations } from 'src/selectors/directory'
|
|
import { getFieldValue } from 'src/selectors/forms'
|
|
import { AppState, AppThunkDispatch } from 'src/types'
|
|
|
|
import GroupInvitations, { Props } from './group-invitations'
|
|
|
|
const mapStateToProps = (state: AppState) => ({
|
|
invitations: getInvitations(state),
|
|
expiration: getFieldValue<string>(state, 'expiration', '0'),
|
|
limit: getFieldValue<string>(state, 'limit', '0'),
|
|
})
|
|
|
|
const mapDispatchToProps = (dispatch: AppThunkDispatch, ownProps: Props) => ({
|
|
fetchInvitations: () => {
|
|
try {
|
|
dispatch(fetchInvitations(ownProps.group))
|
|
} catch (err) {
|
|
handleApiError(err, dispatch)
|
|
}
|
|
},
|
|
createInvitation: async (expiration: string, limit: string) => {
|
|
try {
|
|
await dispatch(createInvitation(ownProps.group, moment().add(expiration, 'day').valueOf(), parseInt(limit, 10)))
|
|
await dispatch(fetchInvitations(ownProps.group))
|
|
} catch (err) {
|
|
handleApiError(err, dispatch)
|
|
}
|
|
},
|
|
})
|
|
|
|
export default connect(
|
|
mapStateToProps,
|
|
mapDispatchToProps
|
|
)(GroupInvitations)
|